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 din7 from sorted by
Terminal - Commands by din7 - 19 results
curl -Ls "http://support.dell.com/support/DPP/Index.aspx?c=us&cs=08W&l=en&s=biz&ServiceTag=$(dmidecode -s system-serial-number)"|egrep -i '>Your Warranty<|>Product Support for'|html2text -style pretty|egrep -v 'Request|View'|perl -pane 's/^(\s+|\})//g;'
2011-02-18 22:29:05
User: din7
Functions: egrep perl
-2

The dates in the output are Start Date, End Date, Days Remaining in warranty, respectively. This will only work if you are running it on a dell machine. You can substitute the dmidecode command with a service tag if you are not using a dell. Also, you have to either allow your user to run sudo dmidecode with no password or run this command as root.

ddrescue -v /dev/sda /dev/sdb logfile.log
2011-01-06 22:47:46
User: din7
1

If you use the logfile feature of ddrescue, the data is rescued very efficiently (only the needed blocks are read). Also you can interrupt the rescue at any time and resume it later at the same point.

http://www.gnu.org/software/ddrescue/ddrescue.html

awk '/Table structure for table .table01./,/Table structure for table .table02./{print}' <file> > restored_table.sql
2010-08-09 18:23:13
User: din7
Functions: awk
-1

This will look through file and print the data in between the pattern matches. It's great for restoring tables from a mysqldump backup. You can then import it back into your database with:

mysql -u <user> -h <host> <database> < restored_table.sql
perl -pi -e "s/\r/\n/g" <file>
2010-07-29 16:07:36
User: din7
Functions: perl
-1

Replace DOS character ^M with newline using perl inline replace.

audio-convert <dir>/*
2010-02-22 17:44:53
User: din7
1

Audio convert is a script that uses zenity and lame to transcode virtually any format to any other format provided you have the libraries installed to do so.

tc qdisc add dev <dev> root handle 1: cbq avpkt 1000 bandwidth 100mbit;tc class add dev <dev> parent 1: classid 1:1 cbq rate 300kbit allot 1500 prio 5 bounded isolated;tc filter add dev <dev> parent 1: protocol ip prio 16 u32 match ip dst <ip> flowid 1:1
2010-02-16 01:39:09
User: din7
0

Tc is used to configure Traffic Control in the Linux kernel. See man tc for further details.

This series of commands will limit the bandwidth of the specified device to the limit you set (300kbit in the second command) to the address you specify.

awk '!x[$0]++' <file>
2009-12-20 02:33:21
User: din7
Functions: awk
64

Using awk, find duplicates in a file without sorting, which reorders the contents. awk will not reorder them, and still find and remove duplicates which you can then redirect into another file.

tcpdump -nnvvXSs 1514 -i <device> <filters>
2009-12-17 22:30:55
User: din7
Functions: tcpdump
3

This command will show you the entire payload of a packet.

The final "s" increases the snaplength, grabbing the whole packet.

!?<string>?
2009-11-03 22:51:10
User: din7
8

Execute the most recent command containing search string.

This differs from !string as that only refers to the most recent command starting with search string.

nice -n19 dump -0af - /<filesystem> -z9|gpg -e -r <gpg key id>|cstream -v 1 -t 60k|ssh <user@host> "cat > backup.img"
2009-10-29 18:27:25
User: din7
Functions: dump gpg nice ssh
2

This command will nicely dump a filesystem to STDOUT, compress it, encrypt it with the gpg key of your choice, throttle the the data stream to 60kb/s and finally use ssh to copy the contents to an image on a remote machine.

date|osd_cat
2009-10-02 18:26:46
User: din7
Functions: date
7

This is very useful if you need to show someone some text from a distance. (Like someone standing over your shoulder...)

I'd recommend aliasing it to something like:

alias osd_cat="osd_cat -o 400 -s 8 -c blue -d 60 -f -*-bitstream\ vera\ sans-*-*-*--200-*-*-*-*-*-*-*"

xosd is the utility that provides osd_cat.

taskset -cp <core> <pid>
2009-08-12 20:45:46
User: din7
Functions: taskset
9

Set the affinity of a process to a particular core(s).

Arguments for processor include a comma separated list, or a range. (example: 1,2 or 0-3)

You can use top in smp mode (Press 1) to see the changes to the affinity.

curl -s http://isc.sans.org/sources.html|grep "ipinfo.html"|awk -F"ip=" {'print $2'}|awk -F"\"" {'print $1'}|xargs -n1 sudo iptables -A OUTPUT -j DROP -d > 2&>1
dig -t txt -c chaos VERSION.BIND @<dns.server.com>
2009-07-30 18:38:39
User: din7
Functions: dig
8

Due to the recent dynamic update vulnerability with bind, I was forced to dig a little deeper into dig...

knock <host> 3000 4000 5000 && ssh -p <port> user@host && knock <host> 5000 4000 3000
2009-07-28 14:08:01
User: din7
Functions: ssh
33

Knock on ports to open a port to a service (ssh for example) and knock again to close the port. You have to install knockd.

See example config file below.

[options]

logfile = /var/log/knockd.log

[openSSH]

sequence = 3000,4000,5000

seq_timeout = 5

command = /sbin/iptables -A INPUT -i eth0 -s %IP% -p tcp --dport 22 -j ACCEPT

tcpflags = syn

[closeSSH]

sequence = 5000,4000,3000

seq_timeout = 5

command = /sbin/iptables -D INPUT -i eth0 -s %IP% -p tcp --dport 22 -j ACCEPT

tcpflags = syn

mencoder dvd://<title> -dvd-device <device> -aid 128 -info srcform='ripped by mencoder' -oac mp3lame -lameopts abr:br=128 -ovc xvid -xvidencopts pass=2:bitrate=-700000 -ofps 30000/1001 -o '<outputfile.avi>'
2009-07-19 20:53:54
User: din7
Tags: mencoder
2

This set of commands will rip a dvd title using a 2 pass mencoder xvid encode. It will provide a great quality rip. It will rip as close to 700MB as possible. (note the bitrate of -700000)

Enjoy!

mencoder dvd://<title> -dvd-device <device> -aid 128 -info srcform='ripped by mencoder' -oac mp3lame -lameopts abr:br=128 -ovc xvid -xvidencopts pass=1:chroma_opt:vhq=4:bvhq=1:quant_type=mpeg -vf pp=de,crop=0:0:0:0, -ofps 30000/1001 -o '/dev/null'
2009-07-19 20:50:57
User: din7
2

This set of commands will rip a dvd title using a 2 pass mencoder xvid encode. It will provide a great quality rip. It will rip as close to 700MB as possible. (note the bitrate of -700000)

Enjoy!

for i in $(tar -tf <file.tar.gz>); do rm $i; done;
2009-07-06 19:57:23
User: din7
Functions: rm tar
-4

Remove annoying improperly packaged files that untar into the incorrect directory.

Example, When you untar and it extracts hundreds of files into the current directory.... bleh.

curl -v -k -u user:password "https://members.dyndns.org/nic/update?hostname=<your_domain_name_here>&myip=$(curl -s http://checkip.dyndns.org | sed 's/[a-zA-Z<>/ :]//g')&wildcard=NOCHG&mx=NOCHG&backmx=NOCHG"
2009-06-24 17:00:15
User: din7
5

This is great if you are behind a router that does not support dynamic dns updates!

Example: AT&T u-verse gateway...

Put this in a script and run it as a cron job.