Linux常用命令列表.docx
《Linux常用命令列表.docx》由会员分享,可在线阅读,更多相关《Linux常用命令列表.docx(24页珍藏版)》请在冰点文库上搜索。
Linux常用命令列表
LinuxShortcutsandCommands:
LinuxNewbieAdministratorGuide
byStanandPeterKlimas
Thisisapracticalselectionofthecommandsweusemostoften.Presstoseethelistingofallavailablecommand(onyourPATH).Onmysmallhomesystem,itsaysthereare2595executablesonmyPATH. Manyofthese"commands"canbeaccessedfromyourfavouriteGUIfront-end(probablyKDEorGnome)byclickingontherightmenuorbutton.Theycanallberunfromthecommandline. ProgramsthatrequireGUIhavetoberunfromaterminalopenedunderaGUI.
Legend:
<>=singlespecialorfunctionkeyonthekeyboard.Forexampleindicatesthe"control"key.
italic=nameofthefileorvariableyouprobablywanttosubstitutewithyourown.
fixedwidth=in-lineLinuxcommandsandfilenames.
NotesfortheUNIXClueless:
1.LINUXISCASE-SENSITIVE.Forexample:
Netscape,NETSCAPEandnEtscapearethreedifferentcommands.Alsomy_filE,my_file,andmy_FILEarethreedifferentfiles.Youruserloginnameandpasswordarealsocasesensitive.(ThisgoeswiththetraditionofUNIXandthe"c"programminglanguagebeingcasesensitive.)
2.Filenamescanbeupto256characterslongandcancontainletters,numbers,"."(dot),"_"(underscore),"-"(dash),plussomeothernotrecommendedcharacters.
3.Fileswithnamesstartingwith"."arenormallynotshownbythels(list)ordircommands.Thinkofthesefilesas"hidden".Usels-a (listwiththeoption"all")toseethesefiles.
4."/"isanequivalenttoDOS"\"(rootdirectory,meaningtheparentofallotherdirectories).
5.UnderLinux,alldirectoriesappearunderasingledirectorytree(therearenoDOS-styledriveletters).
6.Inaconfigurationfile,alinestartingwith#isacomment.
7.1Linuxessentialshortcutsandsanitycommands
Switchtothefirsttextterminal.UnderLinuxyoucanhaveseveral(6instandardsetup)terminalsopenedatthesametime.
(n=1..6)
Switchtothenthtextterminal.
tty
Printthenameoftheterminalinwhichyouaretypingthiscommand.
SwitchtothefirstGUIterminal(ifX-windowsisrunningonthisterminal).
(n=7..12)
SwitchtothenthGUIterminal(ifaGUIterminalisrunningonscreenn-1).Ondefault,nothingisrunningonterminals
8to12,butyoucanrunanotherserverthere.
(Inatextterminal)Autocompletethecommand ifthereisonlyoneoption,orelseshowalltheavailableoptions.
THISSHORTCUTISGREAT!
ItevenworksatLILOprompt!
Scrollandeditthecommandhistory.Presstoexecute.
Scrollterminaloutputup.Workalsoattheloginprompt,soyoucanscrollthroughyourbootupmessages.
Scrollterminaloutputdown.
<+>
(inX-windows)ChangetothenextX-serverresolution(ifyousetuptheX-servertomorethanoneresolution).FormultipleresolutionsonmystandardSVGAcard/monitor,Ihavethefollowinglineinthefile/etc/X11/XF86Config(thefirstresolutionstartsondefault,thelargestdeterminesthesizeofthe"virtualscreen"):
Modes"1024x768""800x600""640x480""512x384""480x300""400x300""1152x864"
<->
(inX-windows)ChangetothepreviousX-serverresolution.
(inX-windows)KillthecurrentX-windowsserver.UseiftheX-windowsservercrushesandcannotbeexitednormally.
Shutdownthesystemandreboot.Thisisthenormalshutdowncommandforauseratthetext-modeconsole.Don'tjustpressthe"reset"buttonforshutdown!
c
Killthecurrentprocess(mostlyinthetextmodeforsmallapplications).
d
Logoutfromthecurrentterminal. Seealsothenextcommand.
d
Send[End-of-File]tothecurrentprocess.Don'tpressittwiceelseyoualsologout(seethepreviouscommand).
s
Stopthetransfertotheterminal.
q
Resumethetransfertotheterminal.Tryifyourterminalmysteriouslystopsresponding.
z
Sendthecurrentprocesstothebackground.
exit
Logout.Icanalsouselogoutforthesameeffect. (Ifyouhavestartedasecondshell,e.g.,usingbashthesecondshellwillbeexitedandyouwillbebackinthefirstshell,notloggedout.)
reset
Restoreascrewed-upterminal(aterminalshowingfunnycharacters)todefaultsetting.Useifyoutriedto"cat"abinaryfile.Youmaynotbeabletoseethecommandasyoutypeit.
Pastethetextwhichiscurrentlyhighlightedsomewhereelse.Thisisthenormal"copy-paste"operationinLinux. (Itdoesn'tworkwithNetscapeandWordPerfectwhichusetheMSWindows-style"copy-paste".Itdoesworkinthetextterminalifyouenabled"gpm"serviceusing"setup".)BestusedwithaLinux-ready3-buttonmouse(Logitechorsimilar)orelseset"3-mousebuttonemulation").
~
(tilde)Myhomedirectory(normallythedirectory/home/my_login_name).Forexample,thecommandcd~/my_dirwillchangemyworking directorytothesubdirectory"my_dir"undermyhomedirectory. Typingjust"cd"aloneisanequivalentofthecommand"cd~".
.
(dot)Currentdirectory.Forexample,./my_programwillattempttoexecutethefile"my_program"locatedinyourcurrentworkingdirectory.
..
(twodots)Directoryparenttothecurrentone.Forexample,thecommandcd..willchangemycurrentworkingdirectoryoneonelevelup.
7.2CommonLinuxcommands--systeminfo
pwd
Printworkingdirectory,i.e.,displaythenameofmycurrentdirectoryonthescreen.
hostname
Printthenameofthelocalhost(themachineonwhichyouareworking).Usenetconf(asroot)tochangethenameofthemachine.
whoami
Printmyloginname.
idusername
Printuserid(uid)andhis/hergroupid(gid),effectiveid(ifdifferentthantherealid)andthesupplementarygroups.
date
Printorchangetheoperatingsystemdateandtime.E.g.,Icouldchangethedateandtimeto2000-12-3123:
57usingthiscommand:
date123123572000
Tosetthehardware(BIOS)clockfromthesystem(Linux)clock,usethecommand(asroot)setclock
time
Determinetheamountoftimethatittakesforaprocesstocomplete+otherinfo.Don'tconfuseitwiththedatecommand.E.g.Icanfindouthowlongittakestodisplayadirectorycontentusing:
timels
who
Determinetheusersloggedonthemachine.
rwho-a
(=remotewho)Determineallusersloggedonyournetwork.Therwhoservicemustbeenabledforthiscommandtorun.Ifitisn't,runsetupasroottoenable"rwho".
fingeruser_name
Systeminfoaboutauser.Try:
fingerroot
last
Showlistingofuserslastlogged-inonyoursystem.
history|more
Showthelast(1000orso)commandsexecutedfromthecommandlineonthecurrentaccount.The"|more"causesthedisplaytostopaftereachscreenful.
uptime
Showtheamountoftimesincethelastreboot.
ps
(=printstatus)Listtheprocessescurrentlyrunbythecurrentuser.
psaxu|more
Listalltheprocessescurrentlyrunning,eventhosewithoutthecontrollingterminal,togetherwiththenameoftheuserthatownseachprocess.
top
Keeplistingthecurrentlyrunningprocesses,sortedbycpuusage(topusersfirst).InKDE,youcangetGUI-basedKtopfrom"K"menuunder"System"-"TaskManager"(orbyexecuting"ktop"inanX-terminal).
uname-a
(=Unixnamewithoption"all")Infoonyour(local)server.Icanalsouseguname(inX-windowterminal)todisplaytheinfomorenicely.
free
Memoryinfo(inkilobytes).
df-h
(=diskfree)Printdiskinfoaboutallthefilesystems(inhuman-readableform)
du/-bh|more
(=diskusage)Printdetaileddiskusageforeachsubdirectorystartingatthe"/"(root)directory(inhumanlegibleform).
cat/proc/cpuinfo
Cpuinfo--itshowthecontentofthefilecpuinfo.Notethatthefilesinthe/procdirectoryarenotrealfiles--theyarehookstolookatinformationavailabletothekernel.
cat/proc/interrupts
Listtheinterruptsinuse.
cat/proc/version
Linuxversionandotherinfo
cat/proc/filesystems
Showthetypesoffilesystemscurrentlyinuse.
cat/etc/printcap
Showthesetupofprinters.
lsmod
(Asroot.Use/sbin/lsmodtoexecutethiscommandwhenyouareanon-rootuser.)Showthekernelmodulescurrentlyloaded.
set|more
Showthecurrentuserenvironment.
echo$PATH
Showthecontentoftheenvironmentvariable"PATH".Thiscommandcanbeusedtoshowotherenvironmentvariablesaswell.Use"set"toseethefullenvironment.
dmesg|less
Printkernelmessages(thecontentoftheso-calledkernelringbuffer).Press"q"toquit"less".Useless/var/log/dmesg toseewhat"dmesg"dumpedintothisfilerightafterthelastsystembootup.
7.3Basicoperations
any_command--help|more
Displayabriefhelponacommand(workswithmostcommands)."--help"workssimilartoDOS"/h"switch.The"more"pipeisneedediftheoutputislongerthanonescreen.
mantopic
Displaythecontentsofthesystemmanualpages(help)onthetopic.Trymanmanfirst.Press"q"toquittheviewer.Thecommandinfotopicworkssimilarandmaycontainmoreup-to-dateinformation.Manualpagescanbehardtoread.Tryany_command--helpforshort,easytodigesthelponacommand.Ifmoreinfoneeded,havealooktothedirectory/usr/doc.Todisplaymanualpagefromaspecificsection,Imayusesomethinglikeinthisexample:
man3exit(thisdisplaysaninfoonthecommandexitfromsection3ofthemanualpages).
apropostopic
Givemethelistofthecommandsthathavesomethingtotodowithmytopic.
helpcommand
Displaybriefinfoonabash(shell)build-incommand.
ls
Listthecontentofthecurrentdirectory.UnderLinux,thecommand"d