Day 12 : Linux and Git/GitHub Command Cheat Sheet
List Commands
ls -l # list the files and directories in long list format with extra information
ls -a # list all including hidden files and directory
ls *.sh # list all the files having .sh extension.
ls -i # list the files and directories with index numbers inodes
ls -d */ # list only directories.(we can also specify a pattern)
Directory Commands
pwd # print work directory. Gives the present working directory.
cd path_to_directory # Change directory to the provided path
cd ~ or just cd # Change directory to the home directory
cd - # Go to the last working directory.
cd .. # Change directory to one step back.
cd ../.. # Change directory to 2 levels back.
mkdir DirectoryName # To make a directory in a specific location
mkdir newFolder # make a new folder 'newFolder'
mkdir .NewFolder # make a hidden directory (also . before a file to make it hidden)
mkdir A B C D # make multiple directories at the same time
mkdir /home/user/Mydirectory # make a new folder in a specific location
mkdir -p A/B/C/D # make a nested directory
mkdir dir{1..99} # To make dir 1 to 99
Some Commands
cat FileName # To see the data in file
chomod 777 FolderName # To Change the full permitions
history # To see the commands used before
rmdir DirectoryName # To remove Empty directory
rmdir -rf DirectoryName # To remove a Directory with files in it
vim fruits.txt # To Edit file with vim or vi
cat fruits.txt # To see the data in Fruits.txt
head -n 3 fruits.txt # To see the top 3 lines in fruits.txt
tail -n 3 fruits.txt # To see the last 3 lines in fruits.txt
touch Colours.txt # To create file
cat Colours.txt # To view contents
echo "Apple" > Colors.txt # To Add Apple to the Colours.txt
diff fruits.txt Colors.txt # To see differents between two files
chmod +x print_variables.sh # To give Excute permition to the file
CronTab
crontab -l -u username # View crontab entries for a specific user
crontab -e -u username # Edit crontab entries for a specific user
crontab -r -u username # Remove crontab entries for a specific user
User Commands
useradd # To create a new user
usedel # To Delete a user account
usermod # To modifiy user details
passwd # To change the password
su # To switch the user
sudo # To give root permitions to the normal user
chown user:group directory/file # To change ownership
chgrp group directory/file # To change the group
setfacl -m u:username:permissions /path/to/file # To give specified special permission
getfacl /path/to/file # To see detailed list of permission
setfacl -m u:johndoe:rw /path/to/file # To To give read & write permission to user johndoe
setfacl -m g:mygroup:-x /path/to/file # To remove EX permition to mygroup specified file
Normal commands
sudo apt-get update -y # To update the packages
sudo apt-get install -y # To install any package
-version # To check the java version
systemctl status docker # To view the status of the Docker use below com
sudo systemctl start docker # Start Docker demon
sudo systemctl stop docker # To STOP the docker service use below command
Git Commands
git init # To initialise the repository
git add . # To add all file to staging
git commit -m 'commit message' # To Commit the changes with specified commit message
git push origin main # To push the changes to the remote repository
git config --global user.email "[email protected]" # To SET the author mail id
git config --global user.name "Your Name" # To SET teh author name
git remote add origin <link of the git repository> # To add the remote repo to local repo
git log # To see all the commits with full details
git log --oneline # To see all the commits with oneline
git branch # To see the branch
git push --force origin master # To push the changes forcefully
git checkout -b branchname # To create a branch and change to that
git checkout branchname # To change the branch
git merge branchname # To merge the changes to another branch
git log --oneline --all --graph # To see the all commits with small graph
git stash # To save the working directory work with out commiting
git stash pop # To bring back the changes to the working directory
git stash apply # To bring back the a copy of hashcode to the working direcoory
git revert # It used to record some new commits to
reverse the effect of some earlier.
Thanks for reading my article i hope it will be useful for you <3
#Mosad-Rashad <3