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 using cat from sorted by
Terminal - Commands using cat - 430 results
check_disk -w 15% -c 10% $(for x in $(cat /proc/mounts |awk '{print $2}')\; do echo -n " -p $x "\; done)
cat foo.csv bar.csv | sort -t "," -k 2 | uniq
2009-02-19 20:23:03
User: rafeco
Functions: cat sort
2

The value for the sort command's -k argument is the column in the CSV file to sort on. In this example, it sorts on the second column. You must use some form of the sort command in order for uniq to work properly.

cat somefilehere.txt | ssh-xfer nametocallfile.txt -
2009-02-19 18:35:33
User: scubacuda
Functions: cat
0

from http://matt.ucc.asn.au/ssh-xfer/

"ssh-xfer is a hackish but handy way of transferring files from remote hosts to your local computer. Firstly, you need to run a slightly modified SSH authentication agent program on your local computer. Patches are available for both OpenSSH and PuTTY, see below. If you haven't used a SSH agent program before, this article seems to be reasonable, or you can look at the OpenSSH/PuTTY docs.

You don't need any modifications to your ssh client or server programs - only the modified SSH authentication agent, and the extra ssh-xfer program."

for i in $(cat listofservers.txt); do konsole --new-tab -e ssh $i; done
2009-02-19 16:32:36
User: nottings
Functions: cat ssh
4

creates a new tab for each of N servers in listofservers.txt and ssh's to said servers

then, try the "send to all sessions" feature of konsole to do the same work on all servers at the same time. BIG time saver, but be careful!

cat .ssh/id_dsa.pub | ssh elsewhere "[ -d .ssh ] || mkdir .ssh ; cat >> .ssh/authorized_keys"
2009-02-18 22:13:04
User: jsiren
Functions: cat ssh
5

Enter your ssh public key in the remote end for future key-based authentication. Just type your password one last time. The next time you should be able to login with the public key. If you don't have a key, generate one with ssh-keygen.

Requires Bourne-compatible shell in the remote end.

cat /dev/urandom > /dev/dsp
2009-02-18 21:40:29
User: joem86
Functions: cat
4

This command will generate white noise through your speakers (assuming you have sound enabled). It's good for staying focused, privacy, coping with tinnitus, etc. I use it to test that the sound works.

cat /dev/mem > /dev/audio
ssh user@host cat /path/to/some/file | xclip
2009-02-18 10:56:38
User: raphink
Functions: cat ssh
Tags: X X11
18

Have you ever had to scp a file to your work machine in order to copy its contents to a mail? xclip can help you with that. It copies its stdin to the X11 buffer, so all you have to do is middle-click to paste the content of that looong file :)

On PC1: nc -l -p 6666 > /dev/dsp On PC2: cat /dev/dsp | nc <PC1's IP> 6666
2009-02-18 00:39:32
User: someguy
Functions: cat
6

Sends the microphone input from PC1 to the speakers of PC2. Do the same in reverse to have an actual conversation ;) ... maybe with another port tough

cat /proc/cpuinfo
2009-02-17 14:50:29
User: stinger
Functions: cat
-4

how to get full cpu info of your (linux) box

cat /dev/urandom | gzip -9 > /dev/null &
2009-02-16 14:12:38
Functions: cat gzip
3

check your load with top... Start more of these jobs to get an multi-core cpu busy...

cat ~/.ssh/*.pub | ssh user@remote-system 'umask 077; cat >>.ssh/authorized_keys'
MAC=`(date; cat /proc/interrupts) | md5sum | sed -r 's/^(.{10}).*$/\1/; s/([0-9a-f]{2})/\1:/g; s/:$//;'`
2009-02-16 07:09:43
User: vaporub
Functions: cat md5sum sed
15

Original author unknown (I believe off of a wifi hacking forum).

Used in conjuction with ifconfig and cron.. can be handy (especially spoofing AP's)

sudo aptitude -y install iasl && sudo cat /sys/firmware/acpi/tables/DSDT > dsdt.dat && iasl -d dsdt.dat
2009-02-15 23:13:50
User: brettalton
Functions: cat install sudo
-1

In July 2008, there was an uproar over Foxconn motherboards feeding Linux installs incorrect ACPI information (http://ubuntu-virginia.ubuntuforums.org/showthread.php?t=869249).

Foxconn has gladly corrected their mistake, but make sure it's not happening on your motherboard!

After running the command, just view the 'dsdt.dsl' in any editor you like.

cat -n $file | tail -n 100 && head -n number-of-lines-you-want-to-keep > newfile
2009-02-15 01:02:10
User: bbelt16ag
Functions: cat head tail
-1

tells you the number of lines in said file, and then tail the last 100 lines ( or how many are messed up) then u take the total amount of lines and then subract the 100 or so lines u DONT WANT, then do a head -n $new_number and then redirect it to new file.db

cat welcome | wall
2009-02-14 18:12:50
User: Williebee
Functions: cat
-3

Show message in file "welcome" to all logged in terminal users.

cat SomeFile.txt | pbcopy
2009-02-13 15:23:10
Functions: cat
2

Great for little scripts that dig up obscure info that you are going to have to paste into another app anyway.

cat /dev/null >filename
2009-02-13 10:50:41
User: vorphalax
Functions: cat
-8

with this command you can empty file

cat .ssh/id_rsa.pub | ssh hostname 'cat >> .ssh/authorized_keys'
2009-02-11 17:40:12
User: bendavis78
Functions: cat hostname ssh
14

Just run the command, type your password, and that's the last time you need to enter your password for that server.

This assumes that the server supports publickey authentication. Also, the permissions on your home dir are 755, and the permissions on your .ssh dir are 700 (local and remote).

cat file.php | perl -p -e 's/(\$|->)(str|arr|obj|int|flt|boo|bool|mix|res)([A-Z])/$1\L$3/g'
2009-02-10 14:37:12
User: root
Functions: cat perl
0

This removes the type prefix used in Hungarian notation (v. bad) for PHP variables. Eg. variables of the form $intDays, $fltPrice, $arrItems, $objLogger convert to $days, $price, $Items, $logger.

cat -n file.txt
split -b 1k file ; cat x* > file
2009-02-08 23:10:18
User: abcde
Functions: cat file split
2

`split -b 1k file` splits files into 1k chunks. Rejoin them with `cat x* > file`.

cat /proc/<PID>/environ
2009-02-07 20:49:19
User: al3x
Functions: cat
0

Good to find out about hostile processes

cat file.txt|perl -ne '$_=~s/\s+/\n/g; print $_;'
2009-02-06 08:47:18
User: foodie
Functions: cat
-4

This command is useful for separating a text file where all the words are in one line. Any group of spaces will be replaced with a single newline. Instead of one long line of tokens. You'll have a long list of tokens. One token per line.