Professional Documents
Culture Documents
Unix Commands
Unix Commands
Unix Commands
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.
df[[options]
diff[options]file1 file2
CompiledbyAluiziousingthebookUNIXINANUTSHELL,ArnoldRobbins,O'ReillyEd.,4thedition,2005,ISBN0596100299.
egrep[options] [regexp][files]
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
CompiledbyAluiziousingthebookUNIXINANUTSHELL,ArnoldRobbins,O'ReillyEd.,4thedition,2005,ISBN0596100299.
ps[options]
pwd rm[options]files
script[options] [file]
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]
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]
umount[options] [arguments]