Linux Cheatsheet
Basic Commands
Commands | Description |
date | It shows the current date and time |
cal | It shows the current month's calendar |
uptime | It shows when your system running |
whoami | It will show you |
users | It shows user information |
who | It will show you who you are and your public IP |
man | It will show you command details eg. man who |
ls | It will show files and directories in the current working directory |
ls -a | Shows hidden files |
pwd | Shows the path of the present working directory |
Files and Directories
Commands | Description |
touch | To create empty files and to update timestamp |
cat > filename | It creates a file and allows to add content |
cat <filename> | Shows the content of the file |
head <filename> | Shows the first top 10 lines of a file |
tail <filename> | Shows the bottom 10 lines of a file |
rm <filename> | Removes file |
rm -rf <filename> | Removes file forcefully |
cp <filname1> <filename2> | It copies the content of a filename1 to filename2 |
mv <filename1> <filename2> | It is used to rename or move files. |
mkdir <dirname> | To create a directory |
cd <dirname> | To change the directory |
rm -r <dir name> | Removes directory |
rm -rf <dir name> | Forcefully removes directory |
find | To search files or directories in Linux |
grep | To search patterns in a file |
diff | find the difference between file |
sed | To search and replace content from a file |
User Management
All the user information is stored in /etc/passwd.
Commands | Description |
addgroup <groupname> | It will add a new group |
useradd <username> | It will create a user |
su <username> | To switch user |
deluser <username> | To delete user |
del group <groupname> | To delete a group |
chown | To change ownership of a file |
chgrp | To change group membership of a file |
usermod -g | To change the group of a user |
usermod -a -G | To add a user to multiple groups |
passwd | To change the password |
System Management
Commands | Description |
history | shows list commands executed by the user |
free | It shows free and used memory in the system |
/proc/meminfo | It shows memory information |
/proc/cpuinfo | It shows CPU information |
uname -a | It shows kernel information |
du | It shows directory-wise disk usage (for memory monitoring) |
df | It shows filesystem disk usage (for memory monitoring) |
top / top | for CPU monitoring |
Software Management
yum is the tool to install, delete, update and manage RHEL software packages.
Commands | Description |
yum install <package name> | It will install the package. eg. yum install git |
yum remove <package name> | It will remove the package |
yum update <package name> | It will update the package |
yum info <package name> | It will give package info |
yum list available | It will show available packages on Yum |
yum list installed | It will show installed packages. |
apt-get command is used to install, remove, and perform other operations on installed software packages. The apt-get command, and other core APT utilities, are available by default in the Debian, Ubuntu, and Linux Mint operating systems.
Commands | Description |
apt-get install <package name> | It will install the package |
apt-get remove <package name> | It will remove the package |
apt-get purge <packga name> | It will remove the package and its configuration |
dpkg -l | It will show all installed package |
Networking
Commands | Description |
ping host | ping host and output result |
hostname | list the hostname of the server |
wget | It will download packages or software on the Linux system |
telnet | connect to the remote host |
curl | access the application from the browser |
Services
Commands | Description |
service <name of the service> status | To see the status of the service |
service <name of the service> start | Start the service |
service <name of the service> stop | stop the service |
service <name of the service> reload | Reload the service |
service <name of the service> restart | Restart the service |
Process Management
Commands | Description |
ps -ef | To display the current working process |
top | Display all running process |
kill -9 | Kill the process |
Compression
Commands | Description |
gzip file | compress the file and rename it to file.gz |
gzip -d file.gz | Decompresses file.gz back to the file |
tar cf file.tar file | Create a tar named file.tar containing file |
tar xf file.tar | Extract the files from the file.tar |
tar czf file.tar.gz files | Create a tar with Gzip compression |
tar xzf file.tar.gz files | Extract a tar using Gzip compression |
GIT Cheatsheet
Configuring user information for all local repositories
$ git config --global user.name "[Enter name]" | Configuring the name |
$ git config --global user.email "[email id]" | configuring the email |
Create Repositories
git init | Initialize an existing directory as a Git repository |
git clone <url> | Copy the entire repository from the central hosted location via URL |
Stage and snapshot
git status | Shows the status of a file like tracked untracked. |
git add (file) | adding a file from the working area to the staging area |
git add . | It will add all the files from the working area to the staging area |
git reset (file) | Unstage a file while retaining the changes in the working directory |
git commit -m <"Message"> | It will commit all the files from the staging area to the commit area. |
Branch and Merge
git branch | It will list all branch |
git branch <branch name> | It will create a new branch |
git branch checkout | It will switch to another branch |
git merge <branch name> | It will merge branch history into the current branch |
git branch -d <branch name> | It will remove a branch |
git log | It will show all the commit history currently active branch |
Compare
git log <branch1> <branch2> | Shows the commit on branch1 that are not in branch2 |
git log --merge | It will show commits that cause conflicts |
git diff <branch1> <branch2> | Shows the difference between the two branch |
Share and Update
git remote add origin <url> | add remote origin URL |
git remote remove origin <url> | remove remote origin |
git merge <branch name> | Merge a remote branch into a current branch |
git push origin <branch name> | push local changes to the remote branch |
git pull origin <branch name> | pull remote changes to the local branch |
Tracking Path Changes
git rm <filename> | It will remove the file from the project and stage the removal for the commit |
git mv <existing path> <new path> | change an existing file path and stage the move |
git log --stat -M | Show all commit logs with an indication of any paths that moved |
Rewrite History
git rebase <branch> | Apply any commits of the current branch ahead of the specified one. |
git reset --hard [commit] | clear staging area, rewrite the working tree from a specific commit |
Temporary Commits
git stash | Save modified and stage changes |
git stash list | To see stashed item list |
git stash pop | Popping an item from the stash |
git stash drop | Delete a stash from the queue |
git stash clear | To clear the stash |
Thank You for reading this blog
Parimal Pradhan
You can follow me on LinkedIn for my daily updates:- linkedin.com/in/parimal-pradhan-b62021168
Great initiative by the #trainwithshubham community. Thank you Shubham Londhe