command-line-one-liners Command line one-liners.开源项目

我要开发同款
匿名用户2021年11月09日
40阅读
开发技术SHELL
所属分类终端/远程登录、应用工具
授权协议Readme

作品详情

Commandlineone-liners

Aftermyarticleaboutcommandlineone-liners,manypeoplewanttocontributewiththeirowncommands.Thisistheplacetodoit,pullrequestsarewelcome!

TableofContentsHistoryDirectoriesFilesSearchingNetworkingUserenvironmentFilesystemDate&TimeProcessesMiscellaneousHistory

Runthelastcommand

$!!

Runthelastcommandasroot

$sudo!!

Createascriptofthelastexecutedcommand

$echo"!!">script.sh

Reuseallparameterofthepreviouscommandline

$echocd.$!*

Runthelastcommandwithsomeargument

$echoabcde$echo!!:2$echo!!:3-$

Insertthelastargumentofthepreviouscommand

$cpscript.sh/usr/bin/$cd!$$cd<ESC>.$cd<ALT>.

Runspreviouscommandbutreplacing

$echonotypos$^typos^errors

Escapeanycommandaliases

$aliasls="ls-a"$\ls

Runacommandfromthehistory

$history...1225ls-l1226gitstatus1227history$!-3$!1225

Searchthehistoryforthemostrecentcommandbeginningwithtext

$!text

Searchthehistoryforthemostrecentcommandcontainingtext

$<ctrl-r>text

Listofcommandsyouusemostoften

$history|awk'{print$2}'|sort|uniq-c|sort-rn|head

Executeacommandwithoutsavingitinthehistory

$<space>commandDirectories

Makeadirectorycreatingintermediatedirectories

$mkdir-pa/long/directory/path

Createadirectoryandchangeintoit

$mkdirdir&&cd$_

Changetothepreviousworkingdirectory

$cd-

Jumptoadirectory.Executeacommandinasubshell.Jumpbacktocurrentdirectory

$(cd/tmp&&ls)Files

Quicklyrenameafile

$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}EOF

Emptyafilefromcommandline(usefulltotruncatelogfilefromrunningprocesses)

$>file.txt

Emptyafilefromcommandlineorscript

$cat/dev/null>file.txt

Makelessbehaveliketail-f

$less+Fsomelogfile

Displaylinenumbersinafile

$cat-nfile$less-Nfile

Redirectstandardinputtoafile.Printittostandardoutput

$command|teefile.txt|less┌─────────┐┌─────────┐┌─────────┐│command│─▸│tee│─▸│stdout│└─────────┘└────┬────┘└─────────┘│▾┌───────────┐│file│└───────────┘Searching

Searchforastringinsideallfilesinthecurrentdirectory

$grep-RnsI--color=auto<pattern>*

Beyondgrep

_/|\'o.O'=(___)=Uack!$ack<pattern>

Recursivelyremoveallemptydirectories

$find.-typed-empty-deleteNetworking

Servecurrentdirectorytreeathttps://$HOSTNAME:8000/

$python-mSimpleHTTPServer$ruby-run-ehttpd.-p8000

Shareafilebetweentwocomputers

receiver$nc-l5566>data-dump.sqlsender$nc<receiver-ip-address>5566<data-dump.sql

ShareaBIGfilebetweentwocomputersandshowprogressbar

receiver$nc-l5566>big-file.isosender$pvbig-file.iso|nc<receiver-ip-address>5566

Transferafolderbetweentwocomputers

receiver$nc-l5566|tar-zxvsender$tar-zcv<folder>|nc-w1<receiver-ip-address>5566

Downloadanentirewebsite

$wget-m-khttps://website.comUserenvironment

ShowPATHinahuman-readableway

$echo$PATH|tr':''\n'$tr':''\n'<<<$PATH

Cleartheterminalscreen

$<ctrl-l>$clear

Salvageaborkedterminal

$reset

Closeshellkeepingallsubprocessrunning

$disown-a&&exit

Runacommandimmunetohangups

$nohupcommand&Networking

Attachscreenoverssh

$sshuser@host-tscreen-r

Comparearemotefilewithalocalfile

$sshuser@hostcat/path/to/remotefile|diff/path/to/localfile-

GetyourpublicIPaddress

$curlifconfig.me

SetaudiblealarmwhenanIPaddresscomesonline

$ping-aIP_address

Listprogramswithopenportsandconnections

$lsof-i

Checkwhichprocessislisteningonaspecificport

$netstat-nlp|grep8080$netstat-nlptcp|grep8080(BSD)Filesystem

Currentlymountedfilesystemsinnicelayout

$mount|column-t

Displayfreediskspace

$df-h

Displaydiskusagestatisticsforthecurrentdirectory

$du-sh*

Display10biggestfiles/foldersforthecurrentdirectory

$du-s*|sort-nr|head

Createaziparchiveofadirectory

$zip-rarchive.zipdirectory

Extractcompressedarchive

$unziparchive.zip

ShowFileSystemHierarchy

$manhierDate&Time

Shutdownthesystematagiventime

$shutdown-hnow$shutdown-h22:49

Executeacommandatagiventime

$echo"ls-l"|atmidnight

Simplestopwatch

$timeread<ctrl-d>

Putaconsoleclockintoprightcorner

$whilesleep1;dotputsc;tputcup0$(($(tputcols)-29));date;tputrc;done&

Displaysacalendar

$cal121984

Whatdaywasyesterdayorwillitbetomorrow,etc...

$date-dyesterday$date-dtomorrow+%Y-%m-%d$date-d"7daysago"+%Y-%m-%d$date-j-v-1d(BSD)Processes

Displaythetoptenrunningprocesses.(Sortedbymemoryusage)

$psaux|sort-nk+4|tail

KillallRubyprocesses

$psaux|grepruby|awk'{print$2}'|xargskill-9$psaux|awk'/ruby/&&!/awk/{system("kill-9"$2)}'$pkill-fruby$killall-9ruby

Checkwhichprocessismodifyingacertaindirectoryorfile

$auditctl-w/path/to/directory-pwar

Seeresults

$ausearch-f/path/to/directoryMiscellaneous

32bitsor64bits?

$getconfLONG_BIT

Quickaccesstotheasciitable

$manascii

Countyourcommits

$gitshortlog-sn

RussianRouletteinBash(rememberkidsdon'ttrythisathome)

$[$[$RANDOM%6]==0]&&rm-rf/||echo"Youlive"

WatchStarWarsviatelnet

$telnettowel.blinkenlights.nlWhomadethis?

ThiswasmadebyArturoHerreroundertheMITLicense.FindmeonTwitter@ArturoHerrero.

声明:本文仅代表作者观点,不代表本站立场。如果侵犯到您的合法权益,请联系我们删除侵权资源!如果遇到资源链接失效,请您通过评论或工单的方式通知管理员。未经允许,不得转载,本站所有资源文章禁止商业使用运营!
下载安装【程序员客栈】APP
实时对接需求、及时收发消息、丰富的开放项目需求、随时随地查看项目状态

评论