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 ankush108 from sorted by
Terminal - Commands by ankush108 - 20 results
nohup ./my-shell-script.sh &
2012-06-26 19:43:42
User: ankush108
Functions: nohup
Tags: nohup
0

After you execute a command (or shell script) in the background using

&, if you logout from the session, the command will get killed. To avoid

that, you should use nohup as shown below.

stat /etc/my.cnf
tr -s ' '
2012-06-26 19:34:18
User: ankush108
Functions: tr
Tags: tr
0

Convert long list of ' ' to a single space. Compress space and other characters.

cut -d: -f 1 names.txt
2012-06-26 19:28:25
User: ankush108
Functions: cut
Tags: column cut
0

Display the 1st field (employee name) from a colon delimited file

sort namesd.txt | uniq ?cd
2012-06-26 19:23:58
User: ankush108
Functions: sort uniq
0

The following displays only the entries that are duplicates.

sort namesd.txt | uniq
2012-06-26 19:22:34
User: ankush108
Functions: sort
Tags: sort uniq unique
0

Uniq command is mostly used in combination with sort command, as

uniq removes duplicates only from a sorted file. i.e In order for uniq to

work, all the duplicate entries should be in the adjacent lines.

ls -al | sort +4n
2012-06-26 19:20:05
User: ankush108
Functions: ls sort
Tags: size sort files
0

ls -al gives all files, sort +4n sorts by 5th field numerically

sort -t: -k 2 names.txt
2012-06-26 19:15:30
User: ankush108
Functions: sort
Tags: sort sorting
0

Sort using kth column using : delimiter

tr a-z A-Z < file.txt
join employee.txt bonus.txt
2012-06-26 18:36:11
User: ankush108
Functions: join
Tags: sql join
0

Join command combines lines from two files based on a common field.

cat file.txt > /dev/null
2012-06-26 18:34:12
User: ankush108
Functions: cat
0

This will be very helpful when you are debugging shell scripts, where

you don?t want to display the echo statement and interested in only

looking at the error messages. Similarly use 2> to supress error messages

grep -c "^$" filename
2012-06-26 17:43:17
User: ankush108
Functions: grep
Tags: grep count empty
0

This pattern matches empty lines in the file and -c gives the count

shopt -s cdspell
2012-06-26 17:28:57
User: ankush108
Tags: cd shopt spell
0

Use shopt -s cdspell to correct the typos in the cd command

help shopt
pushd path/to/dir/
cd -
2012-06-26 17:20:54
User: ankush108
Functions: cd
Tags: cd
1

switch to previous directory or toggle

function mkdircd () { mkdir -p "$@" && eval cd "\"\$$#\""; }
2012-06-26 17:19:16
User: ankush108
Functions: cd eval mkdir
Tags: cd mkdir
0

Creates a directory and then cds into it directly

~s
2012-06-26 16:26:11
User: ankush108
Tags: ssh
0

While logged into ssh, type ~s to see stats of ssh

~ <Ctrl+Z>
ssh -v jsmith@remotehost.example.com
2012-06-26 16:11:35
User: ankush108
Functions: ssh
Tags: ssh debug
0

Sometimes it is necessary to view debug messages to troubleshoot any

SSH connection issues. pass -v (lowercase v) option to the ssh as shown

below to view the ssh debug messages.