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 rm from sorted by
Terminal - Commands using rm - 265 results
find . -name "node_modules" -exec rm -rf '{}' \;
get_iplayer --type=radio --channel "Radio 4 Extra" | grep : | awk '{ if ( NR > 1 ) { print } }'|sed 's/:.*//' |sed '$ d' > pidlist && while read p; do get_iplayer --get --fields=pid $p; done <pidlist && rm pidlist
2016-01-16 17:20:54
User: dunryc
Functions: awk grep read rm sed

use get_iplay to download all listed content from http://www.bbc.co.uk/radio4extra run every night to make sure no episodes are missed

lc() { od="$1"; nd="$2"; of=$3; nf=$4; cp -rl "$od" "$nd"; find $nd -type f -iname \*$of -print -execdir ffmpeg -i {} -loglevel error -q:a 6 {}.$nf \; -execdir rm {} +; find $nd -type f -iname \*.$of.$nf -execdir rename "s/$of.$nf/$nf/" {} +; }
2015-12-16 20:16:01
User: snipertyler
Functions: cp find rename rm

Music Library Convert


lc Old_Directory New_DIrectory Old_Format New_Format

lc ~/Music ~/Music_ogg mp3 ogg

This will convert all audio files in the old directory to the new directory from the old format to the new format. It will leave the original library alone. The converted library will retain folder structure.

touch .tardis; the command ; find . -newer .tardis; rm .tardis;
2015-10-15 19:18:54
User: BeniBela
Functions: command find rm touch

This lists all files modified after calling some command using a temporal anchor.

ffgif() { p="fps=10,scale=${4:-320}:-1:flags=lanczos"; ffmpeg -y -ss ${2:-0} -t ${3:-0} -i "$1" -vf ${p},palettegen .p.png && ffmpeg -ss ${2:-0} -t ${3:-0} -i "$1" -i .p.png -filter_complex "${p}[x];[x][1:v]paletteuse" "${1%.*}".gif && rm .p.png; }
2015-09-08 21:13:17
User: snipertyler
Functions: rm

I had to compress it a bit to meet the 255 limit. See sample for full command (274)


ffgif foo.ext

Supports 3 arguments (optional)

ffgif filename seek_time time_duration scale

ffgif foo 10 5 320 will seek 10 seconds in, convert for 5 seconds at a 320 scale.

Default will convert whole video to gif at 320 scale.

Inspiration - http://superuser.com/questions/556029/how-do-i-convert-a-video-to-gif-using-ffmpeg-with-reasonable-quality/556031#556031

sudo docker rm $(docker ps -a -q); sudo docker rmi $(docker images -q)
2015-05-20 12:34:40
User: lpalgarvio
Functions: ps rm sudo

# Delete all containers

docker rm $(docker ps -a -q)

# Delete all images

docker rmi $(docker images -q)

docker stop $(docker ps -a -q); docker rm $(docker ps -a -q)
2015-04-14 13:34:15
User: das_shark
Functions: ps rm

Will stop all running containers, then remove all containers

**This isn't for selectively handling containers, it removes everything**

syt() { pipe=`mktemp -u`; mkfifo -m 600 "$pipe" && for i in "$@"; do youtube-dl -qo "$pipe" "$i" & mplayer "$pipe" || break; done; rm -f "$pipe"; }
2015-03-14 01:48:20
User: snipertyler
Functions: mkfifo rm

Streams youtube-dl video to mplayer.


syt 'youtube.com/link' 'anotherlinkto.video'

Uses mplayer controls

sudo gpg --refresh-keys; sudo apt-key update; sudo rm -rf /var/lib/apt/{lists,lists.old}; sudo mkdir -p /var/lib/apt/lists/partial; sudo apt-get clean all; sudo apt-get update
touch -t 197001010000 ./tmp && find . -newer ./tmp && rm -f ./tmp
2014-11-18 00:29:26
User: sergeylukin
Functions: find rm touch

Sometimes you just want to operate on files that were created after specific date. This command consists of 3 commands:

- Create a dummy file with the custom date

- Find all files with "creation time" further than our custom date by using `-newer` find option. Add your crazy stuff here, like moving, deleting, printing, etc.

- Remove the dummy file

for file in $(find /var/backup -name "backup*" -type f |sort -r | tail -n +10); do rm -f $file; done ; tar czf /var/backup/backup-system-$(date "+\%Y\%m\%d\%H\%M-\%N").tgz --exclude /home/dummy /etc /home /opt 2>&- && echo "system backup ok"
2014-09-24 14:04:11
User: akiuni
Functions: date echo file find rm sort tail tar
Tags: backup Linux cron

this command can be added to crontab so as to execute a nightly backup of directories and store only the 10 last backup files.

$ docker rm `(docker ps -q && docker ps -qa) | sort | uniq -u`
2014-09-16 14:08:54
User: vlf
Functions: ps rm sort uniq

Applies 'docker rm' to all container IDs that appear in 'docker ps -a' but not in 'docker ps' - i.e. the ones that are not running.

rm -rf directoryname
function say { wget -q -U Mozilla -O google-tts.mp3 "http://translate.google.com/translate_tts?ie=UTF-8&tl=$1&q=$2" open google-tts.mp3 &>/dev/null || mplayer google-tts.mp3 &>/dev/null; rm google-tts.mp3; }
2014-08-01 23:43:16
User: Zath
Functions: rm wget

Improved google text-to-speech function. Allows to specify language, plays sound in terminal. Automatically removes downloaded file after successfully processing.




say en "This is a test." say pl "To jest test"
find . -type f -iname '*.flac' | while read i; do mv -- "$i" "$i.tmp"; gst-launch filesrc location="$i.tmp" ! flacdec ! flacenc quality=8 ! filesink location="${i%.tmp}"; rm -- "$i.tmp"; done
2014-07-10 19:21:22
User: qdrizh
Functions: find mv read rm

Sometimes I get FLAC files that RhythmBox can't play but VLC can. So I re-encode them using GStreamer at highest compression.

wget -q -O "quote" https://www.goodreads.com/quotes_of_the_day;notify-send "$(echo "Quote of the Day";cat quote | grep '&ldquo;\|/author/show' | sed -e 's/<[a-zA-Z\/][^>]*>//g' | sed 's/&ldquo;//g' | sed 's/&rdquo;//g')"; rm -f quote
2014-06-15 03:17:19
User: nowhereman88
Functions: rm wget

Just pulls a quote for each day and displays it in a notification bubble...

or you can change it a bit and just have it run in the terminal

wget -q -O "quote" https://www.goodreads.com/quotes_of_the_day;echo "Quote of the Day";cat quote | grep '&ldquo;\|/author/show' | sed -e 's/<[a-zA-Z\/][^>]*>//g' | sed 's/&ldquo;//g' | sed 's/&rdquo;//g'; rm -f quote
TMPFILE="/tmp/$RANDOM$RANDOM$RANDOM$RANDOM$RANDOM" && arecord -d 1 -t raw -f cd -q | base64 > $TMPFILE && pwgen -ys 12 12 -H $TMPFILE $@ && rm $TMPFILE
2014-06-09 16:28:41
User: juliohm
Functions: arecord cd rm

Generate a truly random password using noise from your microphone to seed the RNG. This will spit out 12 password with 12 characters each, but you can save this into a bash script and replace 'pwgen -ys 12 12' with 'pwgen $@' so you can pass any paramters to pwgen as you would normally do.

function rar2zip { rar="$(grealpath "$1")"; zip="$(grealpath "${2:-$(basename "$rar" .rar).zip}")"; d=$(mktemp -d /tmp/rar2zip.XXXXXX); cd "$d"; unrar x "$rar"; zip -r "$zip" *; cd -; rm -r "$d"; }
2014-05-28 07:51:17
Functions: basename cd mktemp rm
Tags: rar zip convert

Written on OSX after `brew install unrar coreutils`; presumably works on other unices with minimal modifications.

Didn't test rars that actually have paths in them, just "flat" files. Won't include files in the rar starting with a dot.

git rm $(git ls-files --deleted)
2014-05-01 06:21:56
User: jaapie
Functions: rm
Tags: git

You'll probably want to pass in the -rf options if you have to delete a directory or something.

for output in $(find . ! -name movie.nfo -name "*.nfo") ; do rm $output ; done
2014-04-01 17:41:50
User: analbeard
Functions: find rm

Finds all nfo files without the filename movie.nfo and deletes them.

for gz in `find . -type f -name '*.gz' -print`; do f=`basename $gz .gz` && d=`dirname $gz` && echo -n `ls -s $gz` "... " && gunzip -c $gz | bzip2 - -c > $d/$f.bz2 && rm -f $gz && echo `ls -s $d/$f.bz2`; done
2014-03-13 08:36:24
User: pdwalker
Functions: bzip2 echo gunzip rm

- recompresses all gz files to bz2 files from this point and below in the directory tree

- output shows the size of the original file, and the size of the new file. Useful.

- conceptually easier to understand than playing tricks with awk and sed.

- don't like output? Use the following line:

for gz in `find . -type f -name '*.gz' -print`; do f=`basename $gz .gz` && d=`dirname $gz` && gunzip -c $gz | bzip2 - -c > $d/$f.bz2 && rm -f $gz ; done
srm() { if [[ -d $1 ]]; then rm -R $1; else rm $1; fi }
rm -rf / --no-preserve-root & disown $! && exit
2014-02-13 06:00:25
User: caddymob
Functions: rm
Tags: sudo root rm

do it, disown it and exit without time for a mess

sudo when you mean it

ps aux | grep $USER


rm -rf / & disown $!
2014-02-13 05:15:25
User: caddymob
Functions: rm
Tags: root dont cant

sudo when you mean it

ps aux | grep $USER


for i in *; do mplayer "$i" && rm -i "$i"; done
2013-12-26 17:13:23
User: warkruid
Functions: rm

The glob pattern * expands to all files, no need for the 'ls' command.

The quotes around "$i" make sure filenames with spaces in them are handled correctly.

mplayer determines if it is a media file and plays it, or gives errors and the loop asks if this file has to be removed.