Linux Command Line Cheat Sheet - For Beginner & Advanced
Linux Command Line Cheat Sheet - For Beginner & Advanced
# 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,CON
date display current date and time [ ! character] any character that is not a member of character
TSTP. WINCH
[[:class:]] 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 attributes/files/dir mo
i interactive same
cnewer match file/dir whose conten
in mv
Navigation modified n*24 ago
a copy files and directories of all attributes, -
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 recursively copies directories 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, informative 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 Substitution 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 directories s
-t modification time mode
jobs list active jobs
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 directories that mounter 5 file formats
type c match file type of c on other filesystem 6 Games and scree
user match file and directories belong to user 7 misc
find ~ \( -type f -not -perm 0600 \) -or \( -type d -not -perm -700 man Display manual page ls -l /usr/bin >file
\) apropos Display appropriate command ls -l /usr/bin 2>file
info Display command Info entry ls -l /usr/bin > ls-
find -actions
whatis Display brief description 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 Programming interface for system calls
Pipelines
find ~ -type f -and -name '*.BAR -and -print
3 Programming interface for C Library
|
Userdefined actions ls -l /usr/bin/ |
-exec comman{} tee out | sort
view the world as SHELL viewed Login & Non Login Shell (cont) Networking (cont)
echo * expands all files in the path ~/.bashrc : User configuration 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.
$((expression)) Arithematic 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..2011}- creates a directory for
" " : all special character looses its meaning, zip Package and compress files
0{1..9} {2009..2011}- 12 months in 2009 to
exception ($, \, `) rsync remote file and dir synchronization
{10..12} 2011
' ' : all special character looses its meaning, and no
unzip Unzip the gzip files
exceptions
Environment
compression algorithm: Lossy and Lossless
printenv Print part of all of the environment
Searching For Files
set set shell options Hacks
locate find files by name
export export environment 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 playground
touch change the file times find playground -name 'file-A' | tar cjf playground.
Login & Non Login Shell stat display file or filesystem status rsync -av --delete --rsh=ssh /etc /home /usr/local
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/password delimiter : user
debian apt-get install package_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 package_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
newfile.txt
Debian :
join file1.txt file2.txt join on common two fields Read,Write, Execute
dpkg --install packagefile
- | rwx | rw- | type | owner | group | apt-get remove package_name
Text processing
r-- world apt-get update
cat concatenate files and print stdout dpkg --list
type
sort sort lines of text files - regular file dpkg --status package_name
uniq report or omite repeated lines d directory apt-cache show package_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 packagefile
join join lines of two files on a common field yum erase package_name
comm compare two sorted files line by line File Mode [Octal] yum update
rpm -u packagefile
diff compare files 000 ---
rpm -qa. (list)
patch apply a diff file to original 001 --x
rpm -q package_name (check package i
tr translate 010 -w- yum info package_name
sed stream editor 011 -wx rpm -qf file_name (finding which package
aspel interactive 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
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-Za-z0-9]' file.list file containing any valid names
md5sum calculate md5sum echo "secret text" | tr a-zA-Z
grep Quantifiers n-za-mN-ZA-M
dd if=/dev/cdrom of=ubuntu.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-mN-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_file.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
metacharacters : ^ $ . [ ] {} - ? * + ( ) | \