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

Commands by totti from sorted by
Terminal - Commands by totti - 87 results
ls -i1 filename
tail -f ~/.bash_history
2011-09-15 19:35:09
User: totti
Functions: tail
Tags: watch
-1

Changes are displayed when they are written to the file

to exit

vi +4 /etc/mtab
2011-09-15 19:18:00
User: totti
Functions: vi
Tags: edit text line goto
1

This is not printing, real editing using the text editor.

awk '$3==$4' /etc/passwd
sed 's/.$//' Win-file.txt
cat aaaaaa 2>&-
nl file.txt > file_numbered.txt
var='123456789'; echo ${var:<start_pos>:<offset>}
2011-09-14 20:05:17
User: totti
Functions: echo
12

substrings a variable starting at position.

If no offset given prints rest of the line

c=$(pgrep <cmd>) && <new_cmd> && kill $c
2011-09-14 19:58:30
User: totti
Functions: kill
1

eg:

Already running cmd

sleep 120

Substitution cmd

c=$(pgrep sleep) && sleep 5 && kill $c
bsdiff <oldfile> <newfile> <patchfile>
2011-09-13 18:22:40
User: totti
7

Upload/download newer version of any file with less size and high speed.

To remake the new file use

bspatch <oldfile> <newfile> <patchfile>
less file.ext
2011-09-13 10:29:27
User: totti
Functions: less
Tags: less text search
-4

Use the following key binding to search

----------------------------------------------------------------

ng

: Jump to line number n. Default is the start of the file.

nG

: Jump to line number n. Default is the end of the file.

/pattern

: Search for pattern. Regular expressions can be used. [/ = slash] Press / and then Enter to repeat the previous search pattern. Press ESC and then u to undo search highlighting.

n

: Go to next match (after a successful search).

N

: Go to previous match.

mletter

: Mark the current position with letter.

'letter

: Return to position letter. [' = single quote]

'^ or g

: Go to start of file.

'$ or G

: Go to end of file.

s

: Save current content (got from another program like grep) in a file.

= or Ctrl+g

: File information.

F

: continually read information from file and follow its end. Useful for logs watching. Use Ctrl+c to exit this mode.

-option

: Toggle command-line option -option.

h

: Help.

smartctl -A /dev/sda | grep Power_On_Hours
tr -d "\r" < file.vcf | tr "\0" " " > file.vcf.txt
tr -d "\r" < dos.txt > linux.txt
mogrify -resize 600x800! *.jpg
2011-09-09 18:19:59
User: totti
0

- Backup data before reszie as it over write original

-To preserve aspect ratio remove !

hexdump -c <file>
say() { wget -q -U Mozilla -O output.mp3 "http://translate.google.com/translate_tts?tl=en&q=$1"; gnome-terminal -x bash -c "totem output.mp3"; sleep 4; totem --quit;}
2011-09-07 19:48:53
User: totti
Functions: bash sleep wget
1

No need to install additional packages

eg:

say hello

For multiword

say how+are+you

<Ctrl><Alt><F6> killall5
2011-09-07 19:19:34
User: totti
1

Killall5 will kill your session and redirect to login screen.

-Very useful when suffering display problems.

-Can use F1-F6

-Need to login in the particular console if not already

wallpaperWarn() { BG="/desktop/gnome/background/picture_filename"; convert "`gconftool-2 -g $BG`" -pointsize 70 -draw "gravity center fill red text 0,-360 'Warn' fill white text 0,360 'Warn'" /tmp/w.jpg; gconftool-2 --set $BG -t string "/tmp/w.jpg"; }
2011-09-07 19:00:40
User: totti
1

Display some text on the wallpaper especially warning messages

convert -background none -pointsize 55 label:"`whoami`" me.png
2011-09-07 17:06:38
User: totti
1

Create transparent image to use as icon, watermark for other images, etc.

sed '4!d'
2011-09-05 17:54:57
User: totti
Functions: sed
-1

d --> delete

!d ---> delete others

bc <<< `uptime | sed -e 's/^.*up //' -e 's/[^0-9:].*//' | sed 's/:/*60+/g'`
2011-08-29 10:24:43
User: totti
Functions: bc sed
1

Want to run scripts/programs in the system after starting X minute [ For letting the system to free ]? This will give uptime in minute.

seq 20 | sed '5,6 { w out.txt }' #Can't print correctly. See sample output
2011-08-29 10:17:47
User: totti
Functions: sed seq
Tags: sed
0

Can't print correctly in the command field.

There is a new line before } as follows

seq 20 | sed -n '5,6 { w out.txt

}'

mount |tail -1 | less -p "/dev/[^ ]*"
switchMonitor () { LF=/tmp/screen-lock; if [ -f $LF ]; then rm $LF; else touch $LF; sleep .5; while [ -f $LF ]; do xset dpms force off; sleep 2; done; fi };
2011-08-26 17:55:44
User: totti
Functions: rm sleep touch
1

Use the command to create a script and bind it to a key using keyboard shortcut.

eg:

Script locks the screen in a loop until the command is executed again.At first it