Aftermyarticleaboutcommandlineone-liners,manypeoplewanttocontributewiththeirowncommands.Thisistheplacetodoit,pullrequestsarewelcome!
TableofContentsHistoryDirectoriesFilesSearchingNetworkingUserenvironmentFilesystemDate&TimeProcessesMiscellaneousHistoryRunthelastcommand
$!!Runthelastcommandasroot
$sudo!!Createascriptofthelastexecutedcommand
$echo"!!">script.shReuseallparameterofthepreviouscommandline
$echocd.$!*Runthelastcommandwithsomeargument
$echoabcde$echo!!:2$echo!!:3-$Insertthelastargumentofthepreviouscommand
$cpscript.sh/usr/bin/$cd!$$cd<ESC>.$cd<ALT>.Runspreviouscommandbutreplacing
$echonotypos$^typos^errorsEscapeanycommandaliases
$aliasls="ls-a"$\lsRunacommandfromthehistory
$history...1225ls-l1226gitstatus1227history$!-3$!1225Searchthehistoryforthemostrecentcommandbeginningwithtext
$!textSearchthehistoryforthemostrecentcommandcontainingtext
$<ctrl-r>textListofcommandsyouusemostoften
$history|awk'{print$2}'|sort|uniq-c|sort-rn|headExecuteacommandwithoutsavingitinthehistory
$<space>commandDirectoriesMakeadirectorycreatingintermediatedirectories
$mkdir-pa/long/directory/pathCreateadirectoryandchangeintoit
$mkdirdir&&cd$_Changetothepreviousworkingdirectory
$cd-Jumptoadirectory.Executeacommandinasubshell.Jumpbacktocurrentdirectory
$(cd/tmp&&ls)FilesQuicklyrenameafile
$mvfilename.{old,new}$mvfilename.{png,jpg}Createaquickback-upcopyofafile
$cpfile.txt{,.bak}Createasimpletextfilefromcommandline
$cat>file.txt{yourtexthere}{yourtexthere}<ctrl-d>Createasimpletextfilefromcommandlineorscript(EOFisjustatoken,canbeanyword)
$cat>file.txt<<EOF{yourtexthere}{yourtexthere}EOFEmptyafilefromcommandline(usefulltotruncatelogfilefromrunningprocesses)
$>file.txtEmptyafilefromcommandlineorscript
$cat/dev/null>file.txtMakelessbehaveliketail-f
$less+FsomelogfileDisplaylinenumbersinafile
$cat-nfile$less-NfileRedirectstandardinputtoafile.Printittostandardoutput
$command|teefile.txt|less┌─────────┐┌─────────┐┌─────────┐│command│─▸│tee│─▸│stdout│└─────────┘└────┬────┘└─────────┘│▾┌───────────┐│file│└───────────┘SearchingSearchforastringinsideallfilesinthecurrentdirectory
$grep-RnsI--color=auto<pattern>*Beyondgrep
_/|\'o.O'=(___)=Uack!$ack<pattern>Recursivelyremoveallemptydirectories
$find.-typed-empty-deleteNetworkingServecurrentdirectorytreeathttps://$HOSTNAME:8000/
$python-mSimpleHTTPServer$ruby-run-ehttpd.-p8000Shareafilebetweentwocomputers
receiver$nc-l5566>data-dump.sqlsender$nc<receiver-ip-address>5566<data-dump.sqlShareaBIGfilebetweentwocomputersandshowprogressbar
receiver$nc-l5566>big-file.isosender$pvbig-file.iso|nc<receiver-ip-address>5566Transferafolderbetweentwocomputers
receiver$nc-l5566|tar-zxvsender$tar-zcv<folder>|nc-w1<receiver-ip-address>5566Downloadanentirewebsite
$wget-m-khttps://website.comUserenvironmentShowPATHinahuman-readableway
$echo$PATH|tr':''\n'$tr':''\n'<<<$PATHCleartheterminalscreen
$<ctrl-l>$clearSalvageaborkedterminal
$resetCloseshellkeepingallsubprocessrunning
$disown-a&&exitRunacommandimmunetohangups
$nohupcommand&NetworkingAttachscreenoverssh
$sshuser@host-tscreen-rComparearemotefilewithalocalfile
$sshuser@hostcat/path/to/remotefile|diff/path/to/localfile-GetyourpublicIPaddress
$curlifconfig.meSetaudiblealarmwhenanIPaddresscomesonline
$ping-aIP_addressListprogramswithopenportsandconnections
$lsof-iCheckwhichprocessislisteningonaspecificport
$netstat-nlp|grep8080$netstat-nlptcp|grep8080(BSD)FilesystemCurrentlymountedfilesystemsinnicelayout
$mount|column-tDisplayfreediskspace
$df-hDisplaydiskusagestatisticsforthecurrentdirectory
$du-sh*Display10biggestfiles/foldersforthecurrentdirectory
$du-s*|sort-nr|headCreateaziparchiveofadirectory
$zip-rarchive.zipdirectoryExtractcompressedarchive
$unziparchive.zipShowFileSystemHierarchy
$manhierDate&TimeShutdownthesystematagiventime
$shutdown-hnow$shutdown-h22:49Executeacommandatagiventime
$echo"ls-l"|atmidnightSimplestopwatch
$timeread<ctrl-d>Putaconsoleclockintoprightcorner
$whilesleep1;dotputsc;tputcup0$(($(tputcols)-29));date;tputrc;done&Displaysacalendar
$cal121984Whatdaywasyesterdayorwillitbetomorrow,etc...
$date-dyesterday$date-dtomorrow+%Y-%m-%d$date-d"7daysago"+%Y-%m-%d$date-j-v-1d(BSD)ProcessesDisplaythetoptenrunningprocesses.(Sortedbymemoryusage)
$psaux|sort-nk+4|tailKillallRubyprocesses
$psaux|grepruby|awk'{print$2}'|xargskill-9$psaux|awk'/ruby/&&!/awk/{system("kill-9"$2)}'$pkill-fruby$killall-9rubyCheckwhichprocessismodifyingacertaindirectoryorfile
$auditctl-w/path/to/directory-pwarSeeresults
$ausearch-f/path/to/directoryMiscellaneous32bitsor64bits?
$getconfLONG_BITQuickaccesstotheasciitable
$manasciiCountyourcommits
$gitshortlog-snRussianRouletteinBash(rememberkidsdon'ttrythisathome)
$[$[$RANDOM%6]==0]&&rm-rf/||echo"Youlive"WatchStarWarsviatelnet
$telnettowel.blinkenlights.nlWhomadethis?ThiswasmadebyArturoHerreroundertheMITLicense.FindmeonTwitter@ArturoHerrero.
评论