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.

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

2011-03-12 - Confoo 2011 presentation
Slides are available from the commandlinefu presentation at Confoo 2011: http://presentations.codeinthehole.com/confoo2011/
2011-01-04 - Moderation now required for new commands
To try and put and end to the spamming, new commands require moderation before they will appear on the site.
2010-12-27 - Apologies for not banning the trolls sooner
Have been away from the interwebs over Christmas. Will be more vigilant henceforth.
2010-09-24 - OAuth and pagination problems fixed
Apologies for the delay in getting Twitter's OAuth supported. Annoying pagination gremlin also fixed.
Hide

Tags

Hide

Functions

All commands from sorted by
Terminal - All commands - 11,856 results
echo -e "CHECK=SAMPLE" output --command_to_long
2013-04-03 08:46:47
User: techie
Functions: echo
-1

This is longer than others on here. The reason for this is I have combined two different matrix commands so it would work on all computers. I logged onto my server through a computer and it worked fine. I logged into my server through a mac and it looked $4!t so I have made one that works through both.

ps -e -o pid,vsz,comm= | sort -n -k 2
2014-05-14 00:36:50
Functions: ps sort
-1

left-most column is PID, middle is virtual memory being consumed, right-most is actual process.

find . -size 0 -print0 | xargs -0 rm
2009-10-29 14:10:02
User: osvaldofilho
Functions: find xargs
-1

The command find search commands with size zero and erase them.

date MMDDhhmmYYYY
2010-05-29 08:26:13
User: christian773
Functions: date
-1

date MMDDhhmmYYYY

date MMDDhhmm

# example 27.12.1975 08:00

date 122708001975

c="cp -a";e="~";echo -e "\npaste\n";i=0;k="1"; while [[ "$k" != "" ]]; do read -a k;r[i]=$k;((i++));done;i=0;while :;do t=${r[i]};[ "$t" == "" ] && break; g=$(echo $c ${r[i]} $e);echo -e $g "\ny/n?";read y;[ "$y" != "n" ] && eval $g;((i++));done
2011-12-04 12:45:44
User: knoppix5
Functions: echo eval read
-1

Schematics:

command [options] [paste your variable here] parameter

command [options] [paste entire column of variables here] parameter

...

(hard-code command "c" and parameter "e" according to your wishes: in example shown command = "cp -a" and parameter = "~")

Features:

- Quick exchange only variable part of a long command line

- Make variable part to be an entire column of data (i.e. file list)

- Full control while processing every single item

Hints:

Paste column of data from anywhere. I.e. utilize the Block Select Mode to drag, select and copy columns (In KDE Konsole with Ctrl+Alt pressed, or only Ctrl pressed in GNOME Terminal respectively).

Disadvantages:

You can paste only one single variable in a row. If there are more space separated variables in a row only first one will be processed, but you can arrange your variables in a column instead. To transpose rows to columns or vice versa look at Linux manual pages for 'cut' and 'paste'.

TODO:

- add edit mode to vary command "c" and parameter "e" on the fly

- add one edit mode more to handle every list item different

- add y/n/a (=All) instead of only y(=default)/n to allowed answers

Disclaimer:

The code is not optimized, only the basic idea is presented here. It's up to you to shorten code or extend the functionality.

kde-open -v | grep Platform | cut -d' ' -f4-
2012-01-19 13:05:26
User: funollet
Functions: cut grep
-1

Sample input:

kde-open -v

Qt: 4.7.4

KDE Development Platform: 4.7.3 (4.7.3)

KIO Client: 2.0

sed -i 's/http:\/\/old\/new\///g' index.html
tar -cf - folder/ | gpg -c > folder.tpg
2009-05-08 19:20:08
User: copremesis
Functions: gpg tar
-1

gpg's compression is as suitable as gzip's however your backups can now be encrypted.

to extract use:

gpg < folder.tpg | tar -xf -
fetch -q -o - http://ipchicken.com | egrep -o '([[:digit:]]{1,3}\.){3}[[:digit:]]{1,3}'
2009-08-06 11:57:44
User: spackle
Functions: egrep
-1

Same thing as above, just uses fetch and ipchicken.com

disper --displays=auto -e -t left
2010-01-28 06:46:56
-1

Disper: http://willem.engen.nl/projects/disper/

Moving Gnome Panels to the external screen is done using gconf-editor, changing property "/apps/panel/toplevels/top_panel_screen0/monitor", as well as "/apps/panel/toplevels/bottom_panel_screen0/monitor" to int value "1". This can be done from the command line using '

gconftool-2 --set "/apps/panel/toplevels/top_panel_screen0/monitor" --type integer "1"' so a nice script can be written.

wget -O - http://checkip.dyndns.org|sed 's/[^0-9.]//g'
svn log -v | less
for i in *; do j=`echo $i | cut -d "-" -f1`; j=$j; mv $i $j; done
2011-03-06 11:58:37
User: jaimerosario
Functions: cut mv
-1

Renames files eliminating suffix, in this case everything after "-" is cutted. Just change "-" with the character you need.

grep -E '<DT><A|<DT><H3' bookmarks.html | sed 's/<DT>//' | sed '/Bookmarks bar/d' | sed 's/ ADD_DATE=\".*\"//g' | sed 's/^[ \t]*//' | tr '<A HREF' '<a href'
2011-05-26 22:21:01
User: chrismccoy
Functions: grep sed tr
Tags: sed grep chrome
-1

chrome only lets you export in html format, with a lot of table junk, this command will just export the titles of the links and the links without all that extra junk

while true; do date; (curl -s -o 1.html http://www.biglion.ru/deals/ebay-80/ &); sleep 5; cat 1.html | grep "&#1082;&#1091;&#1087;&#1086;&#1085;&#1086;&#1074;" | awk -F"<div>" '{print $2}' | awk -F"<span>" '{print $1}'; done
2013-11-08 12:40:05
User: sxiii
Functions: awk cat grep sleep
-1

Processes biglion quantity of sold ebay coupons/bonus codes, so you can know approximate count of users who buyed the coupons and when sales are come up again.

You can change sleep parameter so script will work slowly or faster (default is 5 seconds).

Additional requirements: curl

Standart tools used: awk, date, cat, grep (bash)

cp -p file-you-want-backup{,_`date +%Y%m%d`} # for bash
find -not -empty -type f -printf "%s\n" | sort | uniq -d | parallel find -type f -size {}c | parallel md5sum | sort | uniq -w32 --all-repeated=separate
2010-01-28 08:40:18
Functions: find md5sum sort uniq
Tags: xargs parallel
-1

A bit shorter and parallelized. Depending on the speed of your cpu and your disk this may run faster.

Parallel is from https://savannah.nongnu.org/projects/parallel/

year=2010; math=`echo "$year%4" | bc`; [ ! -z $year ] && [ $math -eq 0 ] && echo "$year is leap year!" || echo "$year isn't leap year";
wget -qO - http://i18n.counter.li.org/ | grep 'users registered' | sed 's/.*\<font size=7\>//g' | tr '\>' ' ' | sed 's/<br.*//g' | tr ' ' '\0'
ls -lad
2013-04-03 09:58:31
User: techie
Functions: ls
Tags: ls
-1

This will show you the permissions on the directory you are currently in

w
2009-03-24 16:03:28
User: haivu
-1

Short and sweet command. This command is also useful for other information such as what IP address a particular user logged in from, how long had they been logged in, what shell do they use.

du -kd | egrep -v "/.*/" | sort -n
2010-03-30 15:40:35
User: rmbjr60
Functions: du egrep sort
-1

Thanks for the submit! My alternative produces summaries only for directories. The original post additionally lists all files in the current directory. Sometimes the files, they just clutter up the output. Once the big directory is located, *then* worry about which file(s) are consuming so much space.

mount | grep "mount point"
mmv "*-*.mp3" "#1.mp3"
2011-03-06 13:41:54
User: houghi
-1

replace the "-" by the character you wish. If you have multiple extentions, like jpef, jpg and JPG you could use

mmv "*-*.*" "#1.#3"
awk 'BEGIN {srand} /^[a-z]{4,8}$/ {w[i++]=$0} END {while (j++<4) print w[int(rand*i)]}' /usr/share/dict/words
2011-08-18 02:09:42
User: putnamhill
Functions: awk
Tags: awk xkcd
-1

If you do not have shuf or an -R option in sort, you can fall back on awk. This provides maximum portability IMO. The command first collects words from the dictionary that match the criteria - in this case: lower case words with no punctuation that are 4 to 8 characters long. It then prints 4 random entries. I decided to print each word on a separate line to improve readability.