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.

Universal configuration monitoring and system of record for IT.
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

May 19, 2015 - A Look At The New Commandlinefu
I've put together a short writeup on what kind of newness you can expect from the next iteration of clfu. Check it out here.
March 2, 2015 - New Management
I'm Jon, I'll be maintaining and improving clfu. Thanks to David for building such a great resource!
Hide

Top Tags

Hide

Functions

Hide

Credits

All commands from sorted by
Terminal - All commands - 12,143 results
for /F "DELIMS=""" %i in ('dsquery group -name SourceGroupName ^| dsget group -members') do dsquery group -name TargetGroupName | dsmod group -addmbr %i
2009-09-25 16:32:33
User: miketheman
-3

Interacting with Active Directory to add users from one group to another group.

This prevents from having to deal with long DNs and copying, pasting problems. It executes once per returned object.

apropos network |more
2009-09-25 15:05:33
User: shaiss
Functions: apropos
11

Get all the networking related commands for your distro

dmidecode | awk '/VMware Virtual Platform/ {print $3,$4,$5}'
2009-09-25 14:46:35
User: SuperFly
Functions: awk
6

If you run this command on a VMWare Virtual Machine, it will return the string "VMware Virtual Platform". If you run it on a physical machine, it will return nothing. Useful for having a script determine if it's running on a VM or not. Of course, you must have dmidecode installed for this to work.

Try it this way in a script: ISVM=$(dmidecode | awk '/VMware Virtual Platform/ {print $3,$4,$5}')

Then test if $ISVM has text in it, or is blank.

ack --pager='less -r'
encfs ~/.crypt ~/crypt
2009-09-25 10:13:39
User: bkn390
8

Create/open/use an encrypted directory

encfs needs to be installed

During creation easiest to use default values

The encrypted files will be in ~/.crypt and you will work as usual in ~/crypt

To close the encrypted directory run:

fusermount -u ~/crypt

When you switch off the computer the encrypted directory will be automatically closed

This example uses /home/user/crypt as encrypted directory

I use ubuntu linux 8.04 and I am also the creator of www.minihowto.org

sudo dpkg -i packagename.deb
2009-09-25 09:54:04
User: bkn390
Functions: sudo
-7

Install a deb package you have downloaded (synaptic has to be closed).

(dpkg-dev needs to be installed)

After that you may have to run following:

sudo apt-get install -f

(that should fix any dependency problems)

I am using ubuntu linux

grep . filename > newfilename
mysql -e 'show databases' | sed -n '2,$p' | xargs -I DB 'mysqldump DB > DB.sql'
2009-09-25 08:43:06
User: mislav
Functions: sed xargs
Tags: mysqldump
5

No need to loop when we have `xargs`. The sed command filters out the first line of `show databases` output, which is always "Database".

gate() { mkfifo /tmp/sock1 /tmp/sock2 &> /dev/null && nc -p $1 -l < /tmp/sock1 | tee /tmp/sock2 & PID=$! && nc $2 $3 < /tmp/sock2 | tee /tmp/sock1; kill -KILL $PID; rm -f /tmp/sock1 /tmp/sock2 ; }
2009-09-25 08:10:23
User: true
Functions: kill mkfifo rm tee
1

USAGE: gate listening_port host port

Creates listening socket and connects to remote device at host:port. It uses pipes for connection between two sockets. Traffic which goes through pipes is wrote to stdout. I use it for debug network scripts.

eject -x 8 /dev/cdrom
2009-09-25 08:02:30
User: eastwind
Functions: eject
3

this command limit the speed to 8 until next eject of your cdrom disc , can be usefulll when you don't want to listen the sound of your cdrom driver .

bchunk IMAGE.bin IMAGE.cue IMAGE.iso
arecord -q -f cd -r 44100 -c2 -t raw | lame -S -x -h -b 128 - `date +%Y%m%d%H%M`.mp3
2009-09-25 05:32:52
User: oracular
Functions: arecord cd
11

record audio notes or meetings

requires arecord and lame

run mp3gain on the resulting file to increase the volume / quality

ctrl-c to stop recording

for i in {21..29}; do nc -v -n -z -w 1 192.168.0.$i 443; done
2009-09-25 03:31:29
User: rez0r
9

Simple one-liner for scanning a range of hosts, you can also scan a range of ports with Netcat by ex.: nc -v -n -z -w 1 192.168.0.1 21-443

Useful when Nmap is not available:)

Range declaration like X..X "for i in {21..29}" is only works with bash 3.0+

wget -q -O - 'http://wap.weather.gov.hk/' | sed -r 's/<[^>]+>//g;/^UV/q' | tail -n4
2009-09-25 02:36:46
User: dakunesu
Functions: sed tail wget
-1

"get Hong Kong weather infomation from HK Observatory

From Hong Kong Observatory wap site ;)"

other one showed alot of blank lines for me

wget -q -O - 'http://wap.weather.gov.hk/' | sed -r 's/<[^>]+>//g;/^UV/q' | grep -v '^$'
curl "http://www.house.gov/house/MemberWWW.shtml" 2>/dev/null | sed -e :a -e 's/<[^>]*>//g;/</N;//ba' | perl -nle 's/^\t\t(.*$)/ $1/ and print;'
2009-09-24 23:37:36
User: drewk
Functions: perl sed
Tags: perl sed curl
-1

Uses curl to download page of membership of US Congress. Use sed to strip HTML then perl to print a line starting with two tabs (a line with a representative)

column -s, -t <tmp.csv
2009-09-24 20:57:32
User: pykler
Functions: column
18

Splits the input based on commas and prints it in a nice column format. This would not work for CSV rows that have "," between quotes or with newline characters. Use only simple simple csv files.

find . -name "*.txt" -exec sed -i "s/old/new/" {} \;
lynx "futz.me/xxx hey this is a test"
2009-09-24 19:23:41
-1

Allows you to send yourself notes from the commandline and receive them via email or text message. Also lets you send pics from the web, pics from your computer, and tweets directly to twitter. All without having to log in Ever.

sed '/^$/d' file >newfile
random -f <file>
beepwhenup () { echo 'Enter host you want to ping:'; read PHOST; if [[ "$PHOST" == "" ]]; then exit; fi; while true; do ping -c1 -W2 $PHOST 2>&1 >/dev/null; if [[ "$?" == "0" ]]; then for j in $(seq 1 4); do beep; done; ping -c1 $PHOST; break; fi; done; }
2009-09-24 18:11:10
Functions: echo host ping read seq
Tags: ping beep
2

After this, just type:

beepwhenup

You need to install "beep" before this would make the beep sound.

Save it in your .profile if you want to use it later

WARNING: this command won't exit until it is successful. You won't be able to CONTROL+C out of it.

find [path] [expression] -exec du -ab {} \; | awk '{total+=$0}END{print total}'
echo $PATH|tr : '\n'|sort|uniq -d
md () { mkdir -p "$@" && cd "$@"; }
2009-09-24 16:09:19
User: drewk
Functions: cd mkdir
28

How often do you make a directory (or series of directories) and then change into it to do whatever? 99% of the time that is what I do.

This BASH function 'md' will make the directory path then immediately change to the new directory. By using the 'mkdir -p' switch, the intermediate directories are created as well if they do not exist.