0% found this document useful (0 votes)
16 views5 pages

Linux Command Line Cheat Sheet - For Beginner & Advanced

This document is a comprehensive Linux Command Line Cheat Sheet that provides various commands for file manipulation, process management, networking, and text processing. It includes examples of command usage, options, and syntax for commands like cp, mv, ps, find, and grep. The cheat sheet is aimed at helping users navigate and utilize the Linux command line effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
16 views5 pages

Linux Command Line Cheat Sheet - For Beginner & Advanced

This document is a comprehensive Linux Command Line Cheat Sheet that provides various commands for file manipulation, process management, networking, and text processing. It includes examples of command usage, options, and syntax for commands like cp, mv, ps, find, and grep. The cheat sheet is aimed at helping users navigate and utilize the Linux command line effectively.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

Linux Command Line Cheat Sheet

by SathyaNarayanan (Sathyanarayanan) via cheatography.com/136085/cs/29006/

shell prompt Manipu​lating Files and Direct​ories (cont) Process commands

# Super User ln create Hard and symbolic link ps aux BSD style ou
$ normal user * any character fg %1 jobs
? any single character kill -1 13456 kill process id
simple commands [ character] any character that is a member of character
SIGNALS: HUP, INT, KILL, TERM,C​ON
date display current date and time [ ! character] any character that is not a member of character
TSTP. WINCH
[[:cla​ss:]] any character that is a member of class
cal display current month calendar
df displays disk usages Find command
command Options : cp, mv
free display memory usage cmin match attrib​ute​s/f​ile​s/dir mo
i intera​ctive same
cnewer match file/dir whose conten
in mv
Navigation modified n*24 ago
a copy files and direct​ories of all attrib​utes, -
cd change the current diretcory ctime n match file or direct whose c
ownership and permission
ls list the directory modified n*24 hrs ago
r recurs​ively copies direct​ories and contents same
empty match empty files and direc
cd - : change to previous working directory in mv
cd ~username : change to home directory group match files or direc belongin
u copy the files that don't exists same
name
in mv
Exploring Filesystem iname pattern like the iname test b
v verbose, inform​ative message same
file Determine file type in mv inum n match files with inode numb
less view file contents mmin n match files or dir whose con
Command Substi​tution minutes ago
ls
-l diplay in long format echo $(ls) mtime n match files or dir whose con
-h human readable ls -l $(which cp) new method n*24 hours ago
-a list all files even those hidden, name match files and dir with spe
ls -l which cp back tick, old method
-d directory pattern
-F option will append an indictor charactor to
Process nouser match files and dir that don
the end of listed names
ps reports snap shot of current process nogroup match files and dir that don
-r display result in reverse order
-S sort by file Size top diskplays task perm match files and direct​ories s
-t modifi​cation time mode
jobs list active jobs

bg place a job in the background


Manipu​lating Files and Direct​ories
fg place a job in the foreground
cp copy the files
kill send a signal to process
mv move the files from one folder to other
killall kill process by name
mkdir creates a directory
rm remove files and direct​ories

By SathyaNarayanan Published 19th October, 2021. Sponsored by ApolloPad.com


(Sathyanarayanan) Last updated 18th October, 2021. Everyone has a novel in them.
cheatography.com/sathyanarayanan/ Page 1 of 5. https://apollopad.com
Linux Command Line Cheat Sheet
by SathyaNarayanan (Sathyanarayanan) via cheatography.com/136085/cs/29006/

Find command (cont) Find Options - scope (cont) man page options (c

samefile matches files that share the same inode number mindepth min num of level that find will descend into a 4 Special files such
name as file name directory when performing test and action drivers
size n match file size of n mount direct find not to traverse direct​ories that mounter 5 file formats
type c match file type of c on other filesystem 6 Games and scree
user match file and direct​ories belong to user 7 misc

find %test %action %options 8 system admini​stra


Tricks
find ~
clear clears the screen
find ~ | wc -l Redire​ction
find ~ -type d | wc -l history stores the history
cat concat​enates
------​---​---​---​---​---​------- script file capture all command execution in a file
sort sort the file
history: CTRL + {R, P }
uniq report or omit
b block
!!number : command history number
c character special device grep print lines mat
!! : last command
d directory head prints first few
!?string : history containing last string
f regular file
!string : history containing last string tail prints las few
l symbolic link
export HISTCO​NTR​OL=​ign​oredups tee reads stdin an
export HISTSI​ZE=​10000 and file
Find Logical Operator
wc count number
and Working With Commands
bytes
or type Indicate how command name is interp​reted
not which display which executable program will be executed Redire​ction Operato

find ~ \( -type f -not -perm 0600 \) -or \( -type d -not -perm -700 man Display manual page ls -l /usr/bin >file
\) apropos Display approp​riate command ls -l /usr/bin 2>file
info Display command Info entry ls -l /usr/bin > ls-
find -actions
whatis Display brief descri​ption of command output 2>&1
delete
alias create an alias for command ls -l /usr/bin &> ls-
ls output
print man page options ls -l /usr/bin 2>
quite /dev/null
1 User commands
find ~ -type f -name '*.BAR] -print 2 Progra​mming interface for system calls
Pipelines
find ~ -type f -and -name '*.BAR -and -print
3 Progra​mming interface for C Library
|
Userde​fined actions ls -l /usr/bin/ |
-exec comman{} tee out | sort

find ~ -type f -name 'foo*'​ -exec ls -l '{}' +


find ~ -type f -name 'foo*'​ -exec ls -l '{}' ';'

Find Options - scope

depth to process a directory files before the dir itself


maxdepth max num of level that find will descend into a
directory when performing test and action

By SathyaNarayanan Published 19th October, 2021. Sponsored by ApolloPad.com


(Sathyanarayanan) Last updated 18th October, 2021. Everyone has a novel in them.
cheatography.com/sathyanarayanan/ Page 2 of 5. https://apollopad.com
Linux Command Line Cheat Sheet
by SathyaNarayanan (Sathyanarayanan) via cheatography.com/136085/cs/29006/

view the world as SHELL viewed Login & Non Login Shell (cont) Networking (cont)

echo * expands all files in the path ~/.bashrc : User config​uration sftp Secure File transfer program
echo D* expands all files with OpenSSH package includes two programs that c
starting D Quoting
encrypted tunnel to copy file across the network.
$((exp​res​sion)) Arithe​matic expression echo This This is a test; space is stripped a) scp
is a test b) sftp
echo 75
$(($((5*2))3)) echo "This This is a test
is a test" SFTP doesn't require ftp server to connect, it nee
ls -l which cp backtick instead of
machines, any machine that has ssh running, we
expression echo $(echo foo) $((2+2))
files to server
'$(echo
Braces Expansion foo)
Archiving and Backup
$((2+2))'
echo Front-​{A,​B,C​}- Front-​A-Back, Front-​‐
gzip Compress or expand files
Back B-Back, Front-​C-Back echo the $5 is undefined variable so it supress
total is the value, output will be like the total bzip2 A block sorting file compressor
echo {Z..A} Z Y X W V U .....A
$500.00 is 00.00 tap tape archving utility
mkdir {2009..20​11}​- creates a directory for
" " : all special character looses its meaning, zip Package and compress files
0{​1..9} {2009..20​11}​- 12 months in 2009 to
exception ($, \, `) rsync remote file and dir synchr​oni​zation
{1​0..12} 2011
' ' : all special character looses its meaning, and no
unzip Unzip the gzip files
exceptions
Enviro​nment
compre​ssion algorithm: Lossy and Lossless
printenv Print part of all of the enviro​nment
Searching For Files
set set shell options Hacks
locate find files by name
export export enviro​nment to subseq​‐ Examples:
find search for files in a dir
uently executed programs ssh remote-sys 'tar cf - Document' | tar xf -
xargs build and exec cmd lines from stdin
alias create an alias for command find playground -name 'file-A' | tar czf playgr​oun​d
touch change the file times find playground -name 'file-A' | tar cjf playgr​oun​d.
Login & Non Login Shell stat display file or filesystem status rsync -av --delete --rsh=ssh /etc /home /usr/local

Login Shells : - or Hyphen is the stdin and stdout


Networking
/etc/p​rofile : global config​uration
~/.bas​h_p​rofile : personal startup efile Ping Send ICMP packets Text processing examples
~/.bas​h_l​ogin. : if ~/.bas​h_p​rofile is not found, traceroute Print route packets to a network cat -A $FILE
bash attempts to read this script
netstat print network connec​tion, routing table,
~/.profile : if neither ~/.bas​h_p​rofile & ~/.bas​‐
interface stats sort file1.txt file2.txt file3.txt > final_​sor​‐
h_login bash reads this file
ftp/lftp Internet file transfer program ted​_li​st.txt
Non Login shells :
wget Non Intera​ctive network downloader ls - l | sort -nr -k 5
/etc/b​ash.bashrc : Global config​uration
ssh OpenSSH SSH Client (remote login
program)
scp secure copy

By SathyaNarayanan Published 19th October, 2021. Sponsored by ApolloPad.com


(Sathyanarayanan) Last updated 18th October, 2021. Everyone has a novel in them.
cheatography.com/sathyanarayanan/ Page 3 of 5. https://apollopad.com
Linux Command Line Cheat Sheet
by SathyaNarayanan (Sathyanarayanan) via cheatography.com/136085/cs/29006/

Text processing examples (cont) Permis​sions Packaging Ssystem

sort --key=1,1 --key=2n key field 1,1 sort and second id display user identity Debian Debain, ubuntu, xandros,
distor.txt column sort by numeric chmod change's file mode Style (.dep)
sort foo.txt | uniq -c to find repetition umask set the default file permission RedHat Fedora, CentOS, Redhat
cut -f 3 distro.txt cut column 3 style(.rpm) Mandriva, PCLinuxOS
su Run a shell as another user
cut -c 7-10 cut character 7 - 10 sudo Execute command as another
Install from Repo
cut -d ':' -f 1 /etc/p​assword delimiter : user
debian apt-get install packag​e_n
sort -k 3.7nbr -k 3.1nbr -k 3 rd field 7 the character, 3rd field 1 chown changes file's owner
redhat yum install packag​e_nam
3.4nbr distro.txt character chgrp change file groups owner
paste file1.txt file2.txt > merge two files passwd change a user password Operation on Package File
newfil​e.txt
Debian :
join file1.txt file2.txt join on common two fields Read,W​rite, Execute
dpkg --install packag​efile
- | rwx | rw- | type | owner | group | apt-get remove packag​e_name
Text processing
r-- world apt-get update
cat concat​enate files and print stdout dpkg --list
type
sort sort lines of text files - regular file dpkg --status packag​e_name
uniq report or omite repeated lines d directory apt-cache show packag​e_name (info ab
l symbolic link dpkg --search file_name (finding which p
cut remove section from each line of files
c character device Redhat :
paste merge lines of files
b block device rpm -i packag​efile
join join lines of two files on a common field yum erase packag​e_name
comm compare two sorted files line by line File Mode [Octal] yum update
rpm -u packag​efile
diff compare files 000 ---
rpm -qa. (list)
patch apply a diff file to original 001 --x
rpm -q packag​e_name (check package i
tr translate 010 -w- yum info packag​e_name
sed stream editor 011 -wx rpm -qf file_name (finding which package
aspel intera​ctive spell checker 100 r--
storage media
101 r-x
mount mount a filesystem
110 rw-
ummount unmount a file system
111 rwx
fdisk partition table manipu
chmod 0600 file [ rw- is set for owner ]
fsck check and repair files

Mode symbolic notation fdformat format floppy disk

ugo user, group, others


u+x giving exeute permission for
user
u=rw,o=x giveing user read write and
others execute perm

chmod u=rw,o=x file.txt

By SathyaNarayanan Published 19th October, 2021. Sponsored by ApolloPad.com


(Sathyanarayanan) Last updated 18th October, 2021. Everyone has a novel in them.
cheatography.com/sathyanarayanan/ Page 4 of 5. https://apollopad.com
Linux Command Line Cheat Sheet
by SathyaNarayanan (Sathyanarayanan) via cheatography.com/136085/cs/29006/

storage media (cont) grep examples Text Processing Hacks

mkfs create a file system grep -h '.zip' file.list . is any character diff -c
dd write a block oriented data directly to a grep -h '^zip' file.list starts with zip diff -u
device grep -h 'zip$' file.list ends with zip diff -Naur oldfile newfile >
geniso​‐ create an ISO 9660 image file grep -h '^zip$' file.list containing only zip diff_file
image patch < diff_file
grep -h '[^bz]zip' file.list not containing b and z
wodim Write data to optical storage device
grep -h '^[A-Z​a-z​0-9]' file.list file containing any valid names
md5sum calculate md5sum echo "​secret text" | tr a-zA-Z
grep Quanti​fiers n-za-m​N-ZA-M
dd if=/de​v/cdrom of=ubu​ntu.iso (create image file)
fsck /dev/sdb1 (check file system) echo "​frperg grkg" |
? match element zero or one time
mkfs -t ext3 /dev/sdb1 (create ext3 file system) n-za-m​N-ZA-M
* match an element zero or more times
unmount /dev/sdb1 (unmount the file system, before -, +, ! : deleted, added, line
+ Match an element one or more times
changing the partition table)
fdisk /dev/sdb (create a partition table ) {} match an element specfic number of times
$diff -Naur file1.txt file2.txt >
It always match the preceding element $patch < diff_f​ile.txt
POSIX charcter class {n} match the preceding element occurs n times patching file file1.txt
character class {n,m} match the preceding element occurs at least n times, but
alnum, word , alpha blank, cntrl, digit, graph,​lowe, no more than m times rotate by 13 places (ROT13
punct, print, space, upper, xdigit {n,} match the preceding element if it occurs n or more times
format: [ :alnum: ] {,m} match the preceding element if it occurs no more than m
times
echo $LANG
export LANG=POSIX
grep hacks

grep Options grep -E '^\([0​-9]​{3}​\).[​0-​9]{​3}.[​0-​9]{3}$' phone.txt


locate --regex 'bin/(​bz|​gz|​zip)'
i ignore case
for i in {1..10}; do echo "​(${​RAN​DOM​:0:​3})​-${​RAN​DOM​:0:​3}-​${R​‐
v invert match
AND​OM:​0:3​}"; done >>p​hon​e.txt
c print number of matches
l print the name of each file that contain matches
L print only the names of files that don't match
n print match line with the number
h for multiple output supress the output of filename

grep [options] regex [file....]

metach​ara​cters : ^ $ . [ ] {} - ? * + ( ) | \

By SathyaNarayanan Published 19th October, 2021. Sponsored by ApolloPad.com


(Sathyanarayanan) Last updated 18th October, 2021. Everyone has a novel in them.
cheatography.com/sathyanarayanan/ Page 5 of 5. https://apollopad.com

You might also like