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,585 results
echo 1395767373016 | gawk '{print strftime("%c", ( $0 + 500 ) / 1000 )}'
dpipe /usr/lib/openssh/sftp-server = ssh $REMOTE_HOST sshfs whatever:$LOCAL_PATH $REMOTE_PATH -o slave
2014-03-25 17:40:34
User: em
Functions: ssh
5

While `sshfs $REMOTE_HOST:$REMOTE_PATH $LOCAL_PATH` "pulls" a directory from the remote server to the local host, the above command does the reverse and "pushes" a directory from the local host to the remote server.

This makes use of the "slave" option of sshfs which instructs it to communicate over plain stdin/stdout and the `dpipe` tool from vde2 to connect the sftp-server stdout to the sshfs stdin and vice-versa.

find . -name '*.mp3' | sort | while read -r mp3; do echo -e "<h3>$mp3</h3>\n<audio controls src=\"$mp3\"></audio>"; done > index.html; python -m http.server
2014-03-24 15:01:49
User: hendry
Functions: echo find python read sort
Tags: audio browser
1

I tried a few curses based mp3 players for playing back choir practice songs for my wife.

Unfortunately none of the ones I tried were capable of scrubbing a track.

Firefox saves the day.

for i in *.svg; do convert "$i" "${i%.svg}.png"; done
2014-03-24 14:02:02
User: flatcap
1

Convert some SVG files into PNG using ImageMagick's convert command.

for i in *; do inkscape $i --export-png=`echo $i | sed -e 's/svg$/png/'`; done
ls -lF -darth `find . -mmin -3`
2014-03-22 16:52:20
User: UncleLouie
Functions: ls
-2

Provides a recursive time ordered list of the current directory over the last 3 minutes.

Excluding zero byte files:

ls -lF -darth `find . -size +0 -mmin -3`

For the last day's files, change "-mmin -3" to "-mtime -1":

ls -lF -darth `find . -size +0 -mtime -1`
dmesg | grep -Po 'csum failed ino\S* \d+' | awk '{print $4}' | sort -u | xargs -n 1 find / -inum 2> /dev/null
2014-03-22 12:22:46
User: Sepero
Functions: awk dmesg find grep sort xargs
Tags: find inode btrfs
1

Btrfs reports the inode numbers of files with failed checksums. Use `find` to lookup the file names of those inodes. The files may need to be deleted and replaced with backups.

find ./ -type l -ls
find ./ -type l -print0 | xargs -0 ls -plah
2014-03-20 20:36:39
Functions: find ls xargs
0

shows you the symlinks in the current directory, recursively, but without following them

sed -n "/^.\{73,\}/p" < /path/to/file
2014-03-20 12:31:57
User: flatcap
Functions: sed
0

Filter out lines of input that contain 72, or fewer, characters.

"sed -n" : don't print lines by default

"/^.\{73,\}/" : find lines that start with 73 (or more) characters

"p" : print them

while read i; do [ ${#i} -gt 72 ] && echo "$i"; done < /path/to/file
2014-03-20 12:27:06
User: flatcap
Functions: echo read
1

Filter out lines of input that contain 72, or fewer, characters.

This uses bash only. ${#i} is the number of characters in variable i.

perl -nle 'print length,"\t",$_ if length > 37' < /path/to/input/file
dmesg | grep -Po 'csum failed ino\S* \d+' | sort | uniq | xargs -n 3 find / -inum 2> /dev/null
2014-03-20 06:27:15
User: Sepero
Functions: dmesg find grep sort uniq xargs
Tags: find inode btrfs
-1

Btrfs reports the inode numbers of files with failed checksums. Use `find` to lookup the file names of those inodes.

dsquery computer DC=example,DC=com -limit 150 | find /c /v ""
ruby -run -e httpd . -p 8000
tar -cvf - /path/to/tar/up | xz - > myTarArchive.tar.xz
2014-03-18 19:51:50
User: razerwolf
Functions: tar
1

compress directory archive with xz compression, if tar doesn't have the -J option (OSX tar doesn't have -J)

psql -h <SERVER NAME HERE> -c 'SELECT version();' | grep -v 'version\|---\|row\|^ *$' | sed 's/^\s*//'
2014-03-17 18:36:40
User: pnelsonsr
Functions: grep sed
0

In a multiple PostgreSQL server environment knowing the servers version can be important. Note that psql --version returns just the local psql apps version which may not be what you want. This command dumps the PostgreSQL servers version out to one line. You may need to add more command line options to the psql command for your connection environment.

alias ...='while read line; do echo -n "."; done && echo ""'
net user user_name new_password /domain
Set-Mailbox -Identity John -DeliverToMailboxAndForward $false -ForwardingSMTPAddress manuel@contoso.com
Add-ADPermission "username_mailbox" -User "Domain\User" -Extendedrights "Send As"
Add-MailboxPermission -Identity "username_of_mailbox_owner" -User username_control_to -AccessRights Fullaccess -InheritanceType all
for i in `sudo /sbin/fdisk -l |grep Disk |grep dev |awk '{ print $2 }' |sed s/://g` ; do sudo /usr/bin/dd if=/dev/urandom of=$i bs=8M & done
2014-03-16 12:04:59
User: aimana007
Functions: awk grep sed sudo
Tags: bash Linux
1

This command will use the fdisk utility to find all block devices on your system, and overwrite them with data from the /dev/urandom non-blocking random number generator.

CAUTION: This will irrevocably erase EVERY SINGLE physical block storage device visible to the fdisk utility, including plugged USB devices, RAID sets, LVM, etc.

!a[$0]++
wmic OS get OSArchitecture /value | grep -Eo '[^=]*$'
2014-03-15 02:04:08
User: lowjax
Functions: get grep
0

Using "wmic get * /value" within any Cygwin shell will return lots of Win/Dos newline junk ie "^M$" at the end of found value line, two lines ("$" Unix newline) above, and three below. This makes storing and or evaluating wmic queries as variables a pain. The method i suggest strips the mentioned junk, only returns the value after "OSArchitecture=", and includes only one Unix style newline. Other methods using sed|awk|cut can only handle the output of wmic cleanly when piped or using multiple sed statements.

wmic OS get OSArchitecture /value | sed 's/\r//g;s/^M$//;/^$/d;s/.*=//'

making

wmic OS get OSArchitecture /value | grep -Eo '[^=]*$'

a much cleaner and slightly less costly alternative.