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 sonic from sorted by
Terminal - Commands by sonic - 7 results
sed -i 's/^/ls -l /' output_files.txt
2013-10-07 15:12:53
User: sonic
Functions: sed
Tags: sed replace
0

The original command is great, but I often want to prepend to every line.

:set number
2013-10-07 15:03:52
User: sonic
Tags: vim vi
0

Prints line numbers making it easier to see long lines that wrap in your terminal and extra line breaks at the end of a file.

:set nu

works too.

find -L /home/sonic/archive -name '*gz' -type f
2013-10-07 14:32:22
User: sonic
Functions: find
Tags: find
-1

If /home/sonic/archive/ was a symlink to /backup/sonic/archive it would follow the links and give you the file listing. By default find will NOT follow symbolic links. The default behavior for the find command is to treat the symlinks as literal files.

I discovered this when trying to write a script run via cron to delete files with a modification time older than X days. The easiest solution was to use:

/usr/bin/find -L /home/sonic/archive -name '*gz' -type f -mtime +14 -exec rm '{}' \;

find * -maxdepth 0 -type d
2013-02-25 21:10:49
User: sonic
Functions: find
0

the advantage to doing it this way is that you can adjust the max depth to get more recursive results and run it on non GNU systems. It also won't print trailing slashes, which can easily be removed, but can be slightly annoying..

You could run:

# for file in `find * -maxdepth 0 -type d`;do ls -d $file;done

and in the ls -d part of the command you can put in whatever parameters you want to get things like permissions, time stamps, and ownership.

export HISTFILE=/dev/null
2013-02-18 16:37:01
User: sonic
Functions: export
Tags: history bash
0

just an alternative to setting the size, this allows you to scroll up and see your previous commands in a given session but when you logout the history is not saved. That's the only advantage to doing it this way..

for file in *; do convert $file -resize 800x600 resized-$file; done
2013-02-17 21:37:14
User: sonic
Functions: file
Tags: xargs convert
0

To ignore aspect ratio, run:

for file in *; do convert $file -resize 800x600! resized-$file; done

and all images will be exactly 800x600.

Use your shell of choice.. This was done in BASH.

wget -c or wget --continue
2013-02-17 21:12:00
User: sonic
Functions: wget
2

I couldn't find this on the site and it's a useful switch. Great for large files.