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,925 results
cp data.{json,yaml}
look mysql /etc/group
2009-04-24 18:20:20
Functions: look
-2

Look search for lines in a file that beginning with a given string.

Same as $ grep ^n /etc/passwd

smbclient -N -gL \\SambaServer 2>&1 | grep -e "Disk|" | cut -d'|' -f2
reg add "HKLM\SOFTWARE\Microsoft\Microsoft Antimalware\Exclusions\Paths" /v "C:\temp\evil.exe" /t REG_DWORD /d 00000000
2013-09-20 01:32:05
User: viperbit
-2

Add an entry to Microsoft Forefront's "Excluded file and locations". Replace C:\temp\evil.exe with desired folder to exclude. Requires administrative privileges.

Examples:

%SystemRoot%\system32\evil.exe

C:\*.exe

C:\

C:\temp\*.*

\\remotesvr\share

\\remotesvr\share\evil.exe

\\remotesvr\share\folder\evil.exe

cut -f2 file.txt | cut -d " " -f1
echo 'Host or User@Host?:'; read newserver && ssh-keygen -N "" -t rsa -f ~/.ssh/id_rsa ; ssh $newserver cat <~/.ssh/id_rsa.pub ">>" ~/.ssh/authorized_keys ; ssh $newserver
2010-05-07 06:24:53
User: alf
Functions: cat echo read ssh ssh-keygen
Tags: ssh ssh-keygen
-2

Some servers don't have ssh-copy-id, this works in those cases.

It will ask for the destination server, this can be IP, hostname, or user@hostname if different from current user.

Ssh keygen will let you know if a pubkey already exists on your system and you can opt to not overwrite it.

ls -l /dev/disk/by-id | egrep ata-.*`hdparm -i /dev/sda | grep SerialNo | sed 's/.*SerialNo=//' | tr -d "\n"`.*sda$ | sed -e 's/.*ata-/ata-/' -e 's|[ ].*||' | tr -d "\n"
2013-01-07 10:20:25
Functions: egrep grep ls sed tr
Tags: Ubuntu
-2

This was tested on Ubuntu 12.04 (Precise) LTS Server. It returns the name of the symlink within /dev/disk/by-id for the physical drive you specify. Change /dev/sda to the one you want, and replace ata- with scsi- or the appropriate type for your drive.

I used this to pre-configure grub-pc during a non-interactive install because I had to tell it which disk to install grub on, and physical disks don't have a UUID such as that blkid provides.

zsh$ M-v
2009-11-10 23:02:56
User: bucciarati
-2

355 # from zsh-users

356 edit_command_line () {

357 # edit current line in $EDITOR

358 local tmpfile=${TMPPREFIX:-/tmp/zsh}ecl$$

359

360 print -R - "$PREBUFFER$BUFFER" >$tmpfile

361 exec

362 ${VISUAL:-${EDITOR:-vi}} $tmpfile

363 zle kill-buffer

364 BUFFER=${"$(

365 CURSOR=$#BUFFER

366

367 command rm -f $tmpfile

368 zle redisplay

369 }

370 zle -N edit_command_line

cyanide(){ display "$(wget -q http://explosm.net/comics/random/ -O - | grep -Po 'http://www.explosm.net/db/files/Comics/*/[^"]+(png|jpg|jpeg)')"; }
2011-02-14 15:12:13
User: barbuk
Tags: comic cyanide
-2

Random Cyanide and Happiness comics from explosm.net. I use this command http://www.commandlinefu.com/commands/view/3477/random-xkcd-comic and update it for explosm.net

--edit : modification for *.jpeg files + guest authors

ls | grep ".txt$" | xargs -i WHATEVER_COMMAND {}
bdf | awk '(NF<5){f=$1; next} (NF>5){f=$1} {print f, $2, $3, $NF}'
while true ; do du -sk testfile ; sleep 10 ; done
2009-08-14 11:39:52
User: Solaris
Functions: du sleep true
-2

This command produces the output of "du -sk testfile" in every 10 seconds. You can change the command to be whatever you want.

for F in $(find ./ -name "*.tgz") ; do tar -tvzf $F ; done
2009-11-11 00:50:52
User: alchandia
Functions: find tar
Tags: tar
-2

The magic is performed by the parameter -t

ls | sed 's,\(.*\),"\1",'
2010-08-17 14:27:27
User: randy909
Functions: ls sed
-2

I had a file named " " (one space) and needed a way to see what the real filename was so I could remove it. sed to the rescue.

alias sshdo='ssh -q -t root@localhost -- cd $PWD \&\& sudo'
2010-10-20 22:33:22
User: darkfader
Functions: alias cd
Tags: sudo su ssh-agent
-2

Run program as root by SSH key forwarding instead of sudoers.

Put this alias line in .bashrc or wherever you like. Alias arguments might need extra escaping.

You might wonder about security. But you'd block out root login as much as possible of course. In sshd_config you put this:

PermitRootLogin no

Match Address 127.0.0.1

  PermitRootLogin without-password

xinit $(which awesome) -- /usr/bin/Xephyr :5 -once -fullscreen -ac -keybd "ephyr,,,xkbmodel=pc105,xkblayout=it,xkbrules=evdev,xkboption="
2012-11-03 00:54:33
User: hute37
Functions: which
Tags: awesome
-2

alternatives:

xinit $(which gnome-awesome-session)

with cat /usr/local/bin/gnome-awesome-session:

#!/bin/bash

exec gnome-session --session awesome "$@"

following: http://awesome.naquadah.org/wiki/Quickly_Setting_up_Awesome_with_Gnome

note: in ubuntu 12.10 a probable Xephyr recent bug rejects keybd option ...

mplayer -shuffle $HOME/music/* $HOME/Dropbox/Music/*/* $HOME/Dropbox/Music/*/*/* etc. >> /dev/null 2>&1
for f in *.png; do convert $f -resize 852x480 $f; done
2013-12-15 11:28:07
User: egeoffray
-2

Resize all png in the current folder.

Warning: no copy. Make sure you have a copy of the originals

10,30,50 * * * * ping -q -c1 -w3 192.168.0.14 | grep '1 received' - || env DISPLAY=:0 xeyes
2012-02-06 09:40:11
User: knoppix5
Functions: env grep ping
Tags: ping host crontab
-2

Every 20 minutes ping host with IP address 192.168.0.14. If it's not 'alive' or not reachable, then display something eye-catching (here xeyes) on the desktop.

Hint for newbies: edit crontab with

crontab -e
./poweriso extract $USER/file.daa / -od $USER/file_extracted
2009-02-15 23:19:40
User: brettalton
-2

.daa is a non-standard disk image format that can not be read by any other program. This is how you can extract the files though.

PowerISO binary for Linux: http://www.poweriso.com/poweriso-1.3.tar.gz

"This is a free utility for linux which can extract, list, and convert image files (including ISO, BIN, DAA, and other formats). Type " poweriso -? " for detailed usage information. File Size: 278KB"

clamscan -ir --bell ~user/
2009-05-21 13:09:31
-2

Scan for viruses, recursively and print only infected files, with bell sound. Clamscan is part of clamav package. Tested on Debian.

wget -qO - http://cfaj.freeshell.org/ipaddr.cgi
curl http://whatismyip.org
[Ctrl+u]
ls . | xargs file | grep text | sed "s/\(.*\):.*/\1/" | xargs gedit