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.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

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.

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

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 11,928 results
ps -U nms -o pid,nlwp,cmd:500 | sort -n -k2) && (ps h -U nms -o nlwp | paste -sd+ | bc)
ps axo pid=,stat= | awk '$2~/^Z/ { print $1 }'
2014-11-26 21:29:33
User: krizzo
Functions: awk ps
0

This prints out a list of all zombie processes PIDs so you can do things like kill the zombies

speakwhenup() { [ "$1" ] && PHOST="$1" || return 1; until ping -c1 -W2 $PHOST >/dev/null 2>&1; do sleep 5s; done; espeak "$PHOST is up" >/dev/null 2>&1; }
2014-11-26 10:22:18
User: aguslr
Functions: ping return sleep
Tags: ping beep espeak
0

This allows for sleeping in between pings. Also, espeak needs to be installed.

sed -i 's/geteuid/getppid/g' /usr/bin/vlc
2014-11-21 17:43:59
User: nadavkav
Functions: sed
Tags: root vlc
-5

Enable root user to run VLC

isKsh () { one=1; [ one -eq 1 ] 2> /dev/null; }
2014-11-18 20:45:12
User: applemcg
2

Dave Korn gave me this one. It works because ksh allows variable names ( w/o the $name syntax ) used by sh and bash.

I wrote it to permit "single source" shell libraries; the current objective: every shell library may be sourced by either shell. see http://github.com/applemcg/backash

touch -t 197001010000 ./tmp && find . -newer ./tmp && rm -f ./tmp
2014-11-18 00:29:26
User: sergeylukin
Functions: find rm touch
-2

Sometimes you just want to operate on files that were created after specific date. This command consists of 3 commands:

- Create a dummy file with the custom date

- Find all files with "creation time" further than our custom date by using `-newer` find option. Add your crazy stuff here, like moving, deleting, printing, etc.

- Remove the dummy file

locate -0 -i *barthes* | xargs -0 mv -t ~/'Library/Books/Barthes, Roland'
2014-11-16 18:26:35
User: qdrizh
Functions: locate mv xargs
Tags: mv xargs locate
0

Find all books on my systems and move them into folder. The -0 switches are to handle spaces etc. in the filenames.

Why would you need this? Locate uses an index, so it's super quick, and xargs is more elegant than a for loop.

python -c "import pip; print(' '.join([x.project_name for x in pip.get_installed_distributions()]))" | xargs sudo pip install -U
brew outdated | cut -f1 | xargs brew upgrade
2014-11-16 09:51:50
User: wires
Functions: cut xargs
1

You probably want to run `brew update` before you run this command

find ./i18n -name "*.po" | while read f; do msgfmt $f -o ${f%.po}.mo; done
2014-11-14 19:14:35
User: sergeylukin
Functions: find read
0

This command takes all `.po` files inside `i18n` directory and compiles them to `.mo` files with same basename

lxshortcut -o ~/Desktop/myLauncher
PID=$(ps -ef | grep processName | grep -v grep | awk '{print $2'}); kill -9 $PID
pm2 start app.js
2014-11-07 23:15:12
User: strzel_a
0

I'm the author of PM2 and wrote this tool, and I'm please to share it here.

Github project link: https://github.com/Unitech/pm2

nmap -sP 192.168.1.0/24
curl -s -o /dev/null -w "%{http_code}\n" localhost
curl --write-out %{http_code} --silent --output /dev/null localhost
mencoder -speed 2 -o output.avi -ovc lavc -oac mp3lame input.avi
starts a CGI web server
2014-11-05 23:07:37
User: andreisid
1

In case you need to test some CGI scripts this does the job. It also has the functionality of a http server.

Enjoy!

grep VmHWM /proc/$(pgrep -d '/status /proc/' FOO)/status
2014-11-05 15:06:29
User: michelsberg
Functions: grep
2

Show the maximum amount of memory that was needed by a process at any time. My use case: Having a long-running computation job on $BIG_COMPUTER and judging whether it will also run on $SMALL_COMPUTER.

http://man7.org/linux/man-pages/man5/proc.5.html

VmHWM: Peak resident set size ("high water mark")

chmod +x myfile.py
export PATH=$PATH:/home/user/my_prog
grep 'font-family:[^;]*' <input file.svg> | sed 's/.*font-family:\([^;]*\).*/\1/g' | sort | uniq
2014-11-03 20:38:08
User: caiosba
Functions: grep sed sort
Tags: fonts svg
0

List all fonts used by an SVG file. Useful to find out which fonts you need to have installed in order to open/edit an SVG file appropriately.

sed -i 's/oldname/newname/' /etc/hosts /etc/hostname
2014-11-02 22:03:48
User: adria
Functions: sed
Tags: sed hostname host
0

With sed you can replace strings on the fly.

curl ifconfig.me
2014-11-02 21:57:52
User: adria
0

http://ifconfig.me is a web site which shows your public iP address.

If you want use your own code, you can use PHP code such as:

function getip()

{

return "".$_SERVER["REMOTE_ADDR"];

}

echo getip();

?>

Then, you'll get your IP by 'curl yourfile.php'.

grep -Eoa "\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\b" Filetosearch.txt
2014-11-02 19:50:54
User: jsbrown
Functions: grep
0

Command returns valid IP addresses. Append the following regex to additionally filter out NAT and reserved IP addresses

| grep -Ev "^0|\.0[0-9]|^10\.|^127\.|^169\.|^172\.(1[6-9]|2[0-9]|3[01])|^192.168.|^2(2[4-9]|3[0-9])|^2(4[0-9]|5[0-5])"