You are on page 1of 8

CompiledbyAluiziousingthebookUNIXINANUTSHELL,ArnoldRobbins,O'ReillyEd.,4thedition,2005,ISBN0596100299.

USEFULUNIXCOMMANDS

cancel cancelprintrequestedwithlp
catfile Displaythefile
catfile1file2>files Combinefile1andfile2intofiles
catfile1>>file2 Appendfile1attheendoffile2
chgrp[options] changethegroupofoneormorefiles.NewgroupiseitheragroupIDnumber
newgroupfiles oragroupnamelocatedin/etc/group.

fquiet(donotprinterrormessages)
hchangethegrouponsymboliclinks(Ifnotused,chgrpwillactinthefile
referencedbythesymboliclink)
Rrecursively(descentingthroughthedirectory,includingsubdirectoriesand
symboliclinks.
chmod[options] Changetheaccessmodeofoneormorefiles.Onlytheownerorprivilegeduser
modefiles maychangeitsmode.Createmodebyconcatenatingwho,opcodeand
permission.

who(uuser)(ggroup)(oother)(aall)
opcode(+addpermission)(removepermission)(=assignpermission,and
removefromthenotassigned)
permission(ror4read)(wor2write)(xor1execute)

Examples:
chmodu+xfile(addpermissiontotheusertoexecutethefile)
chmod751file(chmodu=rwx,g=rx,o=xfile)Theyarethesamecommand.

fquiet
Rrecursive
chown[options] Changetheownershipoffilestonewowner(eitherauserIDoraloginname
newownerfiles from/etc/passwd).

fquiet
hchangethesymboliclink,notthedeferencedfile.
Rrecursive
cprintinformationaboutthefileschanged.
clear cleartheterminaldisplay
cmpfile1file2 Comparetwofiles(0identical)(1different)(2inaccessible)
comm[options] Comparefile1andfile2.Outputsthreecolumns:linesuniquetofile1,lines

1
CompiledbyAluiziousingthebookUNIXINANUTSHELL,ArnoldRobbins,O'ReillyEd.,4thedition,2005,ISBN0596100299.

file1file2 uniquetofile2andlinescommontobothfile.
1suppressprintingcolumn1
13suppressprintingcolumns1and3
cp[options]file1 Makeacopyoffile1withthenamefile2
file2
cp[options]files Copythefilesintodirectorywithsamenamefiles.
directory
fforce(removeexistingfilesinthedestination)
iinteractively(prompforconfirmation)
ppreservetheoriginalfilepermissionsandownershipinthenewfile.
r,Rrecursively(copydirectoriesrecursively)
LusedwithR.ifsymboliclinkpointstoadirectory,recursivelytraverse
thedirectory.
LusedwithR.
smakesymboliclinkinsteadofcopying.
df[[options] Reportthenumberoffreediskblocksandinodesonallmountedfilesystems.
hhumanreadable
kkilobytes
mmegabytes
diff[options]file1 Reportsthedifferencesbetweenfile1andfile2.Printsfile1textflagged(<)and
file2 file2(>).

bignoreblankspaces.
eproduceascriptofcommandstorecreatefile2fromfile1,usingededitor.
Dmergefile1andfile2intoasinglefilecontainingconditionalC
preprocessors(#ifdef).Definingsymbolandthencompilingyeldsfile2.
Notdefiningsymbol,yieldsfile1.
du[options] Printdiskusage.Optionslikedfcommand.
echo[options] Echoargumentstostandardsoutputs.Oftenusedforproducingprompsfrom
[string] shellscripts.
\aalert
\nnewline
\rcarriagereturn
\ttab

2
CompiledbyAluiziousingthebookUNIXINANUTSHELL,ArnoldRobbins,O'ReillyEd.,4thedition,2005,ISBN0596100299.

egrep[options] Searchfilesthatmatcharegularexpression[regexp].Supportmetacharacters
[regexp][files] +,?,(),etc.Butmustbeenclosedwithquotes.

nprintthelinematching.
vprintlinesthatdon'tmatch[regexp].
Example:egrep'(Victor|Victoria)'fileSeachVictororVictoriainfile.
fgrep[options] Fastgrep.Seachfilesforlinesthatmatchaliteral.Optionsarethesameasfor
[pattern][files] egrep.
find[options] Findandlocateallthefilesinsidethepathnamespecifiedthatmatchessome
pathnamecondition condition(name.type,size,user).

Examples:
find/homenamechapter1
find/home/usrname'memo*'userann
find/mtime2(findfilesmodifiedwithinthelasttwodays)
find/size10k(findfileswith10kB)
gcc GNUCcompiler.

ccreateslinkableobjectfile(.o)foreachsourcefilebutdonotcallthelinker.
ofilespecifyoutputfileasfile.Defaultisa.out
Wallenablealmostallpossiblewarnings.
lmwhenusingthemath.hfunction.
gftp Tranferfilestoandfromaremotenetworksitehostname.Belowispresentedan
exampleofgftpscreenandloginconfigurationnecessarytoaccessOMG

computers/homes/usernamedirectory.

gunzip[gzip Restorethefile.gz.
options][files]

3
CompiledbyAluiziousingthebookUNIXINANUTSHELL,ArnoldRobbins,O'ReillyEd.,4thedition,2005,ISBN0596100299.

gzip[options][files] Reducethesizeofoneormorefilesandmovetofile.gz.

fforce
qquite(suppresswarnings)
rrecursivelywalkthecurrentdirectorytreeandcompressallfilesfound.
vdisplaythenameandpercantageofreduction.
head[options] Printthefirstfewlinesoffiles(defaultis10lines).
[files]
n50printthefirst50lines.
hostname[option] Printnameofcurrenthostsystem.

idisplaytheiIPaddressofthehost.
id[options] displayinformationaboutyourselforanotheruser:usedID,groupID,etc.
[username]
kill[options]IDs TerminateoneormoreprocessesIDs.Youmustowntheprocessorbea
privilegeduser.
llistthetypesofsignals.
s9sendsignal9(completekill).
locate[pattern] Searchfilesmatchingthepattern.
lp[options][files] Sendfilestoapriner.
ls[options][names] Listthefilesinthecurrentdirectory.Withnamesisspecified,listthefiles
insidethedirectorynamesorthatmatchafilenames.

alistallfiles,includingthehidden.files.
dlistonlydirectoryinformation,notitscontents.Usedwithl.
hhumanreadable,usingabbreviationsforkilobyte,megabyte,etc.
ksizeinkilobytes
llongformatlist(includespermissions,owner,size,modificationtime,etc).
rlistfilesinreverseorder(bynameorbytime).
Rrecursivelylistsubdirectories.
slistsizeinblocks(1block=512KB)
tlistfilesaccordingtomodificationtime(newestfirst)
ulistfilesaccordingtothefileaccesstime.
make[options] Updateoneormoretargetsaccordingtodependencyinstructionsina
[targets] descriptionfile(makefile)inthecurrentdirectoty.
mansubject Displayinformationaboutasubject(nameofacommand).
mkdir[options] Createoneormoredirectories.Youmusthavewritepermissionintheparent

4
CompiledbyAluiziousingthebookUNIXINANUTSHELL,ArnoldRobbins,O'ReillyEd.,4thedition,2005,ISBN0596100299.

directories directoryinordertocreateadirectory.

msettheaccessmode(ex.mkdirmfile1)(toreadexecuteonlydirectory).
more[options][file] Displayfilecontentonaterminal.Onescreenfulatatime.Tochangethenext
screenfuluseSPACEBARandtoscrollthelinesuseENTER.hforhelp,/
tosearch,or:ntogotothenextfile.
mount[options] Thefilestructureondeviceismountedondirectory.Ifnodevicespecified,
[[device] mountlooksforanentryin/etc/fstabtofindwhatdeviceisassociated
directories] withthegivendirectory.Directorywhichmustexistandshouldbeempty,
becometherootofthenewlymountedfilestructure.Ifmountisinvoked
withnoarguments,itdisplaysthenameofeachmounteddevice,the
directoryonwhichitismounted,itsfilesystemtype,andanymount
optionsassociatedwiththedevice.

amountallfilesystemslistedin/etc/fstab.Usettolimitthistoall
filesystemsofaparticulartype.
mv[options] Movefilesanddirectoriesaroundonthesystemandtorenamethem.
sourcestargets
Source Target Result
file name renamefileasname
file existingfile overwriteexistingfilewithsourcefile
directory name renamedirectoryasname
directory existingdirectory movedirectorytobeasubdirectoryof
existingdirectory
oneormorefiles existingdirectory movefilestodirectory

fforce(forcethemoveeveniftargetfileexists)
iinteractive(promptforay(yes)responsebeforeoverwritinganexisting
target.
uDonotremoveafileorlinkifitsmodificationdateisthesameasornewer
thanthatofitsreplacement.
passwd[options] createorchangeapasswordassociatedwithausername.Onlytheownerora
[user] privilegedusermaychangeapassword.

5
CompiledbyAluiziousingthebookUNIXINANUTSHELL,ArnoldRobbins,O'ReillyEd.,4thedition,2005,ISBN0596100299.

ps[options] Reportonactiveprocesses.Whenneededtoforceoneprocesstofinish,ps
showstheprocessesandkillallowstofinishit.

u[user]dispalyprocessesrunningbyuser.Ifnotspecifiedtheuser,displays
fortheactualuser.
rshowprocessescurrentlyrunning.
pwd PrintingWorkingDirectory(pwd).Printthefullpathnameofthecurrent
directory
rm[options]files Deleteoneormorefiles.Toremoveafile,youmusthavewritepermissionon
thedirectorythatcontainsthefile,butyouneednothavepermissionon
thefileitself.Ifyoudonothavewritepermissiononthefile,youare
prompted(yorn)tooverwrite.

fForceremovingwriteprotectedfileswithoutprompting.
iPrompforyorntoremovethefile.
rmdir[options]files Deletethenameddirectories(thedirectoryitself,notthecontents).Directories
aredeletedfromtheparentdirectoryandmustbeempty.

rremovedirectoriesandthefilesinside.

script[options] Createarecordofyourloginsession,storinginfileeverythingthatdisplayson
[file] thescreen.

aappendthescriptrecordtofile.
sed[options][files] Streameditor.Editoneormorefileswithoutuserinteraction.

eapplytheinstructionstothefiles.
fapplythesetofinstructionsfromtheeditingscript.
sortfile Sortthelinesoffileinalphabeticalorder.
ssh[options] Securalylogauserintoaremotesystemandruncommandsonthatsystem.
hostname HOSTANME:user@hostname(ex.aluizio@peel.omg.unb.ca).
[command]
XenableX11forwarding.

6
CompiledbyAluiziousingthebookUNIXINANUTSHELL,ArnoldRobbins,O'ReillyEd.,4thedition,2005,ISBN0596100299.

stty[options] SetterminalI/Ooptionstothecurrentdevice.
[modes] Asaprivilegeduser,youcansetorreadsettingsfromanotherdeviceusingthe
syntax:stty[options][modes]<device

Fdevicereadorchangesettingsofdeviceterminalinsteadofthecurrent
terminal.

controlmodes(n(setterminalbaudrateton(e.g.19200)),inputmodes,output
modes,etc.
su[options][user] Loginasuser.Ifnouserspecified,becomesuperuser.EnterEOFtoterminate.
[shellargs]
sudo(usefulto changetheuser(eg.suuser)
install).
tail[options]file Printthelast10linesofafile.

n20showthelast20lines.

Eg.grep'<title>'file|tailn20(showthelast20linescontaininginstancesof
title).
tar[options][files] Copyfilesorrestorefilesfromtape(tapearchive).Ifanyfilesaredirectories,tar
actsontheentiresubtree.Veryused(cvftoarchiveandxvftoextract).
ccreateanewarchive.
xextractfilesfromarchive.
vprintfunctionletter(xforextractionandaforarchive)
farchstorefilesinorextractfilesfromarchivearch.
tlistthecontentslikelsl.

Examples:
tarcvf/dev/rmt/0/bin/usr/bin(Createanarchiveof/binand/usr/bin,show
thecommandworkungandwritethetapein/dev/rmt/0).
tartvf/dev/rmt/0(listthearchivescontentinaformatlikelsl).
tarxvf/dev/rmt/0/bin(Extractthe/bindirectory)
tty[options] Printthedevicenameofyourterminal.

7
CompiledbyAluiziousingthebookUNIXINANUTSHELL,ArnoldRobbins,O'ReillyEd.,4thedition,2005,ISBN0596100299.

stty[options] SetterminalI/Ooptionstothecurrentdevice.
[modes] Asaprivilegeduser,youcansetorreadsettingsfromanotherdeviceusingthe
syntax:stty[options][modes]<device

Fdevicereadorchangesettingsofdeviceterminalinsteadofthecurrent
terminal.

controlmodes(n(setterminalbaudrateton(e.g.19200)),inputmodes,output
modes,etc.
umount[options] Unmountafilesystem.Announcestothesystemthaaremovablefilestructure
[arguments] previouslymountedonthespecifieddirectoryistoberemoved.Abusy
filesystem(withopenfilesorwithadirectorythatissomeprocesses's
currentlydirectory)cannotbeunmounted.

aummountallfilesystemsspecifiedin/etc/mtab.
fforcetheummount.
users[file] Displaythecurrentlyloggedinusersasaspacedseparatedlist.
which[options] Listwhichfilesareexecutedifthenamedcommandsarerunasacommand.
[files] whichreadstheuser's.cshrcfile(usingthesourcebuiltincommand),
checkingaliasesandsearchingthepathvariable.

aprintallmatches,notjustthefirst

example:$whichfilels
/usr/bin/file
:lsaliasedtolssFC
who[options][file] Withnooptions,listthenamesofuserscurrentlyloggedintothesystem.

amiprintusernameoftheinvokinguser(similartoid)
ureportterminalusage.Presentidletime(HOURS:MINUTES,.(dotless
thanoneminute),orold(morethan24h).
Hprintheadings.

You might also like