Sei sulla pagina 1di 6

USEFULUNIXCOMMANDS

cancel cancelprintrequestedwithlp
catfile Displaythefile
catfile1file2>files Combinefile1andfile2intofiles
catfile1>>file2 Appendfile1attheendoffile2
chgrp[options]
newgroupfiles
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 cleartheterminaldisplay
cmpfile1file2 Comparetwofiles(0identical)(1different)(2inaccessible)
comm[options]
Comparefile1andfile2.Outputsthreecolumns:linesuniquetofile1,lines
1
CompiledbyAluiziousingthebookUNIXINANUTSHELL,ArnoldRobbins,O'ReillyEd.
,4th
edition,2005,ISBN0596100299.
file1file2 uniquetofile2andlinescommontobothfile.
1suppressprintingcolumn1
13suppressprintingcolumns1and3
cp[options]file1
file2
cp[options]files
directory
Makeacopyoffile1withthenamefile2
Copythefilesintodirectorywithsamenamefiles.
fforce(removeexistingfilesinthedestination)
iinteractively(prompforconfirmation)
ppreservetheoriginalfilespermissionsandownershipinthenewfile.
r,Rrecursively(copydirectoriesrecursively)
LusedwithR.ifsymboliclinkpointstoadirectory,recursivelytraverse
thedirectory.
LusedwithR.
smakesymboliclinkinsteadofcopying.
df[[options]
Reportthenumberoffreediskblocksandinodesonallmountedfilesystems.
hhumanreadable
kkilobytes
mmegabytes
diff[options]file1
file2
Reportsthedifferencesbetweenfile1andfile2.Printsfile1textflagged(<)and
file2(>).
bignoreblankspaces.
eproduceascriptofcommandstorecreatefile2fromfile1,usingededitor.
Dmergefile1andfile2intoasinglefilecontainingconditionalC
preprocessors(#ifdef).Definingsymbolandthencompilingyeldsfile2.
Notdefiningsymbol,yieldsfile1.
du[options] Printdiskusage.Optionslikedfcommand.
echo[options]
[string]
Echoargumentstostandardsoutputs.Oftenusedforproducingprompsfrom
shellscripts.
\aalert
\nnewline
\rcarriagereturn
\ttab
2
CompiledbyAluiziousingthebookUNIXINANUTSHELL,ArnoldRobbins,O'ReillyEd.
,4th
edition,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]
pathnamecondition
Findandlocateallthefilesinsidethepathnamespecifiedthatmatchessome
condition(name.type,size,user).
Examples:
find/homenamechapter1
find/home/usrname'memo*'userann
find/mtime2(findfilesmodifiedwithinthelasttwodays)
find/size10k(findfileswith10kB)
gcc GNUCcompiler.
ccreateslinkableobjectfile(.o)foreachsourcefilebutdonotcalltheli
nker.
ofilespecifyoutputfileasfile.Defaultisa.out
Wallenablealmostallpossiblewarnings.
lmwhenusingthemath.hfunction.
gftp
Tranferfilestoandfromaremotenetworksitehostname.Belowispresentedan
exampleofgftpscreenandloginconfigurationnecessarytoaccessOMG
computers/homes/usernamedirectory.
gunzip[gzip
options][files]
Restorethefile.gz.
3
CompiledbyAluiziousingthebookUNIXINANUTSHELL,ArnoldRobbins,O'ReillyEd.
,4th
edition,2005,ISBN0596100299.
gzip[options][files] Reducethesizeofoneormorefilesandmovetofile.gz.
fforce
qquite(suppresswarnings)
rrecursivelywalkthecurrentdirectorytreeandcompressallfilesfound.
vdisplaythenameandpercantageofreduction.
head[options]
[files]
Printthefirstfewlinesoffiles(defaultis10lines).
n50printthefirst50lines.
hostname[option] Printnameofcurrenthostsystem.
idisplaytheiIPaddressofthehost.
id[options]
[username]
displayinformationaboutyourselforanotheruser:usedID,groupID,etc.
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]
[targets]
Updateoneormoretargetsaccordingtodependencyinstructionsina
descriptionfile(makefile)inthecurrentdirectoty.
mansubject Displayinformationaboutasubject(nameofacommand).
mkdir[options]
Createoneormoredirectories.Youmusthavewritepermissionintheparent
4
CompiledbyAluiziousingthebookUNIXINANUTSHELL,ArnoldRobbins,O'ReillyEd.
,4th
edition,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 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.
uDonotremoveafileorlinkifitsmodificationdateisthesameasornew
er
thanthatofitsreplacement.
passwd[options]
[user]
createorchangeapasswordassociatedwithausername.Onlytheownerora
privilegedusermaychangeapassword.
5
CompiledbyAluiziousingthebookUNIXINANUTSHELL,ArnoldRobbins,O'ReillyEd.
,4th
edition,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]
[file]
Createarecordofyourloginsession,storinginfileeverythingthatdisplayson
thescreen.
aappendthescriptrecordtofile.
sed[options][files]
Streameditor.Editoneormorefileswithoutuserinteraction.
eapplytheinstructionstothefiles.
fapplythesetofinstructionsfromtheeditingscript.
sortfile Sortthelinesoffileinalphabeticalorder.
ssh[options]
hostname
[command]
Securalylogauserintoaremotesystemandruncommandsonthatsystem.
HOSTANME: user@hostname(ex.aluizio@peel.omg.unb.ca).
XenableX11forwarding.
6
CompiledbyAluiziousingthebookUNIXINANUTSHELL,ArnoldRobbins,O'ReillyEd.
,4th
edition,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).
Loginasuser.Ifnouserspecified,becomesuperuser.EnterEOFtoterminate.
changetheuser(eg.suuser)
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,sh
ow
thecommandworkungandwritethetapein/dev/rmt/0).
tartvf/dev/rmt/0(listthearchivescontentinaformatlikelsl).
tarxvf/dev/rmt/0/bin(Extractthe/bindirectory)
tty[options] Printthedevicenameofyourterminal.
7
CompiledbyAluiziousingthebookUNIXINANUTSHELL,ArnoldRobbins,O'ReillyEd.
,4th
edition,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] Displaythecurrentlyloggedinusersasaspacedseparatedlist.
which[options]
[files]
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.

Potrebbero piacerti anche