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 by snipertyler from sorted by
Terminal - Commands by snipertyler - 28 results
csv2json() { for file in [email protected]; do python -c "import csv,json,fileinput; print(json.dumps(list(csv.reader(fileinput.input()))))" "$file" 1> "${file%%csv}json"; done; }
2017-06-28 04:28:32
User: snipertyler
Functions: file python
Tags: CSV python json

Based / Inspired by malathion's below command


Is written for python3 and is very easy to use

csv2json *csv will convert all files ending in csv to json

eg csv2json file.csv will output a file to file.json

Validity of json tested in python3 and below site


videospeed() { vname="$1"; speedc="$2"; vs=$(python3 -c "print(1/$speedc)"); aspeed=$(python3 -c "print(1*$speedc)"); ffmpeg -i "$vname" -filter:a "atempo=$aspeed" -filter:v "setpts=$vs*PTS" "${3:-converted_$1}"; }
2017-03-07 22:44:06
User: snipertyler


videospeed video_filename speedchange newfilename

videospeed foo.mp4 0.5 foo_slow.mp4

Range of 0.5 (50%) - 2.0 (200%) is valid.

lc() { od="$1"; nd="$2"; of=$3; nf=$4; cp -rl "$od" "$nd"; parallel -0 "ffmpeg -i {1} -loglevel error -q:a 6 {1.}.{2} && { rm {1}; echo {1.}.{2}; }" :::: <(find "$nd" -type f -iname \*$of -print0) ::: "$nf"; }
2017-03-02 17:37:34
User: snipertyler
Functions: cp find

Uses parallel processing

Reiteration of my earlier command



lc Old_Directory New_DIrectory Old_Format New_Format

lc ~/Music ~/Music_ogg mp3 ogg

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.

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

pyt() { youtube-dl -q -f bestaudio --max-downloads 1 --no-playlist --default-search ${2:-ytsearch} "$1" -o - | mplayer -vo null /dev/fd/3 3<&0 </dev/tty; }
2015-07-27 15:19:59
User: snipertyler

Same as other command, however uses youtube-dl internal search (thanks to qoxxxx mentioning this)

It does however seem to be a little buggy and youtube-dl crashes sometimes.


pyt 'Stairway to heaven - Led Zeppelin'

pyt 'brain damage - Pink Floyd'

No web browser or even X needed. Just a cli and internet connection!

mplayer is pauseable and can skip ahead

This may break if youtube changes their search html.

pyt() { id=$(curl -s 'https://www.youtube.com/results?search_query='$(tr ' ' + <<<"$1") | grep -om3 '"[[:alnum:]]\{11\}"' | awk NR==3 | tr -d \"); youtube-dl -q 'https://www.youtube.com/watch?v='"$id" -o - | mplayer -vo null /dev/fd/3 3<&0 </dev/tty; }
2015-07-20 05:30:27
User: snipertyler
Functions: awk grep tr

pyt 'Stairway to heaven - Led Zeppelin'

pyt 'brain damage - Pink Floyd'

No web browser or even X needed. Just a cli and internet connection!

mplayer is pauseable and can skip ahead

This may break if youtube changes their search html.

ran() { R=$((RANDOM%100)); if [ $R -gt "${1:-50}" ]; then echo FALSE; false; else echo TRUE; true; fi; }
2015-07-15 15:34:56
User: snipertyler
Functions: echo

Command will succeed n% of the time.

ran 75 will cause command to succeed 75% of the time.

No argument will cause it to succeed 50% of the time.

pvl() { (for i in "[email protected]"; do youtube-dl -q --max-downloads 1 --no-playlist "$i" -o - | mplayer -vo null /dev/fd/3 3<&0 </dev/tty; sleep .5; done); }
2015-07-14 04:44:36
User: snipertyler
Functions: sleep

pvl 'link1' 'link2' 'link3'

Play Youtube, Vimeo, etc links without visual elements.

Great for music videos when you just want the audio.

You can control mplayer with this!

Hit Ctrl-C twice to exit (if you're playing multiple files)

syt() { pipe=`mktemp -u`; mkfifo -m 600 "$pipe" && for i in "[email protected]"; 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

ssh hostname nc -l 9876
if [ "${SSH_CLIENT%% *}" == "ipaddr" ]; then command; fi
2015-01-13 22:09:38
User: snipertyler
Tags: ssh

Place in ~/.bashrc

If you login to a ssh server from different ips, sometimes you want to do something specific for each.

e.g., quickly go into screen -x session from a phone, but not your desktop.

2014-12-28 22:00:15
User: snipertyler

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.

cd -P .
mkfifo /tmp/view; nc -l 9876 < /tmp/view& script -f /tmp/view
2014-06-23 05:06:13
User: snipertyler
Functions: mkfifo script
Tags: Network nc fifo

connect to it with any network command (including web browser - if you don't mind weird formatting)


nc 9876

curl 'LINK' | pdftotext - - | less
2014-06-21 00:47:02
User: snipertyler
Tags: less pdf convert

Probably will not work very well with scanned documents.

ncat -vlm 5 --ssl --chat 9876
2014-06-07 19:17:29
User: snipertyler

Client ~$ ncat --ssl localhost 9876

Change localhost to the correct ip address.

stat -c '%n %U:%G-%a' *
2014-05-03 04:56:23
User: snipertyler
Functions: stat
Tags: permissions


alias perm="stat -c '%n %U:%G-%a'"


perm() { for ll in [email protected]; do stat -c "%n %U:%G-%a" "$ll"; done; }

ffmpeg -i file.ext -acodec copy -vn out.ext
2014-04-25 14:24:57
User: snipertyler
Tags: ffmpeg

This removes the video and subsequent file size and directly copies the audio.

tar -cf - file1 dir1/ dir2/ | md5sum
2014-04-17 14:33:44
User: snipertyler
Functions: tar

Doesn't create a file

Make sure to list the files / directories in the same order every time.

curl 'AudioStream' | ffmpeg -i - -acodec libvorbis file.ogg
2014-03-31 02:07:20
User: snipertyler

This encodes it in ogg format.

Does on-the-fly encoding of the incoming stream.

Great for radio streams as they're often flv format.

edrv() { N=${1:-edrv}; truncate -s ${2:-256m} $N.img && L=$(losetup -f) && losetup $L $N.img && cryptsetup luksFormat --batch-mode $L && cryptsetup luksOpen $L $N && mkfs.vfat /dev/mapper/$N -n $N; cryptsetup luksClose $N; echo losetup -d $L to unmount; }
2014-02-24 01:38:21
User: snipertyler
Functions: echo losetup

You need to be root to do this. So check the command before running it.

You enter the same password for

Enter LUKS passphrase:

Verify passphrase:

Enter passphrase for /dev/loopn:


You can then copy the .img file to somewhere else.

Loop it it with losetup -f IMAGENAME.img and then mount it with a file manager (eg nemo) or run mount /dev/loopn /media/mountfolder

Acts similar to a mounted flash drive

ram() { mt=/mnt/ram && grep "$mt" < /proc/mts > /dev/null; if [ $? -eq 0 ] ; then read -p"Enter to Remove Ram Partition ";sudo umount "$mt" && echo $mt 0; else sudo mt -t tmpfs tmpfs "$mt" -o size=$(( ${1:-1} * 1024 ))m && echo $mt '-' "${1:-1}"gb; fi; }
2013-12-13 05:22:02
User: snipertyler
Functions: echo grep mt read sudo umount
Tags: sudo ram tmpfs

Creates a temporary ram partition

To use:

ram 3

to make a 3gb partition (Defaults to 1gb)

nc HOST PORT | tee movie.mp4 | mplayer -
2013-11-28 01:38:29
User: snipertyler
Functions: tee

Requires a listening port on HOST

eg. "cat movie.mp4 | nc -l 1356 " (cat movie.mp4 | nc -l PORT)

Useful if you're impatient and want to watch a movie immediately and download it at the same time without using extra bandwidth.

You can't seek (it'll crash and kill the stream) but you can pause it.

t2s() { wget -q -U Mozilla -O $(tr ' ' _ <<< "$1"| cut -b 1-15).mp3 "http://translate.google.com/translate_tts?ie=UTF-8&tl=en&q=$(tr ' ' + <<< "$1")"; }
2013-10-16 23:29:59
User: snipertyler
Functions: cut tr wget

Usage: t2s 'How are you?'

Nice because it automatically names the mp3 file up to 15 characters

Modified (uses bash manip instead of tr)

t2s() { wget -q -U Mozilla -O $(cut -b 1-15