Show Menu
Cheatography

Basic Linux Commands Cheat Sheet (DRAFT) by

This is a cheatsheet for Linux OS

This is a draft cheat sheet. It is a work in progress and is not finished yet.

Linux

To create a folder
mkdir <fo­lde­r_n­ame>
To get into a folder
cd <fo­lde­r_n­ame>
To create a file
vim <file name>
To display the contents of a file
cat <file name>

Handy commands

To get into a folder
cd <folder name>
To get the list of available files and folders in a directory
ls
To get the current logged in user
whoami
To get the present working directory
pwd
To get the list of all commands used
history
To clear screen
clear
To get date and time
date
To get kernel name
uname
To get kernel version
uname -r
TO get manual of a command
man <co­mmand name>

Copy / Move

To copy a file
cp <op­tio­n> <so­urc­e> <de­sti­nat­ion>
To delete a file
rm <op­tio­n> <path to the file>>
To move/r­ename a file
mv <so­urc­e> <de­sti­nat­ion>

User management

To add a new user account
sudo useradd <user name>
To create a password to the user account
sudo passwd <user name>
To create a new group
sudo group add <group name>
To add user to a group
sudo gpasswd -a <user name> <group name>
To delete a user
sudo userdel <user name>
To delete a group
sudo groupdel <group name>
 

File permis­sions

To change permission
chmod <mo­de> <fi­le/­dir­ect­ory>
To change ownership
chown <ow­ner> <fi­le/­dir­ect­ory>
To change group ownership
chgrp <group name> <fi­le/­dir­ect­ory>

Access Control Lists(ACL)

To get ACL entries of a file or directory
getfacl <fi­le/­dir­ect­ory>
To set ACL to a file/f­older
setfacl -m u:user­nam­e:p­erm­issions <fi­le/­dir­ect­ory>
To remove ACL of a user
setfacl -x u:user­nam­e:p­erm­issions <fi­le/­dir­ect­ory>
To set ACL of a group
setfacl -m g:grou­pna­me:­per­mis­sions <fi­le/­dir­ect­ory>
To remove ACL of a group
setfacl -x g:grou­pna­me:­per­mis­sions <fi­le/­dir­ect­ory>
 
Tp set ACL
setfacl [options] -m u:user­nam­e:p­erm­issions file/d­ire­ctory

Gloal regular expres­sions Print<

Case-i­nse­nsitive pattern search
grep <pa­tte­rn>­<fi­le_­nam­e>
Display line numbers
grep -n <pa­tte­rn> <fi­le>
Search recurs­ively in direct­ories
grep -r <pa­tte­rn> <di­rec­tor­y>
Regular expression search
grep -E <st­rin­g/e­xpr­ess­ion> file
Search recurs­ively in direct­ories:
grep -r <st­rin­g/e­xpr­ess­ion> /path/­to/­dir­ectory

Find

Find files by name
find /path/­to/­dir­ectory -name "­*.t­xt"
Find direct­ories
find /path/­to/­dir­ectory -type d
Display bottom few line of code
tail -n <no of lines to displa­y><file name>
Display top few line of code
tail -n <no of lines to displa­y><file name>
Create a tar archive
tar -cvf <tar archive file> <path to file or folder to be archiv­ed>
Awk command syntax
awk 'pattern { action }' input_file