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.

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

Psst. Open beta.

Wow, didn't really expect you to read this far down. The latest iteration of the site is in open beta. It's a gentle open beta-- not in prime-time just yet. It's being hosted over at UpGuard (link) and you are more than welcome to give it a shot. Couple things:

  • » The open beta is running a copy of the database that will not carry over to the final version. Don't post anything you don't mind losing.
  • » If you wish to use your user account, you will probably need to reset your password.
Your feedback is appreciated via the form on the beta page. Thanks! -Jon & CLFU Team

All commands from sorted by
Terminal - All commands - 12,407 results
python -c "import csv,json;print json.dumps(list(csv.reader(open('csv_file.csv'))))"
2017-05-17 19:35:53
User: malathion
Functions: python
Tags: CSV python json
0

Replace 'csv_file.csv' with your filename.

ps aux | awk '{if ($8 ~ "D") print $0}'
find / -type d | while read i; do ls $i | wc -l | tr -d \\n; echo " -> $i"; done | sort -n
2017-05-12 00:02:43
User: Zort
Functions: echo find ls read sort tr wc
0

Show file count into directories.

Usefull when you try to find hugh directories that elevate system CPU (vmstat -> sy)

ffmpeg -i input.flv -vf scale=320:-1 -r 10 -f image2pipe -vcodec ppm - | convert -delay 5 -loop 0 - output.gif
2017-05-04 16:28:48
User: hadifarnoud
0

you can use any common video format. if you don't need to change the size of gif output, just remove `-vf scale=320:-1`

btw, 320:-1 means width is 320px and height would be set automatically

sudo systemctl mask sleep.target suspend.target hibernate.target hybrid-sleep.target
2017-04-28 19:49:36
User: symgryph
Functions: sudo
0

This causes computer to never power off or go into sleep mode. Disables sleep mode linux.

pmset -g batt | awk '/^ /{print $5}'
printf "%x\n" $(seq 0 255) | xargs -n1 -IH echo -ne \\xH > test.dat
youtube-dl --list-formats <URL>; youtube-dl -f <STREAM_ID> -g <URL>
exec 0</dev/tty
2017-04-12 21:23:40
User: pdxdoughnut
Functions: exec
1

This will grab the controlling tty regardless of what STDOUT and STDERR are doing.

[ ! -t 0 ] && [ -t 1 ] && exec 0<&1
2017-04-12 00:10:27
User: pdxdoughnut
Functions: exec
0

Tests to see if stdin (0) is NOT a terminal.

Tests to see if stdout (1) IS a terminal.

Copies stdout (opened for write) to stdin (open for read).

soxi -D * | awk '{SUM += $1} END { printf "%d:%d:%d\n",SUM/3600,SUM%3600/60,SUM%60}'
function cdb() { select dir in $(find -type d -name "$1" -not -path '*/\.*' -prune); do cd "${dir}" && break; done }
sudo security delete-certificate -c 1000-sans.badssl.com
2017-04-06 01:40:04
User: lgarron
Functions: sudo
0

Use `security list-keychains` to find possible keychains, and `security dump-keychain` to look for certificates.

`sudo security delete-certificate` without arguments shows options for removing: by common name or by SHA-1 hash.

This is especially useful if a certificate locks up Keychain Access.app, which happens for certificates with many SANs in macOS 10.12.

Found via: http://stackoverflow.com/a/16019443

cat externs.json | jq ".efExports | .[] | (keys|.[0]) as \$kind | {kind:\$kind,value:(.[\$kind] |.Ident?)}"
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
0

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

sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }
2017-03-21 23:31:25
User: pdxdoughnut
Functions: echo printf
2

Converts any number of seconds into days, hours, minutes and seconds.

sec2dhms() {

declare -i SS="$1"

D=$(( SS / 86400 ))

H=$(( SS % 86400 / 3600 ))

M=$(( SS % 3600 / 60 ))

S=$(( SS % 60 ))

[ "$D" -gt 0 ] && echo -n "${D}:"

[ "$H" -gt 0 ] && printf "%02g:" "$H"

printf "%02g:%02g\n" "$M" "$S"

}

shebang () { printf '%s\n' 0a '#!'"$1" . w | ed -s "$2" ; }
2017-03-20 19:14:41
User: zlemini
Functions: ed printf
1

Function to add a shebang to an existing script, handy if you forgot to add it in the first place.

find . -type f ! -path "./.git/*" -exec sh -c "head -n 1 {} | egrep -a 'bin/bash|bin/sh' >/dev/null" \; -print -exec shellcheck {} \;
2017-03-16 08:43:56
User: brx75x
Functions: find sh
4

This is a commodity one-liner that uses ShellCheck to assure some quality on bash and sh scripts under a specific directory. It ignores the files in .git directory.

Just substitute "./.git/*" with "./.svn/*" for older and booring centralized version control.

Just substitute ShellCheck with "rm" if your scripts are crap and you want to get rid of them :)

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
4

Usage:

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
3

Uses parallel processing

Reiteration of my earlier command

https://www.commandlinefu.com/commands/view/15246/convert-entire-music-library

Usage

lc Old_Directory New_DIrectory Old_Format New_Format

lc ~/Music ~/Music_ogg mp3 ogg

sudo pv -tpreb /path/to/source | sudo dd bs=4096 of=/path/to/destination
2017-03-01 19:11:57
Functions: dd sudo
3

Uses the pv utility to show progress of data transfer and an ETA until completion.

You can install pv via Homebrew on macOS

tar -zcvf archive-name.tar.gz directory-name
wait_for_this.sh; echo "wait_for_this.sh finished running" | mail -s "Job Status Update" [email protected]
rename 's/^hospital\.php\?loc=(\d{4})$/hospital_$1/' hospital.php*