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
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.

find . -name "pattern" -exec stat -c%s {} \; | awk '{total += $1} END {print total}'
2014-01-15 11:07:09
User: Koobiac
Functions: awk find stat
1

Find files and calculate size with stat of result in shell

IFS=$(echo -en "\n\b"); mkdir Epub; for i in `find . | grep epub`; do echo "epub: $i"; mv -v "$i" Epub; done
dsquery group -samid "Group_SAM_Account_Name" | dsget group -members -expand
gem list | cut -d" " -f1 | grep --invert-match "test-unit\|psych\|io-console\|rdoc\|json\|bigdecimal\|rake\|minitest" | xargs gem uninstall -aIx
2014-01-10 10:58:59
User: gdelfino
Functions: cut grep xargs
-1

This command removes all ruby gems except the default ones that can not be removed. It is based on http://geekystuff.net/2009/01/14/remove-all-ruby-gems/

cd ~/wallpapers; feh --bg-fill "$( ls | sort -R | head -n 1 )"
2014-01-09 03:40:15
User: minnmass
Functions: cd
3

don't bother spawning a bc process or counting the number of options, just pick a random one.

'sort -R' sorts randomly, so pick the top one.

CMD=chrome ; ps h -o pmem -C $CMD | awk '{sum+=$1} END {print sum}'
netstat -tup -W | column -t
2014-01-08 22:39:01
User: b_t
Functions: column netstat
3

The -W switch of netstat makes it print complete URL of the connections, which otherwise by default

is truncated to fit its default column size.

Now to compensate for irregular column sizes, pipe the output to column (-t switch of column prints in tabular form). The only downside to this part is that the very first row, the header, goes pear shape.

rsstail -o -n 1 --f 'RedditQuote: {title}' http://www.reddit.com/r/quotes/new/.rss
2014-01-08 15:33:48
User: Youpfu
-1

The rsstail is the python version (python-rsstail). The final command pipe it on every new line to gammu and a connected phone

rsstail -o -n 1 --f 'RedditQuote: {title}' http://www.reddit.com/r/quotes/new/.rss | while read line; do /usr/bin/gammu --sendsms TEXT +*yournumber* -text "$line"; done
thunderbird -compose "attachment='file://`pwd`/$*'"
Enable-DistributionGroup Name-of-Dist-Group
2014-01-07 18:49:07
-8

To disable the requirement for the sender to be authenticated:

Set-DistributionGroup -Identity Name-of-Dist-Group -RequireSenderAuthenticationEnabled $false

To disable the group:

disable-DistributionGroup Name-of-Dist-Group

find ./ -name '*:*' -exec rename 's/:/_/g' {} +
dpkg-query -W --showformat='${Installed-Size}\t${Package}\n' | sort -nr | less
ls --color=never -1| grep -E "[0-9]{4}"|sed -re "s/^(.*)([0-9]{4})(.*)$/\2 \1\2\3/" | sort -r
watch -n 10 free -m
2014-01-04 10:10:15
User: Darkstar
Functions: free watch
-1

This command shows a high level overview of system memory and usage refreshed in seconds. Change -n 10 to you desired refresh interval.

ps -eo pmem,comm | grep chrome | cut -d " " -f 2 | paste -sd+ | bc
2014-01-03 15:33:16
User: Darkstar
Functions: cut grep paste ps
0

This command will show the sum total of memory used in gigabytes by a program that spawns multiple instances of itself. Replace chrome with whatever program's memory usage you are investigating. This command is rather useless on software that only spawns a single instance of itself.

dsquery computer -name COMPUTERNAME -inactive 4
putty -L 631:localhost:631 username@server
net user USERNAME /domain