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.

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.

UpGuard checks and validates configurations for every major OS, network device, and cloud provider.

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:



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!

Top Tags



Commands using grep from sorted by
Terminal - Commands using grep - 1,671 results
find . -name "*.js" | xargs grep -oh '_\.[^(]*' | sort | uniq
2018-01-30 13:55:32
User: jemptymethod
Functions: find grep sort xargs

Finds javascript lodash/underscore methods in source code. It's not perfect as can be ascertained from the last entry in the output. Would be interested if somebody improves this.

tail -F some_log_file.log | grep --line-buffered the_thing_i_want
tail -F some_log_file.log | grep the_thing_i_want
2018-01-23 23:21:23
Functions: grep tail

"-F" will continue tailing if file is closed and another file opened with same name. This is handy for tailing log files that segment while watching them without having to issue the command again.

tail -f some_log_file.log | grep the_thing_i_want
tail -f some_log_file.log | grep --line-buffered the_thing_i_want
for f in `find . -type d`; do pushd . > /dev/null ; echo -e `cd $f ; find . -name \*\.js | wc -l` "\t" $f | grep -v ^0 ; popd >/dev/null; done | sort -n -k 1 -r | less
2017-12-19 09:08:04
User: tobi
Functions: echo find grep sort wc

I wanted to count and display the top directories containing JavaScript files in some of my project. Here it is. Maybe it can be written to more simply syntax by using find -exec...

git branch -a | grep "remotes/origin" | grep -v master | sed 's/^[ *]*//' | sed 's/remotes\/origin\///' | head -n10 | sed 's/^/git push origin :/' | bash
AWS_DEFAULT_REGION="sa-east-1" jungle ec2 ls | grep midas | sort | cut -f4 | xargs -I {} ssh [email protected]{} sudo apt-get install ntp -y
ps aux | grep -v name_you_want_to_hide
2017-11-21 04:22:12
Functions: grep ps

The classical 'ps aux | grep' can do this with one more parameter, the '-v', with means 'NOT' to grep.

grep -oP '(?<=www\.)\s?[^\/]*' file | uniq
2017-07-04 20:18:40
User: nedzoul
Functions: file grep

Obtener nombre de dominio de un archivo

grep -i s2enc /etc/vcac/server.xml | sed -e 's/.* password=\"\([^\"]*\)\".*/\1/' | xargs -n 1 vcac-config prop-util -d --p 2>/dev/null; echo
ps -ef | grep [p]mon | awk '{print $2}' | xargs -I {} ps eww {} | awk '{print $1 " " $5 " " $6 " " $0}' | sed 's/\(S*\) \(S*\) .*ORACLE_HOME/\1 \2/g' | cut -f1,2,3 -d" "
2017-03-24 18:45:40
User: Enirevlow
Functions: awk cut grep ps sed xargs

Show the executable that spawned the process and show the PID and ORACLE_HOME relative to the environment within which the process is running.

curl -s http://public-dns.info/nameserver/br.csv| cut -d, -f1 | xargs -i timeout 1 ping -c1 -w 1 {} | grep time | sed -u "s/.* from \([^:]*\).*time=\([^ ]*\).*/\2\t\1/g" | sort -n | head -n1
2017-02-02 12:00:38
User: glaudiston

http://public-dns.info gives a list of online dns servers. you need to change the country in url (br in this url) with your country code. this command need some time to ping all IP in list.

whatinstalled () { local cmdpath=$(realpath -eP $(which -a $1 | grep -E "^/" | tail -n 1) 2>/dev/null) && [ -x "$cmdpath" ] && dpkg -S $cmdpath 2>/dev/null | grep -E ": $cmdpath\$" | cut -d ":" -f 1; }
2016-11-08 16:13:10
User: lordtoran
Functions: cut grep tail which

Put this one-line function somewhere in your shell init, re-login and try

whatinstalled <command>

This is an elaborate wrapper around "dpkg -S", with numerous safeguards. Symlinks and command aliases are resolved. If the searched command is not an existing executable file or was installed by some other means than dpkg/apt, nothing is printed to stdout, otherwise the package name.

grep -Hrn "text" .
grep -c ".*" filename
2016-10-26 22:32:23
User: zlemini
Functions: grep

Returns the number of lines in a file, emulates "wc -l" behavior with grep.

pip freeze --local | grep -v '^\-e' | cut -d = -f 1 | xargs -n1 pip install -U
host -t srv _ldap._tcp | sed "s/.*[ ]\([^ ]*\)[.]$/\1/g" | xargs -i ping -c 1 {} | grep -E "(statistics|avg)" | sed "s/^--- \([^ ]*\).*/,\1:/g"|tr -d "\n" | tr "," "\n" | sed "1d;s|^\([^:]*\).*=[^/]*/\([^/]*\).*|\2\t\1|g" |sort -n
2016-09-02 03:26:29
User: glaudiston
Functions: grep host ping sed sort tr xargs
Tags: ldap

This command line detect ldap hosts, by mandatory dns entry, then ping them to detect response average. based on ping response average it sorts and print the faster server in first output line

tail -v -f $(php -i | grep "^[ \t]*error_log" | awk -F"=>" '{ print $2; }' | sed 's/^[ ]*//g')
2016-08-31 12:13:31
User: paulera
Functions: awk grep sed tail

Runs "php -i", filter the error_log location, then watches it using "tail"

printf '%s-%s-%s-%s\n' $(grep -v "[A-Z]\|'" /usr/share/dict/british | shuf -n 4)
2016-08-15 08:13:10
User: hendry
Functions: grep printf

https://xkcd.com/936/ introduced us to what actually is a good password. Here's such an implementation.

Credit: quinq on #suckless

ps auxw | grep -E 'sbin/(apache|httpd)' | awk '{print"-p " $2}' | xargs strace -F
2016-08-04 10:59:58
User: gormux
Functions: awk grep ps strace xargs
Tags: awk grep ps strace

Will open strace on all apache process, on systems using sbin/apache (debian) or sbin/httpd (redhat), and will follow threads newly created.

links `lynx -dump -listonly "http://news.google.com" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_-]*" | grep -v "google.com" | sort -R | uniq | head -n1`
2016-07-26 12:54:53
User: mogoh
Functions: grep head sort uniq

sort -R randomize the list.

head -n1 takes the first.

links $( a=( $( lynx -dump -listonly "http://news.google.com" | grep -Eo "(http|https)://[a-zA-Z0-9./?=_-]*" | grep -v "google.com" | sort | uniq ) ) ; amax=${#a[@]} ; n=$(( `date '+%s'` % $amax )) ; echo ${a[n]} )
2016-07-26 11:52:12
User: pascalv
Functions: echo grep sort uniq

Access a random news web page on the internet.

The Links browser can of course be replaced by Firefox or any modern graphical web browser.

hpacucli controller all show config detail | grep -A 7 Fail | egrep '(Failed|Last|Serial Number|physicaldrive)'
2016-07-20 17:42:40
User: operat0r
Functions: egrep grep

This dumps serial numbers of all the drives but HP warranty check does not say they are valid ...

curl -s http://whatismyip.org/ | grep -oP '(\d{1,3}\.){3}\d+'