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 mpb from sorted by
Terminal - Commands by mpb - 34 results
# wc -l /var/log/security/writable.today
2009-03-19 12:25:52
User: mpb
Functions: wc
0

Mandriva Linux includes a security tool called "msec" (configurable via "draksec").

One of the many things it regularily checks for is world writeable files.

If any are found, it writes the list to /var/log/security/writable.today.

"wc -l" simply counts the number of lines in the file.

This number should be low.

Browse through /var/log/security/writable.today and consider if any of those files *need* to be world-writeable (and if not, modify the permissions. eg: "chmod o-w $file").

A large number of world-writeable files may indicate that umask is not correctly set in /etc/profile (or ${HOME}/.bash_profile) but could also indicate poor security configuration or even malicious activity.

vos listvldb | agrep LOCKED -d RWrite | grep RWrite: | awk -F: '{print $2}' | awk '{printf("%s ",$1)} END {printf("\n")}'
2009-03-17 19:55:39
User: mpb
Functions: awk grep
0

This command shows if there are any locked AFS volumes.

The output is a list of AFS volume IDs (or nothing if there are none locked).

rpm -qa --queryformat '%{installtime} \"%{vendor}\" %{name}-%{version}-%{release} %{installtime:date}\n' | grep "Thu 05 Mar"
2009-03-17 13:38:20
User: mpb
Functions: grep rpm
4

Find out which RPMs were installed on a particular date.

These would (naturally) include update RPMs.

This example shows searching for "Thu 05 Mar" (with grep).

Alternatively, pipe it to less so you can search inside less (with less's neat text highlighting of the search term):

rpm -qa --queryformat '%{installtime} \"%{vendor}\" %{name}-%{version}-%{release} %{installtime:date}\n' | less # (this example) search term: Thu 05 Mar

play $audio_file
2009-03-17 11:30:02
User: mpb
-3

"play" is part of "SoX"

SoX - Sound eXchange, the Swiss Army knife of audio manipulation.

For details, see: man sox

:!cp % %-
2009-03-17 00:34:24
User: mpb
5

At the start of a vi session and *before* saving any changes use ":!cp % %-" to make a backup of the current file being edited.

example: vi /data/some/long/path/file

:!cp% %-

creates /data/some/long/path/file-

# indicates a comment in shell
2009-03-16 23:15:33
User: mpb
-4
#

Using the "#" in shell is surprisingly useful.

Some of the uses I found:

a) As a visible copy buffer in shell history (caveat: do not use for passwords :-)

b) To build complex commands until ready then hit the HOME, DEL, ENTER keys to run it

c) Placing reference data into shell history (search for tags with CTRL-R TAGNAME)

d) Putting aside a "work in progress" command to focus on another task (HOME # ENTER)

rpm -qa --qf '%{SIZE} %{NAME}\n' | sort -nr | nl | head -6 # six largest RPMs
2009-03-15 22:18:17
User: mpb
Functions: head nl rpm sort
2

Low on disk space? Check the largest installed RPMs for delete canditates.

ls -1 | grep " " | awk '{printf("mv \"%s\" ",$0); gsub(/ /,"_",$0); printf("%s\n",$0)}' | sh # rename filenames: spaces to "_"
2009-03-15 18:42:43
User: mpb
Functions: awk grep ls rename sh
2

This command converts filenames with embedded spaces in the current directory replacing spaces with the underscore ("_") character.

gcal -K -q GB_EN 2009 # display holidays in UK/England for 2009 (with week numbers)
2009-03-15 10:19:52
User: mpb
5

NB when you run this gcal command in your shell, holidays are highlighted

but this highlighting does not show in the sample output (above).

To find full details on gcal options: gcal --long-help | less

Example for United States, Pennsylvania:

gcal -K -q US_PA 2009 # display holidays in USA/Pennsylvania for 2009 (with week numbers)

Example for Hong Kong:

gcal -K -q HK 2009 # display holidays in Hong Kong for 2009 (with week numbers)