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,491 results
touch -r "source_file" "destination_file"
phpunit --log-json php://stdout | awk '$NF ~ '/,/' && $1 ~ /"(test|time)"/' | cut -d: -f2- | sed "N;s/\n/--/" | sed "s/,//"| awk 'BEGIN{FS="--"}; {print $2 $1}' | sort -r | head -n 5
alias t="tee >(pbcopy)"
2014-01-24 12:41:07
User: lgarron
Functions: alias
0

Very convenient to for sending data to the clipboard for processing.

However, note that tee will affect the buffering of the output (stdout won't be update very live).

rename s/ .php/ .html/ *.html
imv foo
2014-01-24 01:34:01
User: denilsonsa
Tags: mv cp
0

icp and imv, interactive versions of cp and mv, will prompt the user for the new filename. These tools are from rename-utils package.

netstat -tunlapo
2014-01-23 20:44:31
User: treebeard
Functions: netstat
Tags: netstat
0

-t TCP

-u UDP

-n NO DNS resolution or PORT/SERVICE resolution

-l state

-a ?

-p PORT show

-o flag (keepalive, off, etc)

diff <(cat /etc/fstab | grep vol | grep -v "^#" | awk '{print $1}') <(df -h | grep vol)
2014-01-23 15:18:08
User: Koobiac
Functions: awk cat df diff grep
Tags: diff fstab df
0

With this command, you can check the difference between the volumes mounted and the volume in /etc/fstab.

iconv -f $(file -bi filename.ext | sed -e 's/.*[ ]charset=//') -t utf8 filename.ext > filename.ext
for i in rpcbind nfslock lldpad fcoe rpcidmapd; do service $i stop; chkconfig $i off; done
2014-01-23 05:05:22
User: prasad
Functions: chkconfig
Tags: for loop
0

We will turn off and stop multiple linux services using FOR LOOP.

netstat -t -u -l
2014-01-23 05:01:46
User: prasad
Functions: netstat
1

This command show listening sockets TCP and UDP. Useful for stop unwanted services from linux.

cp foo{,bak}
2014-01-22 14:09:42
Functions: cp
Tags: cp
12

Utilizes shell expansion of {} to give the original filename and a new filename as arguments to `cp`. Can easily be extended to make multiple copies.

zipinfo -1 aap.zip | xargs -d '\n' rm
grep -v rootfs /proc/mounts > /etc/mtab
while true; do rsync -vR $(git ls-files | inotifywait -q -e modify -e attrib -e close_write --fromfile - --format '%w') user@host:dest/dir/; done
2014-01-21 10:31:41
User: leucos
Functions: rsync
0

While edtiing a project under git, it is sometimes nice to sync changes immediately to a test machine.

This command will take care of this if you have inotifywait installed on the developement machine.

Note the -R (relative) in rsync. with

rsync foo/bar/baz user@host:dest/dir/

it will put 'baz' in dest/dir/foo/bar/ which is what we want.

this can be turned into a function for additionnal flexibility :

function gitwatch() {

if [ -z $1 ]; then

echo "You must provide a rsync destination"

return

fi

while true; do

rsync -vR $(git ls-files | inotifywait -q -e modify -e attrib -e close_write --fromfile -

--format '%w') $1

done

}

while [ 1 ] ;do ps aux|awk '{if ($8 ~ "D") print }'; sleep 1 ;done
proot -r /media/user/ubuntu12.10/ cat /etc/motd
2014-01-21 07:50:22
User: totti
Functions: cat
2

PRoot is a user-space implementation of chroot, mount --bind, and binfmt_misc. This means that users don't need any privileges or setup to do things like using an arbitrary directory as the new root filesystem, making files accessible somewhere else in the filesystem hierarchy, or executing programs built for another CPU architecture transparently through QEMU user-mode. Also, developers can use PRoot as a generic Linux process instrumentation engine thanks to its extension mechanism, see CARE for an example. Technically PRoot relies on ptrace, an unprivileged system-call available in every Linux kernel.

https://github.com/cedric-vincent/PRoot

gsettings get org.gnome.desktop.background picture-uri | xargs nautilus
sc query service_name
ls -1 | xargs ruby -e'puts ARGV.shuffle'
find . -type f -regex ".*/core.[0-9][0-9][0-9][0-9]$"
2014-01-17 16:44:47
User: H3liUS
Functions: find
0

Will find and list all core files from the current directory on. You can pass | xargs rm -i to be prompted for the removal if you'd like to double check before removal.

find . -name '*.sh' -exec bash -n {} \;
2014-01-17 16:20:36
User: tsener
Functions: bash find
8

Check all bash scripts in current dir for syntax errors WITHOUT running them.

ls -l /usr/share/xsessions/
2014-01-17 05:09:18
User: puresky
Functions: ls
0

Sometimes there are just no variables such as $DESKTOP_SESSION, $GDMSESSION, or $WINDOWMANAGER.

find . -name "pattern" -type f -exec du -ch {} + | tail -n1
zfs list -H -o name -t snapshot | xargs -n1 -t zfs destroy