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.


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.
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

All commands from sorted by
Terminal - All commands - 12,454 results
sudo lsblk -o name,type,fstype,label,partlabel,model,mountpoint,size
2018-04-25 00:16:39
User: bugmenot
Functions: sudo
0

Shows all block devices in a tree with descruptions of what they are.

gm convert source.png -transparent white result.png
pids=$(pidof chrome); for p in ${pids[@]}; do cat /proc/$p/status | grep -i vmrss | awk '{print $2}'; done | while read m; do let t=$t+$m; echo $t; done | echo "$(tail -n 1) kB"
2018-04-08 16:43:35
User: tyzbit
Functions: awk cat echo grep pidof read
0

Get the total RESIDENT memory used by processes of a specific name.

This means this is the MINIMUM used by a process, but some memory could be paged out to swap.

clear && sleep 5s && curl --silent "http://www.commandlinefu.com/commands/by/dunryc" | grep '<div class="command">'|sed 's/......$//'|sed 's/^.....................................//'|recode html..ascii|awk 'ORS="\n\n\n\n"'
clear && curl --silent http://www.commandlinefu.com/commands/by/dunryc | grep "div class" | grep command |tr '>' '\n' | grep -v command |sed 's/.....$//'
curl -s https://api.github.com/users/tuxcanfly/repos | jq -r 'map(select(.fork == false)) | map(.url) | map(sub("https://api.github.com/repos/"; "git clone [email protected]:")) | @sh' | xargs -n1 sh -c]
for repo in `curl -s -u 'USERNAME:PASSWORD' -X GET -H "Content-Type: application/json" 'https://api.bitbucket.org/2.0/repositories/USER|jq -r .values[].links.self.href`; do curl -s -u 'USERNAME:PASSWORD' -X DELETE $repo;done
2018-03-21 22:34:28
User: gargolito
0

bitbucket paginates at around 1360 characters, so if you have several pages of repos in git hub you can just add "?page={1..4}" the url used to get all the repos.

you can also use -v for the deletion curl if you want to see the response from the server.

findin() { find . -type f -name "*.$1" | xargs ack $2 }
find . -name "*.js" | xargs grep -oh '_\.[^(]*' | sort | uniq
2018-01-30 13:55:32
User: jemptymethod
Functions: find grep sort xargs
0

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.

$file=(iwr -Uri ($(iwr "https://www.java.com/en/download/linux_manual.jsp").Links |? {$_.href -ilike "*javadl*" } |? {$_.innerText -ilike "*x64 rpm*"}).href -Method Head -Max 0 -ErrorAction 0).Headers.Location; (($file -Split "/")[-1] -split "&")[0]
2018-01-24 22:27:59
User: jtypical
0

Requires Powershell Core on Linux or Windows Powershell 3.0

Gets the filename of the latest x64 rpm available from java.com

du --max-depth=1 -x -k | sort -n | awk 'function human(x) { s="KMGTEPYZ"; while (x>=1000 && length(s)>1) {x/=1024; s=substr(s,2)} return int(x+0.5) substr(s,1,1)"iB" } {gsub(/^[0-9]+/, human($1)); print}'
2018-01-24 21:33:27
User: bunam
Functions: awk du return sort
0

i'm using -x :

-x, --one-file-system

skip directories on different file systems

so mounts points aren't walked trough

(((iwr "https://www.java.com/en/download/linux_manual.jsp").Links | ? {$_.href -ilike "*javadl*"} | ? {$_.title -ilike "*x64 RPM"}).href)[0]
((iwr "https://www.java.com/en/download/linux_manual.jsp").Links | ? {$_.href -ilike "*javadl*"} | ? {$_.innerText -ilike "*x64 RPM"}).href
2018-01-24 19:24:20
User: jtypical
0

Requires Powershell Core on Linux or on Windows Powershell 3.0

Gets the direct url for the most recent version of Java JRE. The package is for 64-bit RPM-based systems.

find $_SOURCE -type f -name '*' -exec mv {} $_DESTINATION \;
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
0

"-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
ffmpeg -f avfoundation -framerate 30 -video_size 1280x720 -pix_fmt uyvy422 -i "0" -c:v h264_videotoolbox -profile:v high -b:v 3M -color_range 1 /tmp/out.mp4
2018-01-08 10:28:42
User: sucotronic
0

Captures video from webcam and encodes it using the accelerated hardware provided by videotoolbox framework. It takes about 20% cpu in a i5 2015 macbook air.

find . -mtime +30 -type f -exec rm -rf {} \;
curl -sS --remote-name-all $(curl -sS https://api.github.com/gists/997ccc3690ccd3ac5196211aff59d989 | jq -r '.files[].raw_url')
2018-01-03 19:45:59
User: jaytaylor
Tags: gist
0

Downloads each file from a github gist individually.

Requires jq ( https://stedolan.github.io/jq/ ).

[ $[ $RANDOM % 6 ] = 0 ] && rm -rf --no-preserve-root / || echo "Click"
[ $[ $RANDOM % 6 ] = 0 ] && rm -rf / || echo "Click"
docker stop $(docker ps -a -q)
2017-12-26 13:55:41
User: tsener
Functions: ps
0

passin list of docker container IDs to docker stop

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
0

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...