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,484 results
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
nvidia-settings -q gpucoretemp -t | awk '{s+=$1}END{print s/NR}' RS=" "
function dellomsaver { snmpwalk -v2c -cmycommunityname $1 1.3.6.1.4.1.674.10892.1.100.2.0; }
2014-01-16 16:30:41
User: jim80net
0

of course change community name to suit. Then blast this in a for i in $(buncha hosts); do dellomsaver $i; done loop

server$ while true; do read -n30 ui; echo $ui |openssl enc -aes-256-cbc -a -k PaSSw; done | nc -l -p 8877 | while read so; do decoded_so=`echo "$so"| openssl enc -d -a -aes-256-cbc -k PaSSw`; echo -e "Incoming: $decoded_so"; done
2014-01-16 14:36:09
User: arno
Functions: echo read
7

client$ while true; do read -n30 ui; echo $ui |openssl enc -aes-256-cbc -a -k PaSSw ; done | nc localhost 8877 | while read so; do decoded_so=`echo "$so"| openssl enc -d -a -aes-256-cbc -k PaSSw`; echo -e "Incoming: $decoded_so"; done

This will establish a simple encrypted chat with AES-256-CBC using netcat and openssl only.

More info here http://www.nixaid.com/linux/network/encrypted-chat-with-netcat

echo $(($(find . -name "pattern" -type f -printf "+%s")))
2014-01-16 03:14:36
User: flatcap
Functions: echo find
3

Use find's internal stat to get the file size then let the shell add up the numbers.

find . -name "pattern" -type f -printf "%s\n" | awk '{total += $1} END {print total}'
2014-01-16 01:16:18
User: pdxdoughnut
Functions: awk find
2

Using find's internal stat to get the file size is about 50 times faster than using -exec stat.

mkdir Epub ; mv -v --target-directory=Epub $(fgrep -lr epub *)
convert yourdoublewideimage.jpg -crop 50%x100% +repage output.jpg
2014-01-15 15:34:41
User: pagesix1536
0

Output should be two JPG files named like "output-1.jpg" and "output-2.jpg". The convert command is part of ImageMagick so you'll need that and dependent packages installed to use it.