Sei sulla pagina 1di 12

LinuxCommandsLinev1.

0
cmdline|commandline|commandslinux
ThemostcompleteandupdatedlistofcommandsonlinuxbyLinuxGuide.itover350commands! COMMAND Systeminformation arch unamer dmidecodeq hdaparmi/dev/hda hdparmtT/dev/sda cat/proc/cpuinfo cat/proc/interrupts cat/proc/meminfo cat/proc/swaps cat/proc/version cat/proc/net/dev cat/proc/mounts lspcitv lsusbtv date cal2007 date041217002007.00 clockw showarchitectureofmachine showusedkernelversion showhardwaresystemcomponents(SMBIOS/DMI) displaysthecharacteristicsofaharddisk performtestreadingonaharddisk showinformationCPUinfo showinterrupts verifymemoryuse showfile(s)swap showversionofthekernel shownetworkadptersandstatistics showmountedfilesystem(s) displayPCIdevices showUSBdevices showsystemdate showthetimetableof2007 setdateandtimeMonthDayhoursMinutesYear.Secondi savechangesonBIOS DESCRIPTION

Shutdown,RestartofasystemandLogout shutdownhnow init0 shutdownrhours:minutes& shutdownc shutdownrnow reboot logout shutdownsystem plannedshutdownofthesystem cancelaplannedshutdownofthesystem reboot leavingsession

FilesandDirectory cd/home cd.. cd../.. cd cd~utente cd pwd ls lsF lsl lsa ls*[09]* lstree mkdirdir1 mkdirdir1dir2 mkdirp/tmp/dir1/dir2 rmffile1 rmdirdir1 rmrfdir1 rmrfdir1dir2 mvdir1new_dir cpfile1file2 cpdir/*. cpa/tmp/dir1. cpadir1dir2 lnsfile1lnk1 lnfile1lnk1 toucht0712250000fileditest entertodirectory'/home' gobackonelevel gobacktwolevels gotohomedirectory gotohomedirectory gotopreviousdirectory showthepathofworkdirectory viewfilesofdirectory viewfilesofdirectory showdetailsoffilesanddirectory showhiddenfiles showfilesanddirectorycontainingnumbers showfilesanddirectoriesinatreestartingfromroot createadirectorycalled'dir1' createtwodirectoriessimultaneously createadirectorytree deletefilecalled'file1' deletedirectorycalled'dir1' removeadirectorycalled'dir1'andcontentsrecursively removetwodirectoriesandtheircontentsrecursively rename/moveafileordirectory copyingafile copyallfilesofadirectorywithinthecurrentworkdirectory copyadirectorywithinthecurrentworkdirectory copyadirectory createasymboliclinktofileordirectory createaphysicallinktofileordirectory modifytimestampofafileordirectory(YYMMDDhhmm)

Filesearch find/namefile1 find/useruser1 find/home/user1name*.bin find/usr/bintypefatime+100 find/usr/bintypefmtime10 searchfileanddirectoryintorootfilesystemfrom'/' searchfilesanddirectoriesbelongingto'user1' searchfileswith'.bin'extensionwithindirectory'/ home/user1' searchbynaryfilesarenotusedinthelast100days searchfilescreatedorchangedwithin10days

find/name*.rpmexecchmod755{}; find/name*.rpmxdev locate*.ps whereishalt whichhalt

searchfileswith'.rpm'extensionandmodifypermits

searchfileswith'.rpm'extensionignoringremovablepartitions ascdrom,pendrive,etc.

findfileswiththe'.ps'extensionfirstrun'updatedb'command showlocationofabinaryfile,sourceorman showfullpathtoabinary/executable

MountingaFilesystem mount/dev/hda2/mnt/hda2 umount/dev/hda2 fuserkm/mnt/hda2 umountn/mnt/hda2 mount/dev/fd0/mnt/floppy mount/dev/cdrom/mnt/cdrom mount/dev/hdc/mnt/cdrecorder mount/dev/hdb/mnt/cdrecorder mountoloopfile.iso/mnt/cdrom mounttvfat/dev/hda5/mnt/hda5 mount/dev/sda1/mnt/usbdisk mounttsmbfsousername=user,password=pass //winclient/share/mnt/share mountdiskcalledhda2verifyexistenceofthedirectory'/ mnt/hda2' unmountdiskcalledhda2exitfrommountpoint'/mnt/hda2' first forceumountwhenthedeviceisbusy

runumountwithoutwritingthefile/etc/mtabusefulwhenthe fileisreadonlyortheharddiskisfull mountafloppydisk mountacdrom/dvdrom mountacdrw/dvdrom mountacdrw/dvdrom mountafileorisoimage mountaWindowsFAT32filesystem mountausbpendriveorflashdrive mountawindowsnetworkshare

DiskSpace dfh lslSr|more dushdir1 dush*|sortrn rpmqaqf'%10{SIZE}\t%{NAME}\n'|sortk1,1n dpkgqueryWf='${InstalledSize;10}\t${Package}\n'| sortk1,1n showlistofpartitionsmounted showsizeofthefilesanddirectoriesorderedbysize estimatespaceusedbydirectory'dir1' showsizeofthefilesanddirectoriessortedbysize showspaceusedbyrpmpackagesinstalledsortedbysize (fedora,redhatandlike) showspaceusedbydebpackagesinstalledsortedbysize (ubuntu,debianandlike)

UsersandGroups groupaddgroup_name groupdelgroup_name groupmodnnew_group_nameold_group_name createanewgroup deleteagroup renameagroup

useraddc"NomeCognome"gadmind/home/user1s createanewuserbelongs"admin"group

/bin/bashuser1 useradduser1 userdelruser1 usermodc"UserFTP"gsystemd/ftp/user1s /bin/nologinuser1 passwd passwduser1 chageE20051231user1 pwck grpck aliashh='history' createanewuser deleteauser('r'eliminateshomedirectory) changeuserattributes changepassword changeauserpassword(onlybyroot) setdeadlineforuserpassword

checkcorrectsyntaxandfileformatof'/etc/passwd'andusers existence

checkcorrectsyntaxandfileformatof'/etc/group'andgroups existence setanaliasforacommandhh=history

PermitsonFileuse"+"tosetpermissionsand""toremove lslh ls/tmp|prT5W$COLUMNS chmodugo+rwxdirectory1 chmodgorwxdirectory1 chownuser1file1 chownuser1Rdirectory1 chgrpgruppo1file1 chownuser1:gruppo1file1 find/permu+s chmodu+s/bin/file_eseguibile chmodus/bin/file_binario chmodg+s/home/public chmodgs/home/public chmodo+t/home/comune chmodot/home/comune showpermits divideterminalinto5columns setpermissionsreading(r),write(w)and(x)accesstousers owner(u)group(g)andothers(o) removepermitsreading(r),write(w)and(x)accesstousers group(g)andothers(or changeownerofafile changeuserownerofadirectoryandallthefilesand directoriescontainedinside changegroupoffiles changeuserandgroupownershipofafile viewallfilesonthesystemwithSUIDconfigured setSUIDbitonabinaryfiletheuserthatrunningthatfile getssameprivilegesasowner disableSUIDbitonabinaryfile setSGIDbitonadirectorysimilartoSUIDbutfordirectory disableSGIDbitonadirectory setSTIKYbitonadirectoryallowsfilesdeletiononlyto legitimateowners disableSTIKYbitonadirectory

SpecialAttributesonfileuse"+"tosetpermissionsand""toremove chattr+afile1 allowswriteopeningofafileonlyappendmode

chattr+cfile1 chattr+dfile1 chattr+ifile1 chattr+sfile1 chattr+Sfile1 chattr+ufile1 lsattr

allowsthatafileiscompressed/decompressedautomatically bythekernel makessurethattheprogramignoresDumpthefilesduring backup

makesitanimmutablefile,whichcannotberemoved,altered renamedorlinked allowsafiletobedeletedsafely makessurethatifafileismodifiedchangesarewrittenin synchronousmodeaswithsync

allowsyoutorecoverthecontentsofafileevenifitiscanceled showspecialsattributes

Archivesandcompressedfiles bunzip2file1.bz2 bzip2file1 gunzipfile1.gz gzipfile1 gzip9file1 rarafile1.rartest_file rarafile1.rarfile1file2dir1 rarxfile1.rar unrarxfile1.rar tarcvfarchive.tarfile1 tarcvfarchive.tarfile1file2dir1 tartfarchive.tar tarxvfarchive.tar tarxvfarchive.tarC/tmp tarcvfjarchive.tar.bz2dir1 tarxvfjarchive.tar.bz2 tarcvfzarchive.tar.gzdir1 tarxvfzarchive.tar.gz zipfile1.zipfile1 ziprfile1.zipfile1file2dir1 unzipfile1.zip decompressafilecalled'file1.bz2' compressafilecalled'file1' decompressafilecalled'file1.gz' compressafilecalled'file1' compresswithmaximumcompression createanarchiverarcalled'file1.rar' compress'file1','file2'and'dir1'simultaneously decompressrararchive decompressrararchive createauncompressedtarball createanarchivecontaining'file1','file2'and'dir1' showcontentsofanarchive extractatarball extractatarballinto/tmp createatarballcompressedintobzip2 decompressacompressedtararchiveinbzip2 createatarballcompressedintogzip decompressacompressedtararchiveingzip createanarchivecompressedinzip compressinzipseveralfilesanddirectoriessimultaneously decompressaziparchive

RPMPackagesFedora,RedHatandlike rpmivhpackage.rpm rpmivhnodeepspackage.rpm rpmUpackage.rpm installarpmpackage installarpmpackageignoringdependenciesrequests upgradearpmpackagewithoutchangingconfigurationfiles

rpmFpackage.rpm rpmepackage_name.rpm rpmqa rpmqa|grephttpd rpmqipackage_name rpmqg"SystemEnvironment/Daemons" rpmqlpackage_name rpmqcpackage_name rpmqpackage_namewhatrequires rpmqpackage_namewhatprovides rpmqpackage_namescripts rpmqpackage_namechangelog rpmqf/etc/httpd/conf/httpd.conf rpmqppackage.rpml rpmimport/media/cdrom/RPMGPGKEY rpmchecksigpackage.rpm rpmqagpgpubkey rpmVpackage_name rpmVa rpmVppackage.rpm

upgradearpmpackageonlyifitisalreadyinstalled removearpmpackage showallrpmpackagesinstalledonthesystem showallrpmpackageswiththename"httpd" obtaininformationonaspecificpackageinstalled showrpmpackagesofagroupsoftware showlistoffilesprovidedbyarpmpackageinstalled showlistofconfigurationfilesprovidedbyarpmpackage installed showlistofdependenciesrequiredforarpmpacket showcapabilityprovidedbyarpmpackage showscriptsstartedduringinstallation/removal showhistoryofrevisionsofarpmpackage verifywhichrpmpackagebelongstoagivenfile showlistoffilesprovidedbyarpmpackagenotyetinstalled importpublickeydigitalsignature verifytheintegrityofarpmpackage verifyintegrityofallrpmpackagesinstalled checkfilesize,permissions,type,owner,group,MD5 checksumandlastmodification checkallrpmpackagesinstalledonthesystemusewith caution verifyarpmpackagenotyetinstalled

rpm2cpiopackage.rpm|cpioextractmakedirectories extractexecutablefilefromarpmpackage *bin* rpmivh/usr/src/redhat/RPMS/`arch`/package.rpm rpmbuildrebuildpackage_name.src.rpm installapackagebuiltfromarpmsource buildarpmpackagefromarpmsource

YUMpackagesupdaterFedora,RedHatandlike yuminstallpackage_name yumupdate yumupdatepackage_name yumremovepackage_name yumlist yumsearchpackage_name yumcleanpackages yumcleanheaders yumcleanall downloadandinstallarpmpackage updateallrpmpackagesinstalledonthesystem upgradearpmpackage removearpmpackage listallpackagesinstalledonthesystem findapackageonrpmrepository cleanuprpmcacheerasingdownloadedpackages removeallfilesheadersthatthesystemusestoresolve dependency removefromthecachepackagesandheadersfiles

DEBpackagesDebian,Ubuntuandlike dpkgipackage.deb dpkgrpackage_name dpkgl dpkgl|grephttpd dpkgspackage_name dpkgLpackage_name dpkgcontentspackage.deb dpkgS/bin/ping install/upgradeadebpackage removeadebpackagefromthesystem showalldebpackagesinstalledonthesystem showallrpmpackageswiththename"httpd" obtaininformationonaspecificpackageinstalledonsystem showlistoffilesprovidedbyapackageinstalledonsystem showlistoffilesprovidedbyapackagenotyetinstalled verifywhichpackagebelongstoagivenfile

APTpackagesupdaterDebian,Ubuntuelike aptgetinstallpackage_name aptcdrominstallpackage_name aptgetupdate aptgetremovepackage_name aptgetcheck aptgetclean install/upgradeadebpackage install/upgradeadebpackagefromcdrom updatealldebpackagesinstalledonsystem removeadebpackagefromsystem verifycorrectresolutionofdependencies cleanupcachefrompackagesdownloaded

Viewfilecontent catfile1 tacfile1 morefile1 lessfile1 head2file1 tail2file1 tailf/var/log/messages viewthecontentsofafilestartingfromthefirstrow viewthecontentsofafilestartingfromthelastline viewcontentofafilealong similarto'more'commandbutwhichallowsbackward movementinthefileaswellasforwardmovement viewfirsttwolinesofafile viewlasttwolinesofafile viewinrealtimewhatisaddedtoafile

TextManipulation catfile_test|[operation:sed,grep,awk,grep,etc]> result.txt syntaxtoelaboratethetextofafile,andwriteresulttoanew file

catfile_originale|[operazione:sed,grep,awk,grep,etc] syntaxtoelaboratethetextofafileandappendresultin >>result.txt existingfile grepAug/var/log/messages grep^Aug/var/log/messages grep[09]/var/log/messages grepAugR/var/log/* lookupwords"Aug"onfile'/var/log/messages'

lookupwordsthatbeginwith"Aug"onfile'/var/log/messages' selectfromfile'/var/log/messages'alllinesthatcontain numbers searchstring"Aug"atdirectory'/var/log'andbelow

grepAug/var/log/messages sed's/stringa1/stringa2/g'example.txt sed'/^$/d'example.txt sed'/*#/d;/^*$/d'example.txt echo'esempio'|tr'[:lower:]''[:upper:]' sede'1d'result.txt sedn'/stringa1/p' sede's/*$//'example.txt sede's/stringa1//g'example.txt sedn'1,5p;5q'example.txt sedn'5p;5q'example.txt sede's/00*/0/g'example.txt catnfile1 catexample.txt|awk'NR%2==1' echoabc|awk'{print$1}' echoabc|awk'{print$1,$3}' pastefile1file2 pasted'+'file1file2 sortfile1file2 sortfile1file2|uniq sortfile1file2|uniqu sortfile1file2|uniqd comm1file1file2 comm2file1file2 comm3file1file2

writeresultofasearchwithinafile replace"string1"with"string2"inexample.txt removeallblanklinesfromexample.txt removecommentsandblanklinesfromexample.txt convertfromlowercaseinuppercase eliminatesthefirstlinefromfileexample.txt viewonlylinesthatcontaintheword"string1" removeemptycharactersattheendofeachrow removeonlytheword"string1"fromtextandleaveintactall viewfrom1thto5throw viewrownumber5 replacemorezeroswithasinglezero numberrowofafile removeallevenlinesfromexample.txt viewthefirstcolumnofaline viewthefirstandthirdcolumnofaline mergingcontentsoftwofilesforcolumns mergingcontentsoftwofilesforcolumnswith'+'delimiteron thecenter sortcontentsoftwofiles sortcontentsoftwofilesomittinglinesrepeated sortcontentsoftwofilesbyviewingonlyuniqueline sortcontentsoftwofilesbyviewingonlyduplicateline comparecontentsoftwofilesbydeletingonlyuniquelines from'file1' comparecontentsoftwofilesbydeletingonlyuniquelines from'file2' comparecontentsoftwofilesbydeletingonlythelinesthat appearonbothfiles

CharactersetandFormatfileconversion dos2unixfiledos.txtfileunix.txt unix2dosfileunix.txtfiledos.txt recode..HTML<page.txt>page.html recodel|more convertatextfileformatfromMSDOStoUNIX convertatextfileformatfromUNIXtoMSDOS convertatextfiletohtml showallavailableformatsconversion

FilesystemAnalisys badblocksv/dev/hda1 fsck/dev/hda1 checkbadblocksindiskhda1 repair/checkintegrityoflinuxfilesystemondiskhda1

fsck.ext2/dev/hda1 e2fsck/dev/hda1 e2fsckj/dev/hda1 fsck.ext3/dev/hda1 fsck.vfat/dev/hda1 fsck.msdos/dev/hda1 dosfsck/dev/hda1

repair/checkintegrityofext2filesystemondiskhda1 repair/checkintegrityofext2filesystemondiskhda1 repair/checkintegrityofext3filesystemondiskhda1 repair/checkintegrityofext3filesystemondiskhda1 repair/checkintegrityoffatfilesystemondiskhda1 repair/checkintegrityofdosfilesystemondiskhda1 repair/checkintegrityofdosfilesystemsondiskhda1

FormataFilesystem mkfs/dev/hda1 mke2fs/dev/hda1 mke2fsj/dev/hda1 mkfstvfat32F/dev/hda1 fdformatn/dev/fd0 mkswap/dev/hda3 createafilesystemtypelinuxonhda1partition createafilesystemtypelinuxext2onhda1partition createafilesystemtypelinuxext3(journal)onhda1partition createaFAT32filesystem formatafloppydisk createaswapfilesystem

SWAPfilesystem mkswap/dev/hda3 swapon/dev/hda3 swapon/dev/hda2/dev/hdb3 createaswapfilesystem activatinganewswappartition activatetwoswappartitions

Backup dump0ajf/tmp/home0.bak/home dump1ajf/tmp/home0.bak/home restoreif/tmp/home0.bak rsyncrogpavdelete/home/tmp rsyncrogpavesshdelete/homeip_address:/tmp rsyncazesshdeleteip_addr:/home/public /home/local rsyncazesshdelete/home/local ip_addr:/home/public ddbs=1Mif=/dev/hda|gzip|sshuser@ip_addr'dd of=hda.gz' tarPufbackup.tar/home/user (cd/tmp/local/&&tarc.)|sshCuser@ip_addr'cd /home/share/&&tarxp' (tarc/home)|sshCuser@ip_addr'cd/home/backup home&&tarxp' makeafullbackupofdirectory'/home' makeaincrementalbackupofdirectory'/home' restoringabackupinteractively synchronizationbetweendirectories rsyncviaSSHtunnel synchronizealocaldirectorywitharemotedirectoryviassh andcompression synchronizearemotedirectorywithalocaldirectoryviassh andcompression makeabackupofalocalharddiskonremotehostviassh makeaincrementalbackupofdirectory'/home/user' copycontentofadirectoryonremotedirectoryviassh copyalocaldirectoryonremotedirectoryviassh

tarcf.|(cd/tmp/backup;tarxf) find/home/user1name'*.txt'|xargscpavtarget directory=/home/backup/parents find/var/logname'*.log'|tarcvfilesfrom=|bzip2> log.tar.bz2 ddif=/dev/hdaof=/dev/fd0bs=512count=1 ddif=/dev/fd0of=/dev/hdabs=512count=1

localcopypreservingpermitsandlinksfromadirectoryto another findandcopyallfileswith'.txt'extentionfromadirectoryto another findallfileswith'.log'extentionandmakeanbziparchive makeacopyofMBR(MasterBootRecord)tofloppy restoreMBRfrombackupcopysavedtofloppy

CDROM cdrecordvgracetime=2dev=/dev/cdromeject blank=fastforce mkisofs/dev/cdrom>cd.iso mkisofs/dev/cdrom|gzip>cd_iso.gz cleanarewritablecdrom createanisoimageofcdromondisk createacompressedisoimageofcdromondisk

mkisofsJallowleadingdotsRV"LabelCD"isolevel createanisoimageofadirectory 4o./cd.isodata_cd cdrecordvdev=/dev/cdromcd.iso gzipdccd_iso.gz|cdrecorddev=/dev/cdrom mountoloopcd.iso/mnt/iso cdparanoiaB cdparanoia"3" cdrecordscanbus burnanISOimage burnacompressedISOimage mountanISOimage ripaudiotracksfromaCDtowavfiles ripfirstthreeaudiotracksfromaCDtowavfiles scanbustoidentifythechannelscsi

NetworkingLANandWiFi ifconfigeth0 ifupeth0 ifdowneth0 ifconfigeth0192.168.1.1netmask255.255.255.0 ifconfigeth0promisc dhclienteth0 routen routeaddnet0/0gwIP_Gateway routeaddnet192.168.0.0netmask255.255.0.0gw 192.168.1.1 routedel0/0gwIP_gateway echo"1">/proc/sys/net/ipv4/ip_forward hostname hostwww.linuxguide.it iplinkshow showconfigurationofanethernetnetworkcard activateaninterface'eth0' disableaninterface'eth0' configureIPAddress configure'eth0'inpromiscuousmodetogatherpackets (sniffing) activeinterface'eth0'indhcpmode showroutingtable configuradefaultgateway configurestaticroutetoreachnetwork'192.168.0.0/16' removestaticroute activateiprouting showhostname

lookuphostnametoresolvenametoipaddressandviceversa showlinkstatusofallinterfaces

miitooleth0 ethtooleth0 netstattup netstattupl tcpdumptcpport80 iwlistscan iwconfigeth1

showlinkstatusof'eth0' showstatisticsofnetworkcard'eth0' showallactivenetworkconnectionsandtheirPID showallnetworkserviceslisteningonthesystemandtheir PID showallHTTPtraffic showwirelessnetworks showconfigurationofawirelessnetworkcard

MicrosoftWindowsnetworksSAMBA nbtscanip_addr nmblookupAip_addr smbclientLip_addr/hostname smbgetRrsmb://ip_addr/share mounttsmbfsousername=user,password=pass //winclient/share/mnt/share netbiosnameresolution netbiosnameresolution showremotesharesofawindowshost likewgetcandownloadfilesfromahostwindowsviasmb mountawindowsnetworkshare

IPTABLESfirewall iptablestfilterL iptablestnatL iptablestfilterF iptablestnatF iptablestfilterX iptablestfilterAINPUTptcpdporttelnetjACCEPT iptablestfilterAOUTPUTptcpdporthttpjDROP iptablestfilterAFORWARDptcpdportpop3j ACCEPT iptablestfilterAINPUTjLOGlogprefix"DROP INPUT" iptablestnatAPOSTROUTINGoeth0j MASQUERADE iptablestnatAPREROUTINGd192.168.0.1ptcpm tcpdport22jDNATtodestination10.0.0.2:22 showallchainsoffilteringtable showallchainsofnattable clearallrulesfromfilteringtable clearallrulesfromtablenat deleteanychainscreatedbyuser allowtelnetconnectionstoinput blockHTTPconnectionstooutput allowPOP3connectionstoforwardchain loggingsullachaindiinputLoggingonchaininput configureaPAT(PortAddressTraslation)oneth0masking outboundpackets redirectpacketsaddressedtoahosttoanotherhost

Monitoringanddebugging top pseafw pseopid,argsforest pstree displaylinuxtasksusingmostcpu displayslinuxtasks displayslinuxtasksinahierarchicalmode mostraunalberodeiprocessisistemaShowsatreesystem processes

kill9ID_Processo kill1ID_Processo lsofp$$ lsof/home/user1 stracecls>/dev/null stracefeopenls>/dev/null watchn1'cat/proc/interrupts' lastreboot lsmod freem smartctlA/dev/hda smartctli/dev/hda tail/var/log/dmesg tail/var/log/messages

forceclosureoftheprocessandfinishit forceaprocesstoreloadconfiguration displayalistoffilesopenedbyprocesses displaysalistofopenfilesinagivenpathsystem displaysystemcallsmadeandreceivedbyaprocess displaylibrarycalls displayinterruptsinrealtime showhistoryreboot displaykernelloaded displaysstatusofRAMinmegabytes monitoringreliabilityofaharddiskthroughSMART checkifSMARTisactiveonaharddisk showeventsinherenttotheprocessofbootingkernel showsystemevents

Otherusefulcommands mkbootdiskdevice/dev/fd0`unamer` gpgcfile1 gpgfile1.gpg wgetrwww.example.com wgetcwww.example.com/file.iso echo'wgetcwww.example.com/files.iso'|at09:00 lddssh createabootfloppy encryptafilewithGNUPrivacyGuard decryptafilewithGNUPrivacyGuard downloadanentirewebsite downloadafilewiththeabilitytostopthedownloadand resumelater startadownloadatanygiventime showsharedlibrariesrequiredbysshprogram

Potrebbero piacerti anche