Show Menu
Cheatography

Linux & Git Cheat Sheet by

Cheatsheet including important commands used in Linux and Git

Linux basic commands

pwd
shows Present working directory
cd
changes Directory
cd ~
changes directory to home
cd ..
goes one directory behind
ls
shows list of direct­ories and files in current working directory
ls -l
shows list of direct­ories in long format
ls -a
shows all files and directoies including hidden ones
ls <di­rectory name>
shows list of direct­ories and files in specified directory
ls -lS > file.txt
saves list in long form to txt file in pwd
cat
Echoes input
cat <te­xtf­ile­nam­e>
Displays content of file or files
 

Linux redire­ction

cat > test.txt
Creates a file named test.txt and records data given below
cat > test.txt (again)
Overwrites previous data
cat >> test.txt
appends data
cat [textf­ile1] [textf­ile2] > [new or existing file]
concat­enates textfile1 and textfile2 and saves to new file
mkdir [direc­tor­yname]
creates a directory
mkdir -p [dir]/­[su­bdir]
creates a path of direct­ories
mkdir -p [dir]/­{su­bdi­r1,­sub­dir­2,s­ubdir3}
Create multiple subdir­ect­ories in one directory
rmdir
Remove directory
rmdir -p a/b/c/d/e
removes entire directory path
rmdir pv (verbose)
Shows how removal will work
rm
removes file
cp [file1.txt] [dirname]
copies file1.txt to the specified directory
cp -r
copies recurs­ively
man <any comman­d>
Displays manual for that command
mv [file1.txt] [dirname]
move file1.txt from current dir to specified directory
touch <fi­len­ame>
creates file quickly
touch <ex­ist­ing­fil­e>
updates time stamp of file
nano
opens file editor
vim
opens vim file editor
sudo
executes command as superuser
 

Linux advanced

top
displays processes running on the computer
s (in top menu)
changes refresh rate
i (in top menu)
shows idle processes
k (in top menu)
kills process using PID
pid of
finds process id of process using name
kill [PID]
kills process for given process id
kill -9 [PID]
Force stop
ps -ux
Gives list of running processes and finds PIDs
ps -aux
Gives list of all running processes and finds PIDs
ps -U [user]
displays list of running processes for given user
ps -C
to know the instances of that program
echo
displays whatever we type (useful in bash scripting)
chmod
Utility to change permission of the file
wget
get(just reads)
sudo apt -get update
updates system
exit
Exits superuser or terminal
ssh -i ./[file] [usern­ame­]@[ip]
establ­ishes ssh connection
vmstat
prints a summary of key server statis­tics, processes, cpu, disk space
 

git commands

apt-get install git
installs git on linux
git init
initia­lizes empty git repository in folder
git add <file name>
stages file for commitment
git add .
stages all files for commitment
git commit -m "­<no­te>­"
commits staged files
git status
shows status of files
git branch
shows all branches
git branch <branch name>
creates new branch
git switch <branch name>
switches branch
git checkout <branch name>
switches branch
git merge <branch name>
merges the specified branch with current branch
git rebase <branch name>
merges the specified branch with current branch and adds commit ahead of present commits
git stash
used to store changes when we want to move to a different directory without committing current changes
git push -u origin master
pushing changes to central github repository
git --help
shows all commands
git restore --<­staged file name>
untrack file
       
 

Comments

No comments yet. Add yours below!

Add a Comment

Your Comment

Please enter your name.

    Please enter your email address

      Please enter your Comment.

          Related Cheat Sheets

          Linux Command Line Cheat Sheet
          bash Shortcuts Cheat Sheet
          Windows Terminal Cheat Sheet

          More Cheat Sheets by RohitKadolkar

          Docker Cheat Sheet