Professional Documents
Culture Documents
LINUX COMMANDS
Ramiz Ahmed
UNIX Commands
Linux Commands
A command is a program which interacts with the
kernel to proide the enironment and per!orm the
!"nctions called !or #$ the "ser%
A command can #e& a #"ilt'in shell command( an
e)ec"ta#le shell !ile* known as a shell script( or a
so"rce compiled* o#+ect code !ile%
,he shell is a command line interpreter% ,he "ser
interacts with the kernel thro"gh the shell% -o" can
write ASCII .te)t/ scripts to #e acted "pon #$ a
shell%
Command Str"ct"re
Linux Commands
Command 0Options1 0Arg"ments1
M"ltiple commands separated #$ ( can #e e)ec"ted
one a!ter the other
2elp 3acilities !or Commands
Linux Commands
,o "nderstand the working o! the command and
possi#le options "se .man command/
Using the 4NU In!o S$stem .in!o* in!o command/
Listing a Description o! a 5rogram .whatis command/
Man$ tools hae a long6st$le option* 766help8* that
o"tp"ts "sage in!ormation a#o"t the tool* incl"ding
the options and arg"ments the tool takes% 9)&
whoami --help
5ipes
Linux Commands
An important earl$ deelopment in Uni) was the
inention o! :pipes*: a wa$ to pass the o"tp"t o! one
tool to the inp"t o! another%
eg% ; who < wc 6l
=$ com#ining these two tools* giing the wc
command the o"tp"t o! who* $o" can #"ild a new
command to list the n"m#er o! "sers c"rrentl$ on the
s$stem
Linux Commands
3ile and Director$ management
cd Change the current directory. With no arguments "cd"
changes to the users home directory. (cd <directory path>)
chmod Change the file permissions.
Ex: chmod 7! myfile : change the file permissions to r"x for
o"ner# rx for group and x for others
Ex: chmod go$%r myfile : &dd read permission for the group
and others (character meanings u'user# g'group# o'other# %
add permission#'remo(e#r'read#"'"rite#x'exe)
Ex: chmod %s myfile ' )etuid *it on the file "hich allo"s the
program to run "ith user or group pri(ileges of the file.
Linux Commands
+here are three such special permissions "ithin ,inux. +hey are:
setuid - used only for applications# this permission indicates that the application is to
run as the o"ner of the file and not as the user executing the application. .t is indicated
*y the character s in place of the x in the o"ner category. .f the o"ner of the file does
not ha(e execute permissions# the ) is capitali/ed to reflect this fact.
setgid - used primarily for applications# this permission indicates that the application
is to run as the group o"ning the file and not as the group of the user executing the
application. +he setgid permission is indicated *y the character s in place of the x in
the group category. .f the group o"ner of the file or directory does not ha(e execute
permissions# the ) is capitali/ed to reflect this fact.
sticky bit - used primarily on directories# this *it dictates that a file created in the
directory can *e remo(ed only *y the user that created the file. .t is indicated *y the
character t in place of the x in the e(eryone category. .f the e(eryone category does not
ha(e execute permissions# the + is capitali/ed to reflect this fact.
Linux Commands
chown Change o"ner.
Ex: cho"n <o"ner!> <filename> : Change o"nership of
a file to o"ner!.
chgrp Change group.
Ex: chgrp <group!> <filename> : Change group of a file
to group!.
cp Copy a file from one location to another.
Ex: cp file! file0 : Copy file! to file0
Ex: cp 12 dir! dir0 : Copy dir! to dir0
md>s"m 3rints the 45 Chec6sum
Linux Commands
ls ,ist contents of a directory.
Ex: ls# ls 1l # ls 1al# ls 1ld# ls 12
('r"xr"xr'x ! 7uan 7uan 8 )ep 09 !0:0 foo )
:more "ill list page "ise
mkdir 4a6e a directory.
Ex: m6dir <directory name> : 4a6es a directory
Ex mkdir p /www/chache/var/log "ill create all the directories
starting from """.
m 4o(e or rename a file or directory.
Ex: m( <source> <destination>
Linux Commands
!ind ;ind files (find <start directory> 'name <file name> 'print)
Ex: find /home name readme -print
()earch for readme starting at home and output full path.)
<=home" $ )earch starting at the home directory and proceed
through all its su*directories
"'name readme" $ )earch for a file named readme
"'print" $ >utput the full path to that file
locate ;ile locating program that uses the slocate data*ase.
Ex: locate 1u to create the data*ase#
locate <file=directory> to find file=directory
Linux Commands
pwd 3rint or list the present "or6ing directory "ith full
path.
rm 5elete files (2emo(e files). (rm 1rf <directory=file>)
rmdir 2emo(e a directory. +he directory must *e empty.
(rmdir <directory>)
to"ch Change file timestamps to the current time. 4a6e
the file if it doesn?t exist. (touch <filename>)
whereis ,ocate the *inary and man page files for a
command. ("hereis <program=command>)
which )ho" full path of commands "here gi(en
commands reside. ("hich <command>)
Linux Commands
3ile iewing and editing
emacs ;ull screen editor.
pico )imple text editor.
i Editor "ith a command mode and text mode. )tarts in command
mode.
gedit @A. +ext Editor
tail ,oo6 at the last !8 lines of a file.
Ex: tail 1f <filename> #
Ex: tail '!88 <filename>
head ,oo6 at the first !8 lines of a file. (head <filename>)
Linux Commands
3ile compression* #acking "p and restoring
compress Compress data.
"ncompress Expand data.
cpio Can store files on tapes. to=from archi(es.
gzip ' /ip a file to a g/ file.
g"nzip ' un/ip a g/ file.
tar &rchi(es files and directories. Can store files and directories
on tapes.
Ex: tar '/c(f <destination> <files=directories> ' &rchi(e copy
groups of files. tar 1/x(f <compressed file> to uncompress
zip 1 Compresses a file to a ./ip file.
"nzip 1 Ancompresses a file "ith ./ip extension.
Linux Commands
cat Bie" a file
Ex: cat filename
cmp Compare t"o files.
c"t 2emo(e sections from each line of files.
di!! )ho" the differences *et"een files.
Ex: diff file! file0 : ;ind differences *et"een file! C file0.
echo 5isplay a line of text.
Linux Commands
grep ,ist all files "ith the specified expression.
(grep pattern <filename/directorypath>)
Ex: ls 1l :grep sid*i : ,ist all lines "ith a sid*i in them.
Ex: grep " 2 " : )earch for 2 "ith a space on each side
sleep 5elay for a specified amount of time.
sort )ort a file alpha*etically.
"ni? 2emo(e duplicate lines from a sorted file.
wc Count lines# "ords# characters in a file. ("c 1c="=l
<filename>).
Linux Commands
-a all
-k kilobytes
-a all
-b bytes
-c total
Linux Commands
Merge incorporates all changes that load from file2 to file3 into
file1. This result ordinarily goes into file1.
newgrp[group]
rev[filename]
w present who users are and what they are doing. The w
utility prints a summary of the current activity on the
system, including what each user is doing.
xlsatoms [-options]
-format
-range
By default all atoms starting from 1(the lowest
value defined by the protocol) are listed until
unknown atom in found.
Linux Commands
indent <filename>
Linux Commands
more <filename>
less <filename>
Linux Commands
THANK YOU