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.


If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/

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

All commands from sorted by
Terminal - All commands - 12,332 results
dpkg -l 'linux-*' | sed '/^ii/!d;/'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d;s/^[^ ]* [^ ]* \([^ ]*\).*/\1/;/[0-9]/!d'
watch "awk '/Rss/{sum += \$2; } END{print sum, \"kB\"}' < /proc/$(pidof firefox)/smaps"
2015-09-19 00:36:34
User: gumnos
Functions: watch
2

Sometimes top/htop don't give the fine-grained detail on memory usage you might need. Sum up the exact memory types you want

echo "1 BTC = $(curl -s https://api.coindesk.com/v1/bpi/currentprice/usd.json | grep -o 'rate":"[^"]*' | cut -d\" -f3) USD"
wget https:[email protected]/holy-fsck-a-contest-cd320952726b
2015-09-18 23:57:23
User: jonhendren
Functions: wget
Tags: CLFUContest
0

Here?s the idea: Submit a one-liner that returns a value or string usable for monitoring something. The more interesting/important, the better.

Tag your one-liners with CLFUContest to enter. Whether you?re participating or not, be sure to vote on the other submissions. The top 5 contest entries by vote count will receive a $10 Amazon gift certificate. On top of that, we?ll select our 3 favorite entries to receive $25 Amazon gift certificates. The prizes might even overlap! Feel free to enter as many times as you like. Check out the URL above for the fine print.

-Admin

wget -q -O - ifconfig.co
du -h --max-depth=1 /home/ | sort -n
-A INPUT -p tcp --dport 22 -m mac --mac-source 3E:D7:88:A6:66:8E -j ACCEPT
2015-09-17 14:51:47
User: erez83
0

-A INPUT -p udp -m udp --dport 10000:66000 -m mac --mac-source 3E:D7:88:A6:66:8E -j ACCEPT

-A INPUT -p udp -m udp --dport 5060 -m mac --mac-source 3E:D7:88:A6:66:8E -j ACCEPT

-A INPUT -p tcp --dport 22 -m mac --mac-source 3E:D7:88:A6:66:8E -j ACCEPT

curl $1 | grep -E "http.*\.mp3" | sed "s/.*\(http.*\.mp3\).*/\1/" | xargs wget
2015-09-17 13:19:53
User: theodric
Functions: grep sed xargs
1

The difference between the original version provided and this one is that this one works rather than outputting a wget error

du -sh * | sort -h
du -x --max-depth=1|sort -rn|awk -F / -v c=$COLUMNS 'NR==1{t=$1} NR>1{r=int($1/t*c+.5); b="\033[1;31m"; for (i=0; i<r; i++) b=b"#"; printf " %5.2f%% %s\033[0m %s\n", $1/t*100, b, $2}'|tac
2015-09-12 10:36:49
Functions: awk du printf sort
10

A more efficient way, with reversed order to put the focus in the big ones.

tr -d "\"" < infile.csv > noquotes.csv
2015-09-11 23:41:48
User: UnklAdM
Functions: tr
Tags: CSV quotes
0

I always forget this one and find all kinds of complex solutions on google. Also works great while piping data. ex. 'cat data | process-data | tr -d "\"" > processed-data-without-quotes'

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
3

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

usage:

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

perl -ne [email protected]=split(/,/); $b=0; foreach $r (1..$#a){ $b+=$a[$r] } print "$a[0],$b\n"' -f file.csv
2015-09-04 21:05:56
User: miniker84
Functions: perl
-2

For all lines, sum the columns following the first one, and then print the first column plus the sum of all the other columns.

example input:

1,2,3,4,5

2,2,3,4,5

becomes

1,14

2,14

curl ifconfig.co/all.json
curl ifconfig.co
nohup bash example.sh 2>&1 | tee -i i-like-log-files.log &
nohup exemplo.sh &
sudo sh -c 'printf "[SeatDefaults]\nallow-guest=false\n" >/usr/share/lightdm/lightdm.conf.d/50-no-guest.conf'; sudo sh -c 'printf "[SeatDefaults]\nallow-guest=false\n" >/usr/share/lightdm/lightdm.conf.d/50-guest-wrapper.conf'
2015-08-31 18:12:21
User: andregyn62
Functions: sh sudo
-2

This command will disable a guest user logon, this user don't have password to login in the system.

sed -e "s/[^/]*\/\/\([^@]*@\)\?\([^:/]*\).*/\2/"
: </dev/tcp/127.0.0.1/80
2015-08-28 19:07:27
User: zlemini
14

For times when netcat isn't available.

Will throw a Connection refused message if a port is closed.

Scriptable:

(: </dev/tcp/127.0.0.1/80) &>/dev/null && echo "OPEN" || echo "CLOSED"
sed 's/,/\n/g;q' file.csv | nl
2015-08-26 11:38:56
User: flatcap
Functions: sed
Tags: sed nl
0

Take the header line from a comma-delimited CSV file and enumerate the fields.

.

First sed replaces all commas with newlines

s/,/\n/g

Then sed quits (q) after the first line.

Finally, nl numbers all the lines

awk -F, '{gsub(/ /,"");for(f=1;f<=NF;f++) print f,$f;exit}' file.csv
2015-08-26 09:30:43
User: sesom42
Functions: awk
-1

-F,

use , as field separator

gsub()

deletes all spaces

for(){}

loops over all input fields and print their index and value

exit

exit after first line

head -1 file.csv | tr ',' '\n' | tr -d " " | awk '{print NR,$0}'
2015-08-26 05:46:15
User: neomefistox
Functions: awk head tr
0

Useful to identify the field number in big CSV files with large number of fields. The index is the reference to use in processing with commands like 'cut' or 'awk' involved.

stat -c'%s %n' **/* | sort -n
python -c "import requests; from bs4 import BeautifulSoup; print '\n'.join([cmd.text for cmd in BeautifulSoup(requests.get('http://www.commandlinefu.com/commands/by/${USER}').content, 'html.parser').find_all('div','command')])"
2015-08-22 21:32:36
User: funky
Functions: python
2

This utilizes the Requests and BeautifulSoup libraries in Python to retrieve a user page on commandlinefu, parse it (error-tolerant) and extract all the lines of the following format:

gzip *

To print them, a list comprehension is used to iterate over the values, and join() is called on a newline character.