Linux Commands Line
Linux Commands Line
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
searchfileswith'.rpm'extensionandmodifypermits
searchfileswith'.rpm'extensionignoringremovablepartitions ascdrom,pendrive,etc.
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)
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
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
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
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
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
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
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
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
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
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