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,130 results
nohist(){ export HISTFILE=/dev/null; }
2014-12-31 22:30:08
Functions: export
0

Yo run the `nohist` command and after that the commands won't get stored in the history file for the current session.

This makes no permanent changes.

psg(){ ps aux | grep -v grep | egrep -e "$1|USER"; }
2014-12-31 22:27:27
Functions: egrep grep ps
Tags: grep function ps
-1

Function that searchs a process by its name and shows in the terminal.

* Shows the Header for reference

* Hides the process 'grep' from the list

* Case sensitive

<ctrl>+o
2014-12-28 22:00:15
User: snipertyler
7

Similar to entering a command, but will not erase the command from the command line.

Basically a shortcut from entering command, then pushing the up arrow key.

printf "%s\t%s\t%s\n" {1..9} '*' 0 '#'
2014-12-27 11:27:24
User: flatcap
Functions: printf
Tags: printf
3

Draw a telephone keyboard, using just a shell built-in command.

echo {1..9} '* 0 #' | tr ' ' '\n' |paste - - -
nmap -sP 10.0.0.0/8 | grep -v "Host" | tail -n +3 | tr '\n' ' ' | sed 's|Nmap|\nNmap|g' | grep "MAC Address" | cut -d " " -f5,8-15
2014-12-26 18:31:53
User: jaimerosario
Functions: cut grep sed tail tr
0

In the field, I needed to script a process to scan a specific vendor devices in the network. With the help of nmap, I got all the devices of that particular vendor, and started a scripted netcat session to download configuration files from a tftp server.

This is the nmap loop (part of the script). You can however, add another pipe with grep to filter the vendor/manufacturer devices only. If want to check the whole script, check in http://pastebin.com/ju7h4Xf4

tail -f access_log | awk '{print $1 , $12}'
2014-12-24 14:15:52
User: tyzbit
Functions: awk tail
0

Use this command to watch apache access logs in real time to see what pages are getting hit.

find . -name '*.php' | xargs wc -l
2014-12-24 11:15:18
User: erez83
Functions: find wc xargs
Tags: count code
0

count all the lines of code in specific directory recursively

in this case only *.php

can be *.*

wget blah --progress=dot -e dotbytes=100M
grep -E -rn --color=always --exclude-dir=".svn" --exclude-dir="packages" --exclude="*.swp" "(emit|on)\([\'\"]leader" ~/project/ | less -R
2014-12-23 20:08:25
User: hochmeister
Functions: grep less
0

grep for specific function invocations in this case, wither "emit" or "on" with "leader".

FILE=somefile.js; LOG=~/changes.diff; truncate -s0 ${LOG}; for change in $(svn log ${FILE} | awk -F' | ' '/^r[0-9]+/{print $1}'); do svn log -c ${change} >> ${LOG}; printf "\n" >> ${LOG}; svn diff -c ${change} >> ${LOG}; printf "\n\n\n" >> ${LOG}; done
2014-12-23 20:00:54
User: hochmeister
Functions: awk diff printf
Tags: svn diff log
0

from a svn repo, print a log, with diff, of each commit touching a given file

awk '{ total += gsub(/yourstring/,"") } END { print total }' yourfile
2014-12-16 21:00:45
User: bugmenot
Functions: awk
0

Count how many times a pattern is present into a file. It can be one or more lines. No overlapping. It means searching for aa on aaa will output 1 not 2.

echo something | awk '{ total += gsub(/yourstring/,"") } END { print total }'
2014-12-16 20:58:42
User: bugmenot
Functions: awk echo
0

Count how many times a pattern is present into a stream. It can be one or more lines. No overlapping. It means searching for aa on aaa will output 1 not 2.

cd -P .
curl -s "http://smacie.com/randomizer/borat.txt" | shuf -n 1 -
2014-12-16 04:18:48
User: benjabean1
2

Turns out smacie.com has a text file containing every single one of the borat quotes, each one on a newline. This makes it very convenient, as this can be done without any sed-parsing, and uses less bandwitdth!

Note that borate quotes are quite offensive, much more so than "fortunes-off"!

ls -l | head -n 65535 | awk '{if (NR > 1) total += $5} END {print total/(1024*1024*1024)}'
rsync -v --ignore-existing `ls | head -n 40` root@localhost:/location
scp -r `ls | grep -vE "(Pattern1|Pattern2)"` user@remote_host:/location
apt-cache pkgnames linux-
2014-12-14 06:48:57
User: benjabean1
Functions: apt
1

In this case, linux- is the prefix; simply running

apt-cache pkgnames

would list every package APT knows about.

The default APT config assumes -g, --generate; to use the cache as/is, you could similarly run:

apt-cache --no-generate pkgnames [prefix]

Adding --all-names, like so:

apt-cache --no-generate --all-names pkgnames [prefix]

would print all the packages APT knows about, using the cache as/is, including virtual packages and missing dependencies.

This command was shamelessly stolen from the apt-cache(8) man-page.

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.

strings /dev/urandom | tr -cd '[:alnum:]' | fold -w 30 | head -n 1
2014-12-11 06:21:51
User: atoponce
Functions: fold head strings tr
2

This command is similar to the alternate, except with head(1), you can pick as many passwords as you wish to generate by changing the number of lines you wish to preview.

ps axo pcpu,args | awk '/[p]hp.*pool/ { sums[$4] += $1 } END { for (pool in sums) { print sums[pool], pool } }' | sort -rn | column -t
find . -printf '%.5m %10M %#9u %-9g %TY-%Tm-%Td+%Tr [%Y] %s %p\n'|sort -nrk8|head
rpm -e --allmatches gpg-pubkey-1aa043b8-53b2e946
2014-12-09 21:27:08
User: krizzo
Functions: rpm
Tags: GPG rpm yum pubkey
0

This will remove the gpg-pubkey-1aa043b8-53b2e946 from rpm/yum and you'll be prompted to add it back from the given repo.

rpm -qa gpg-pubkey --qf "%{version}-%{release} %{summary}\n"
2014-12-09 21:23:28
User: krizzo
Functions: rpm
Tags: GPG rpm yum pubkey
0

This will list all the gpg keys that were accepted and installed for yum.