Hide

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again.

Delete that bloated snippets file you've been using and share your personal repository with the world. That way others can gain from your CLI wisdom and you from theirs too. All commands can be commented on, discussed and voted up or down.


Get involved!

You can sign-in using OpenID credentials, or register a traditional username and password.

First-time OpenID users will be automatically assigned a username which can be changed after signing in.

Universal configuration monitoring and system of record for IT.
Hide

Stay in the loop…

Follow the Tweets.

Every new command is wrapped in a tweet and posted to Twitter. Following the stream is a great way of staying abreast of the latest commands. For the more discerning, there are Twitter accounts for commands that get a minimum of 3 and 10 votes - that way only the great commands get tweeted.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

Subscribe to the feeds.

Use your favourite RSS aggregator to stay in touch with the latest commands. There are feeds mirroring the 3 Twitter streams as well as for virtually every other subset (users, tags, functions,…):

Subscribe to the feed for:

Hide

News

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Top Tags

Hide

Functions

Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

All commands from sorted by
Terminal - All commands - 12,371 results
$ sed "2s/$/ $(sed -n '4p' sound.desktop)/" sound.desktop
2016-08-23 02:50:31
User: pibarnas
Functions: sed
0

Using "", which allow bash commands to be interpreted by sed scripts, I've embedded a sed script in another sed substitution, in case, the 4th line of the file at the end of the second one.

rsync --daemon --port 1234 --no-detach -v --config rsyncd.conf
mv ~/html/*~ ~
2016-08-17 17:28:07
User: pascalv
Functions: mv
Tags: mv html CGI
-6

This prevents access to old CGI code

Print everything after last slash
2016-08-17 07:10:33
User: qdrizh
Functions: last
Tags: sed
0

FQPN - Path = Filename

pip install --prefix $PWD -I pip
2016-08-16 06:02:17
User: yoyoyojomo
Functions: install
4

For subsequent commands in the prefixed path:

PYTHONPATH=$PWD/lib/python*/site-packages ./bin/pip --version
printf '%s-%s-%s-%s\n' $(grep -v "[A-Z]\|'" /usr/share/dict/british | shuf -n 4)
2016-08-15 08:13:10
User: hendry
Functions: grep printf
1

https://xkcd.com/936/ introduced us to what actually is a good password. Here's such an implementation.

Credit: quinq on #suckless

printf "\U$(printf '%x' $((RANDOM%79+128512)) )"
2016-08-11 15:59:59
Functions: printf
Tags: bash emoji
3

This will print a random emoji within the range of 1F600 - 1F64F, which includes all the face emoji.

Obviously, this will only show something meaningful if your terminal can display emoji, but it may be useful in scripts.

This likely requires recent versions of bash

curl -s httpbin.org/ip | jq -r .origin
while true ; do fswebcam -d /dev/video0 -r 1280x1024 -F 15 - | uuencode $(date +\%Y\%m\%d\%H\%M).jpeg | mail -s "Video surveillance" [email protected] ; sleep 300 ; done
2016-08-09 14:22:45
User: pascalv
Functions: date mail sleep true uuencode
2

This takes a picture (with the web cam) every 5 minutes, and send the picture to your e-mail.

Some systems support

mail -a "References: "

so that all video surveillance emails are grouped in a single email thread.

To keep your inbox clean, it is still possible to filter and move to trash video surveillance emails (and restore these emails only if you really get robbed!)

For instance with Gmail, emails sent to [email protected] can be filtered with "Matches: DeliveredTo:[email protected]"

ps auxw | grep -E 'sbin/(apache|httpd)' | awk '{print"-p " $2}' | xargs strace -F
2016-08-04 10:59:58
User: gormux
Functions: awk grep ps strace xargs
Tags: awk grep ps strace
1

Will open strace on all apache process, on systems using sbin/apache (debian) or sbin/httpd (redhat), and will follow threads newly created.

gem install `ruby ./isuckat_ruby.rb 2>&1 | sed -e 's/.*find gem .//g' -e 's/ .*//g' | head -n 1`
2016-08-03 19:41:27
User: operat0r
Functions: head install sed
0

When bundle install sucks ...This runs isuckat_ruby.rb and when stderror matches find gem ' it will gem install what ever is missing ...

sed 'X{N;s/\n//;}' file.txt (where X is the current line)
2016-07-30 14:27:20
User: pibarnas
Functions: sed
2

N: On the current line, sed will display it on pattern space, plus a \n (new line); but

s/\n//: Will get rid of new line displayed on pattern space, joining the current line's end with the start of the next line

Useful in scripts.

links `lynx -dump -listonly "http://news.google.com" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_-]*" | grep -v "google.com" | sort -R | uniq | head -n1`
2016-07-26 12:54:53
User: mogoh
Functions: grep head sort uniq
1

sort -R randomize the list.

head -n1 takes the first.

links $( a=( $( lynx -dump -listonly "http://news.google.com" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_-]*" | grep -v "google.com" | sort | uniq ) ) ; amax=${#a[@]} ; n=$(( `date '+%s'` % $amax )) ; echo ${a[n]} )
2016-07-26 11:52:12
User: pascalv
Functions: echo grep sort uniq
2

Access a random news web page on the internet.

The Links browser can of course be replaced by Firefox or any modern graphical web browser.

!!:s/foo/bar/
2016-07-25 18:52:42
User: malathion
3

Replaces the first instance of 'foo' with 'bar'. To replace all instances of 'foo' with 'bar': !!:gs/foo/bar/

f=correlation.png; s=400; t=50; a=1.2; convert $f -resize ${s}% -threshold ${t}% bmp:- | potrace -o ${f%.*}.svg -b svg -z black --fillcolor "#FFFFFF" --alphamax ${a}
2016-07-25 10:45:28
User: T4b
1

Uses ImageMagick and potrace to vectorize the input image, with parameters optimized for xkcd-like pictures.

while true ; do wget --quiet --no-check-certificate --post-data 'login=my_account_number&password=my_password&submit=Valider' 'https://wifi.free.fr/Auth' -O '/dev/null' ; sleep 600; done
2016-07-23 16:34:42
User: pascalv
Functions: sleep true wget
Tags: wifi France
1

(In French) Connection aux hotspots FreeWifi, et maintien de la connection active

hpacucli controller all show config detail | grep -A 7 Fail | egrep '(Failed|Last|Serial Number|physicaldrive)'
2016-07-20 17:42:40
User: operat0r
Functions: egrep grep
1

This dumps serial numbers of all the drives but HP warranty check does not say they are valid ...

tree -i -L 1
curl -s http://whatismyip.org/ | grep -oP '(\d{1,3}\.){3}\d+'
lsa() { ls -lart; history -s "joe \"$(\ls -apt|grep -v /|head -1)\"" ; }
2016-07-07 21:27:55
User: knoppix5
Functions: ls
3

Display recursive file list (newest file displayed at the end) and be free to access last file in the list simply by pressing arrow_up_key i.e. open it with joe editor.

BTW IMHO the list of files with newest files at the end is often more informative.

Put this 'lsa' function somewhere in your .bashrc and issue

. ~/.bashrc

or

source ~/.bashrc

to have access to the 'lsa' command immediately.

.

(the function appends command "joe last_file_in_the_list" at the end of command history)

while true; do A=$(stat -c%s FILE); sleep 1; B=$(stat -c%s FILE); echo -en "\r"$(($B-$A))" Bps"; done
2016-06-27 20:39:06
User: Zort
Functions: echo sleep stat
-2

Muestra el crecimiento de un archivo por segundo.

Cambia el texto "FILE" por el nombre del archivo a monitorear.

Comando STAT

while true; do A=$(ls -l FILE | awk '{print $5}'); sleep 1; B=$(ls -l FILE | awk '{print $5}'); echo -en "\r"$(($B-$A))" Bps"; done
2016-06-27 20:33:02
User: Zort
Functions: awk echo ls sleep
-3

Muestra el crecimiento de un archivo por segundo.

Cambia el texto "FILE" por el nombre del archivo a monitorear.

Comando LS + AWK

netstat -n | grep ESTAB |grep :80 | tee /dev/stderr | wc -l
2016-06-26 11:37:19
User: rubenmoran
Functions: grep netstat tee wc
3

Summarize established connections after netstat output.

Using tee and /dev/stderr you can send one command output to terminal before executing wc so you can summarize at the bottom of the output.

sed '/INSERT INTO `unwanted_table`/d' mydb.sql > reduced.sql
2016-06-24 20:13:47
User: sudopeople
Functions: sed
1

Starting with a large MySQL dump file (*.sql) remove any lines that have inserts for the specified table. Sometimes one or two tables are very large and uneeded, eg. log tables. To exclude multiple tables you can get fancy with sed, or just run the command again on subsequently generated files.