Unix Commands

You might also like

You are on page 1of 8

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

USEFULUNIXCOMMANDS
cancel catfile catfile1>>file2 chgrp[options] newgroupfiles cancelprintrequestedwithlp Displaythefile Appendfile1attheendoffile2 changethegroupofoneormorefiles.NewgroupiseitheragroupIDnumber oragroupnamelocatedin/etc/group. fquiet(donotprinterrormessages) hchangethegrouponsymboliclinks(Ifnotused,chgrpwillactinthefile referencedbythesymboliclink) Rrecursively(descentingthroughthedirectory,includingsubdirectoriesand symboliclinks. chmod[options] modefiles Changetheaccessmodeofoneormorefiles.Onlytheownerorprivilegeduser 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] newownerfiles Changetheownershipoffilestonewowner(eitherauserIDoraloginname from/etc/passwd). fquiet hchangethesymboliclink,notthedeferencedfile. Rrecursive cprintinformationaboutthefileschanged. clear cmpfile1file2 comm[options] cleartheterminaldisplay Comparetwofiles(0identical)(1different)(2inaccessible) Comparefile1andfile2.Outputsthreecolumns:linesuniquetofile1,lines 1

catfile1file2>files Combinefile1andfile2intofiles

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

file1file2

uniquetofile2andlinescommontobothfile. 1suppressprintingcolumn1 13suppressprintingcolumns1and3 Makeacopyoffile1withthenamefile2 Copythefilesintodirectorywithsamenamefiles. fforce(removeexistingfilesinthedestination) iinteractively(prompforconfirmation) ppreservetheoriginalfilepermissionsandownershipinthenewfile. r,Rrecursively(copydirectoriesrecursively) LusedwithR.ifsymboliclinkpointstoadirectory,recursivelytraverse thedirectory. LusedwithR. smakesymboliclinkinsteadofcopying. Reportthenumberoffreediskblocksandinodesonallmountedfilesystems. hhumanreadable kkilobytes mmegabytes Reportsthedifferencesbetweenfile1andfile2.Printsfile1textflagged(<)and file2(>). bignoreblankspaces. eproduceascriptofcommandstorecreatefile2fromfile1,usingededitor. Dmergefile1andfile2intoasinglefilecontainingconditionalC preprocessors(#ifdef).Definingsymbolandthencompilingyeldsfile2. Notdefiningsymbol,yieldsfile1.

cp[options]file1 file2 cp[options]files directory

df[[options]

diff[options]file1 file2

du[options] echo[options] [string]

Printdiskusage.Optionslikedfcommand. Echoargumentstostandardsoutputs.Oftenusedforproducingprompsfrom shellscripts. \aalert \nnewline \rcarriagereturn \ttab

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

egrep[options] [regexp][files]

Searchfilesthatmatcharegularexpression[regexp].Supportmetacharacters +,?,(),etc.Butmustbeenclosedwithquotes. nprintthelinematching. vprintlinesthatdon'tmatch[regexp]. Example:egrep'(Victor|Victoria)'fileSeachVictororVictoriainfile.

fgrep[options] [pattern][files]

Fastgrep.Seachfilesforlinesthatmatchaliteral.Optionsarethesameasfor 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 options][files]

Restorethefile.gz.

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

gzip[options][files] Reducethesizeofoneormorefilesandmovetofile.gz. fforce qquite(suppresswarnings) rrecursivelywalkthecurrentdirectorytreeandcompressallfilesfound. vdisplaythenameandpercantageofreduction. head[options] [files] hostname[option] Printthefirstfewlinesoffiles(defaultis10lines). n50printthefirst50lines. Printnameofcurrenthostsystem. idisplaytheiIPaddressofthehost. id[options] [username] kill[options]IDs displayinformationaboutyourselforanotheruser:usedID,groupID,etc. TerminateoneormoreprocessesIDs.Youmustowntheprocessorbea privilegeduser. llistthetypesofsignals. s9sendsignal9(completekill). Searchfilesmatchingthepattern. Sendfilestoapriner.

locate[pattern] lp[options][files]

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] [targets] mansubject mkdir[options] Updateoneormoretargetsaccordingtodependencyinstructionsina descriptionfile(makefile)inthecurrentdirectoty. Displayinformationaboutasubject(nameofacommand). 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] [[device] directories] Thefilestructureondeviceismountedondirectory.Ifnodevicespecified, mountlooksforanentryin/etc/fstabtofindwhatdeviceisassociated withthegivendirectory.Directorywhichmustexistandshouldbeempty, becometherootofthenewlymountedfilestructure.Ifmountisinvoked withnoarguments,itdisplaysthenameofeachmounteddevice,the directoryonwhichitismounted,itsfilesystemtype,andanymount optionsassociatedwiththedevice. amountallfilesystemslistedin/etc/fstab.Usettolimitthistoall filesystemsofaparticulartype. mv[options] sourcestargets Movefilesanddirectoriesaroundonthesystemandtorenamethem. Source file file directory directory oneormorefiles Target name existingfile name Result renamefileasname overwriteexistingfilewithsourcefile renamedirectoryasname

existingdirectory movedirectorytobeasubdirectoryof existingdirectory existingdirectory movefilestodirectory

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

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

ps[options]

Reportonactiveprocesses.Whenneededtoforceoneprocesstofinish,ps showstheprocessesandkillallowstofinishit. u[user]dispalyprocessesrunningbyuser.Ifnotspecifiedtheuser,displays fortheactualuser. rshowprocessescurrentlyrunning.

pwd rm[options]files

PrintingWorkingDirectory(pwd).Printthefullpathnameofthecurrent directory Deleteoneormorefiles.Toremoveafile,youmusthavewritepermissionon thedirectorythatcontainsthefile,butyouneednothavepermissionon thefileitself.Ifyoudonothavewritepermissiononthefile,youare prompted(yorn)tooverwrite. fForceremovingwriteprotectedfileswithoutprompting. iPrompforyorntoremovethefile.

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

script[options] [file]

Createarecordofyourloginsession,storinginfileeverythingthatdisplayson thescreen. aappendthescriptrecordtofile.

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

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

stty[options] [modes]

SetterminalI/Ooptionstothecurrentdevice. Asaprivilegeduser,youcansetorreadsettingsfromanotherdeviceusingthe syntax:stty[options][modes]<device Fdevicereadorchangesettingsofdeviceterminalinsteadofthecurrent terminal. controlmodes(n(setterminalbaudrateton(e.g.19200)),inputmodes,output modes,etc.

su[options][user] [shellargs] sudo(usefulto install). tail[options]file

Loginasuser.Ifnouserspecified,becomesuperuser.EnterEOFtoterminate. changetheuser(eg.suuser) 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.

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

stty[options] [modes]

SetterminalI/Ooptionstothecurrentdevice. Asaprivilegeduser,youcansetorreadsettingsfromanotherdeviceusingthe syntax:stty[options][modes]<device Fdevicereadorchangesettingsofdeviceterminalinsteadofthecurrent terminal. controlmodes(n(setterminalbaudrateton(e.g.19200)),inputmodes,output modes,etc.

umount[options] [arguments]

Unmountafilesystem.Announcestothesystemthaaremovablefilestructure previouslymountedonthespecifieddirectoryistoberemoved.Abusy filesystem(withopenfilesorwithadirectorythatissomeprocesses's currentlydirectory)cannotbeunmounted. aummountallfilesystemsspecifiedin/etc/mtab. fforcetheummount.

users[file] which[options] [files]

Displaythecurrentlyloggedinusersasaspacedseparatedlist. Listwhichfilesareexecutedifthenamedcommandsarerunasacommand. 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