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

Commands by bugmenot from sorted by
Terminal - Commands by bugmenot - 46 results
pv /dev/urandom -L 3m -i 0.3 > /dev/null
2012-07-29 00:46:09
User: bugmenot
2

-L RATE, --rate-limit RATE

Limit the transfer to a maximum of RATE bytes per second. A suffix of "k", "m", "g", or "t" can be added to denote kilobytes (*1024), megabytes, and so on. It must be an integer.

find path -name '*' -type f | pax -wd > txtarchive.tar
2012-07-29 00:44:51
User: bugmenot
Functions: find pax
0

NOTE that pax goes always recursively, for that reason -d option should be added when you don't want to go recursively into directories.

find path -name '*' -type f | cpio -ov -H ustar -F txtarchive.tar
cat /dev/urandom | pv -L 3m | dd bs=1M count=100 iflag=fullblock > /dev/null
2012-07-29 00:42:16
User: bugmenot
Functions: cat dd
6

This example will close the pipe after transferring 100MB at a speed of 3MB per second.

find . -name '*' -type f -print0 | xargs -0 grep -n pattern1 | grep pattern2
2012-07-29 00:40:06
User: bugmenot
Functions: find grep xargs
1

The option -print0 for find and -0 for grep help prevent issue with weird characters or spaces in filenames. Furthermore with xargs there is no limited number of arguments that find can throw.

watch -n10 "if test -e run.txt ; then chmod +x script.sh && ./script.sh && rm run.txt || rm run.txt && echo > failed.txt ; fi"
2012-07-29 00:38:08
User: bugmenot
Functions: watch
0

You can upload via ftp the script.sh in unix text format, and then upload a file called run.txt to execute once the script. Such script can be multiline. If the script fails a failed.txt will be generated that you can see via ftp.

find ./ -type f -name "*.txt" -exec tar uvf myarchives.tar {} +
2012-07-29 00:35:58
User: bugmenot
Functions: find tar
4

Note: the tar archive must not exist in order to create it. If exists it will only be updated and no already existent files in present search will still remain in the tar archive. The update option has to be used instead of create because the command tar may be executed more than once depending on the number of arguments that find throws. You can see maximum number of arguments with 'getconf ARG_MAX'

mkfifo foo ; nc -lk 2600 0<foo | /bin/bash 1>foo
2012-07-29 00:33:41
User: bugmenot
Functions: mkfifo
7

Then just nc servername 2600 and ./script.sh

kill the client with ctrl+c. You can reconnect several times.

kill the server with exit

export PATH= $(echo $PATH | tr ':' '\n' | awk '!/matching string/' | paste -sd:)
grep "\-\-" file
fdupes -r -1 Neu | while read line; do j="0"; buf=""; for file in ${line[*]}; do if [ "$j" == "0" ]; then j="1"; buf=$file; else ln -f $buf $file; fi; done; done
killall -u username
read -s pass; echo $pass | md5sum | base64 | cut -c -16
2011-11-24 20:23:47
User: bugmenot
Functions: cut echo md5sum read
21

Why remember? Generate!

Up to 48 chars, works on any unix-like system (NB: BSD use md5 instead of md5sum)

scrot -s /tmp/file.png
2011-11-24 20:00:13
User: bugmenot
Tags: scrot
1

I think, this is a shorter one :)

<Ctrl+o>
2011-08-19 00:09:53
User: bugmenot
Tags: bash hotkey
-7

Type out the command and simply press to see the list of options for that command without having to type --help.

cat /usr/share/dict/words | grep -P ^[a-z].* | grep -v "'s$" | grep -Pv ^.\{1,15\}$ | shuf -n4 | tr '\n' ' ' | sed 's/$/\n/'
2011-08-15 01:03:48
User: bugmenot
Functions: cat grep sed tr
Tags: tr xkcd shuf
-2

The first grep rejects capitalised words since the dict has proper nouns in it that you mightn't want to use. The second grep rejects words with ending in apostrophe s, and the third forces the words to be at least 15 characters long.

MIN=10 && for i in $(seq $(($MIN*60)) -1 1); do printf "\r%02d:%02d:%02d" $((i/3600)) $(( (i/60)%60)) $((i%60)); sleep 1; done
tar -cvf - $DIR_TO_BACKUP | tee >(md5sum > backup_md5.txt) > /dev/st0 && mt -f /dev/nst0 bsfm 1 && md5sum -c backup_md5.txt < /dev/st0
2011-01-27 20:57:36
User: bugmenot
Functions: md5sum mt tar tee
0

Backups $DIR_TO_BACKUP into tape, creating on the fly a MD5SUM file of the backup.

Then rewinds one record on tape and checks if it's well written.

mksnap_ffs /var /var/.snap/snap_var_`date "+%Y-%m-%d"` ; mdconfig -a -t vnode -f /var/.snap/snap_var_`date "+%Y-%m-%d"` -u 1; mount -r /dev/md1 /mnt
2010-09-18 11:37:03
User: bugmenot
Functions: mount
0

(FreeBSD)

Once you've made the snapshot you can resume any stopped services and then back up the file system (using the snapshot) without having to worry about changed files.

When finished, the snapshot can be removed :

umount /mnt

mdconfig -d -u 1

rm /var/.snap/snap_var_`date "+%Y-%m-%d"`

sysctl dev.cpu.0.freq_levels
2010-09-18 11:19:46
User: bugmenot
Functions: sysctl
Tags: cpu powerd
2

Once you know the available frequencies for your CPU, they can be used to do things like set minimum CPU frequency for powerd so that it doesn't ramp down too slow on a server :

/etc/sysctl.conf or /boot/loader.conf:

debug.cpufreq.lowest=DESIRED FREQ HERE

or at terminal

sysctl debug.cpufreq.lowest=DESIRED FREQ HERE

aptitude purge '~c'