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 servermanaged from sorted by
Terminal - Commands by servermanaged - 56 results
echo $?
2009-05-09 17:32:23
Functions: echo
11

The variable ? contain the last exit status of a command, it can be printed for troubleshooting purpose.

find ~user/ -name "*~" -exec rm {} \;
2009-05-09 12:55:47
Functions: find rm
4

I use this simple command for remove all backup files generated usually by editors like Vim and Emacs.

cd !$
2009-05-08 09:48:14
Functions: cd
-3

During this operation :

# mv Joomla_1.5.10-Stable-Full_Package.zip /var/www/joomla/

I invoke /var/www/joomla/ as last command argument. To change in this directory I can use

# cd !$

So I go to

hob:/var/www/joomla#

!219 ; !229 ; !221
2009-05-07 20:51:36
8

Assuming that 219,229 and 221 are entries in history, I recall them in a single line for execute multiple commands

219 ifdown wlan0

...

221 ifup wlan0

...

229 iwconfig wlan0 mode Managed

so the result is execution of # ifdown wlan0 ; iwconfig wlan0 mode Managed ; ifup wlan0

tailf file.log
2009-05-07 20:13:41
Functions: tailf
5

tailf same as tail -f follow the flow of a log file, showing it in real time to stdout.

aureport -x
2009-05-06 11:42:12
1

Aureport is a tool for displaying auditd system log. -x options cause to display launched executable on system.

Aureport work with auditd so auditd must be installed an running on a system.

Tested on CentOS / Debian

sed -i '/Centos/d' VirtualBox.xml
2009-05-05 13:03:55
Functions: sed
-3

Simple but useful command, I use this for purge an hard disk entry in Virtualbox registry file (is in ~user/.Virtualbox) that persist if I erase a Virtual Machine, so I need to delete it manually.

sed G
2009-05-02 12:11:40
Functions: sed
-1

G option cause a file to be spacing line by line.

perm=( 6 4 4 ) ; for elem in ${perm[@]}; do echo `expr 7 - $elem` ; done
2009-05-01 12:08:19
Functions: echo
1

Umask is obtained subtracting 7 from each cypher of octal format. I store octal perm format in an array,then for each element of array I subtract 7. The result is the umask.

sftp -oPort=3476 user@host
2009-04-30 16:48:38
Functions: sftp
4

I use this for connect via sftp to a server listening on a non default ssh port.

ifstat -nt
2009-04-30 11:38:31
15

ifstat, part of ifstat package, is a tool for displaying bandwidth and other statistics. The -n option avoid to display header periodically, the -t option put a timestamp at the beginning of the line.

Works for me on Debian and CentOS

shopt -s histappend
2009-04-29 19:49:53
4

If histappend options is set in bash, the file .bash_history will not be overwrite and history list is append to it.

pinfo
2009-04-29 19:08:37
9

pinfo package provide a nice info alternative based on ncurses.

ac -p
2009-04-29 16:24:07
2

Works on CentOS ad OpenBSD too, display time of accounts connection on a system, -p option print individual user's statistics.

getfacl /mydir
gethostip 208.69.34.230 -x
routel
lam -f 1.4 myfile
2009-04-26 19:31:22
0

Lam is a command available on Bsd (I've tested it on OpenBSD).Is useful for laminate a file line by line. The -f option set the field width ( -f min.max ).

lndir sourcedir destdir
2009-04-24 18:30:29
4

Lndir create from source directory to destination directory a full symlink tree of all contents of source directory, really useful for propagate changes from a directory to another.

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

yum erase `yum list installed | grep 'php'`
2009-04-13 12:58:16
Functions: grep
-4

This is useful for remove all packages that are part of a common suite.

for f in * ; do mv -- "$f" "${f/[0-9][0-9] \- /}" ; done
2009-04-10 11:06:13
Functions: mv
-4

I have often file like this

01 - file.file

02 - file.file

03 - file.file

I rename all with this command

for f in * ; do mv -- "$f" "${f/[0-9][0-9] \- /}" ; done

then it looks like this

file.file

file.file

file.file

etc

stat -c '%A %a %n' *
2009-04-09 10:44:56
Functions: stat
22

Nicely display permissions in octal format and filename for a given directory

trap cmd 0
2009-04-08 21:34:13
Functions: trap
7

Execute a command on shell logout,and run it until is finished,then shell is closed.

ls !$
2009-04-07 12:31:06
Functions: ls
1

Suppose that you had change in a directory like /home/user/mycode/code, and now you need to list it, instead of type entire path again, use ls !$ to recall path and list. Useful with many commands, this is only an example. (In this case, same result can be achivied with ls .)