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
for USER in /var/spool/cron/*; do echo "--- crontab for $USER ---"; cat "$USER"; done
2014-12-11 19:48:46
User: tyzbit
Functions: cat echo
0

This is not exhaustive but after checking /etc/cron* is a good way to see if there are any other jobs any users may have set.

Note: this is a repost from a comment "flatcap" made on http://www.commandlinefu.com/commands/view/3726/print-crontab-entries-for-all-the-users-that-actually-have-a-crontab#comment, for which I am grateful and I take no credit.

while sleep 1; do if [ $(echo "$(cat /proc/loadavg | cut -d' ' -f1) > .8 " | bc) -gt 0 ]; then echo -e "\n\a"$(date)" \e[5m"$(cat /proc/loadavg)"\e[0m"; ps aux --sort=-%cpu|head -n 5; fi; done
2014-12-08 15:44:40
User: tyzbit
Functions: cat echo head ps sleep
0

This checks the system load every second and if it's over a certain threshold (.8 in this example), it spits out the date, system loads and top 4 processes sorted by CPU.

Additionally, the \a in the first echo creates an audible bell.

cat File.txt | grep -io 'http://www.acme.com/a/files/.*.pdf'| uniq
cat /etc/named.conf | grep -Po '(?<=(named/)).*(?=\.db)'
2014-10-25 20:16:17
User: KonKar
Functions: cat grep
0

Allows you to have a list of the domains on the server.

cat /etc/httpd/logs/access.log | awk '{ print $6}' | sed -e 's/\[//' | awk -F'/' '{print $1}' | sort | uniq -c
2014-10-13 13:39:53
User: suyashjain
Functions: awk cat sed sort uniq
0

The command will read the apache log file and fetch the virtual host requested and the number of requests.

cat /usr/share/dict/words | egrep '^\w{13,}$' | egrep -iv '(\w).*\1'
2014-09-29 12:52:09
User: hackerb9
Functions: cat egrep
6

This is the most straightforward approach: first regexp limits dictionary file to words with thirteen or more characters, second regexp discards any words that have a letter repeated. (Bonus challenge: Try doing it in a single regexp!)

echo "DISK:";df -Pl | grep -v "Filesystem" | awk '{print $5,$6}' ; echo "MEM:" ; free -mto | awk '{ print $1,$2,$3,$4 }'; echo "CPU:"; top -b -d1 -n1 | grep Cpu | awk '{print $2,$3,$4,$5,$6,$7,$8,$9}';echo "LOAD:"; cat /proc/loadavg
2014-09-29 12:43:52
User: injez
Functions: awk cat df echo free grep top
0

Monitoring system in one line :

DISK : disk space

MEM: memory ( mem , swap, Total)

CPU : all information about cpu activity

LOAD : load average

cat /var/log/syslog | grep score= | awk '{print $15}' | more
w !sudo cat >%
cat h.txt| while read line; do curl -s -X POST 'https://www.virustotal.com/vtapi/v2/file/report' --form apikey="APIKEY" --form resource="$line"|awk -F'positives\":' '{print "VTHits"$2}'|awk -F' ' '{print $1" "$2$5$6}'|sed 's/["}]//g' && sleep 15; done
cat "log" | grep "text to grep" | awk '{print $1}' | sort -n | uniq -c | sort -rn | head -n 100
while true; do clear; cat /proc/[0-9]*/stat | cut -d' ' -f 3 | sort | uniq -c | awk '{print $2" "$1}'; echo '---'; sleep 1; done
$ wget --no-check-certificate -q checkip.dyndns.org -O index.html && cat index.html|cut -d ' ' -f 6 | cut -d '<' -f 1
2014-05-12 07:10:29
User: Superkikim
Functions: cat cut wget
0

This is the command line I use to get my IP address in order to update my zoneedit account. Full script on my blog http://akim.sissaoui.com/linux-attitude/script-de-mise-a-jour-ddns-zoneedit-com-en-bashsh/

cat ~/.ssh/id_rsa.pub | ssh deployer@xxxxx -p 52201 'cat >> ~/.ssh/authorized_keys'
for i in $(cat vulns.txt); do echo $i; rpm -qa ?changelog | grep -i $i; done
2014-04-30 16:11:14
User: sonny108
Functions: cat echo grep rpm
0

Found it online and could be very useful

cat dictionary.txt|while read a; do echo $a|cryptsetup luksOpen /dev/sda5 sda5 $a && echo KEY FOUND: $a; done
2014-04-16 18:49:53
User: rodolfoap
Functions: cat echo read
0

Lost your luks passphrase? You can always bruteforce from the command line. See the sample output, a simple command using a dictionary.

for i in {1..256};do p=" $i";echo -e "${p: -3} \\0$(($i/64*100+$i%64/8*10+$i%8))";done|cat -t|column -c120
2014-04-04 16:54:53
User: AskApache
Functions: cat column echo
6

Prints out an ascii chart using builtin bash! Then formats using cat -t and column.

The best part is:

echo -e "${p: -3} \\0$(( $i/64*100 + $i%64/8*10 + $i%8 ))";

From: http://www.askapache.com/linux/ascii-codes-and-reference.html

num_errs=`grep ERROR /var/log/syslog | tee >(cat >&2) | wc -l`
2014-03-12 00:04:24
Functions: cat tee wc
0

Many circumstances call for creating variable of a summary result while still printing the original pipe. Inserting "tee >(cat >&2)" allows the command output to still be printed while permitting the same output to be processed into a variable.

cat skype_log | sed -s 's/\(\[.*\]\) \(.*\): \(.*\)/<\2> \3/'
pdftk *.pdf cat output merged.pdf
2014-03-02 01:53:37
User: o0110o
Functions: cat
2

Merge Multiple PDFs In Alphabetical Order

cat /proc/cpuinfo | grep BogoMIPS | uniq | sed 's/^.*://g' | awk '{print($1 / 4) }'
cat cachedump.txt | awk -F : '{print $2":"$1}'
find . -name *.properties -exec /bin/echo {} \; -exec cat {} \; | grep -E 'listen|properties'
while true; do cat "file"; done | nc -v -l 1337
2014-02-06 03:02:58
User: bknk
Functions: cat
0

A TCP server that keeps the same socket open, sending the contents of "file" repeatedly.

cat /dev/urandom | env LC_CTYPE=C tr -dc a-zA-Z0-9 | head -c 16; echo
2014-02-05 15:04:07
User: yakovlev
Functions: cat env head tr
0

Feel free to put this in your ~/.profile:

random(){ cat /dev/urandom | env LC_CTYPE=C tr -dc $1 | head -c $2; echo; }

Then use it to generate passwords:

random [:alnum:] 16

Or DNA sequences:

random ACGT 256