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/
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.
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.
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:
Takes filenames and directory names and replace space to '_'.
An alias i made for myself to play music in a faster way.
Works great when you have Guake / Tilda installed (Console that drops down like in the game QUAKE)
I put this in my bash_alias file (I'm on ubuntu, the bash_alias file does autostart with the right config) but it works putting it in bashrc too. Or anything that autostarts when the console is opened.
Needs Mplayer and music files to work. With out music theres nothing to play!
Oh, and also, without modification, this alias will try to play stuff from your ~/Music folder! (case sensitive). Make sure that folder exists and has music OR edit this alias to fit your needs.
If you want to operate on a set of items in Bash, and at least one of them contains spaces, the `for` loop isn't going to work the way you might expect. For example, if the current dir has two files, named "file" and "file 2", this would loop 3 times (once each for "file", "file", and "2"):
for ITEM in `ls`; do echo "$ITEM"; done
Instead, use a while loop with `read`:
ls | while read ITEM; do echo "$ITEM"; done
time read -sn1 (s:silent, n:number of characters. Press any character to stop)
This command will grep the entire directory looking for any files containing the list of files. This is useful for cleaning out your project of old static files that are no longer in use. Also ignores .svn directories for accurate counts. Replace 'static/images/' with the directory containing the files you want to search for.
This assumes you have the package installed necessary for converting WMF files. On my Ubuntu box, this is libwmf-bin. I used this command, as libwmf is not on my wife's iMac, so I archived the directories containing the WMF files from OS X, ran them on my Ubuntu box, archived the resulting SVGs, and sent them back to her. Quick, simple and to the point.
Searches directories recursively looking for extensions ignoring case. This is much more readable and clean than -exec for find. The while loop also gives further flexibility on complex logic. Also, although there is 'wmf2svg --auto', it expects lowercase extensions, and not uppercase. Because I want to ignore case, I need to use the -o option instead.
Works in ZSH and BASH. Haven't tested in other shells.
This will print out the third column of every line in FILE. Useful for many files in /proc or *csv data.
This is a quick line to stream in the latest offerings of your favorite netcasts/podcasts. You will need to have a file named netcast.txt in the directory you run this from. This file should have one and only one of your netcast's/podcst's url per line.
When run the line grabs the offering on the top of the netcast/podcast stack and end it over , quietly, to vlc.
Since I move around computers during the day I wanted an easy way to listen to my daily dose of news and such without having to worry about downloading to whatever machine I am on. This is just a quick grab and stream of whats current.
Future plans... have the list of netcasts be read from the web. possibly an rss or such. I use greader so there might be a way to use it as the source so as not to have to muck with multiple lists
This is a simple case of recursing through all directories, adding the '.bak' extension to every file. Of course, the 'cp $file $file.bak' could be any code you need to apply to your recursion, including tests, other functions, creating variables, doing math, etc. Simple and clean recursion.
Old snapshots can cause problems. It's best to remove them when finished. I use this script to remove all snapshots. The "while read" command is necessary because my vm names contain spaces. The "time" command reports how long the process runs.
see sample output
The $[...] block in bash and zsh will let you do math.
This is the same as using $((...)), which also works in ksh. Of course, this is a simple, dumb wrapper and doesn't allow floating-point.
unsets variables used by the one-liner
sets up the IFS bash variable to not be affected by whitespace and disables extra glob expansion
uses read to slurp the results of the find command into an array
selects an element of the array at random to be passed as an argument to mplayer
This command deletes all files in all subfolders if their name or path contains "deleteme".
To dry-run the command without actually deleting files run:
find . | grep deleteme | while read line; do echo rm $line; done
or, to process a single directory:
for f in *; do mv $f `echo $f |tr '[:upper:]' '[:lower:]'`; done
or, for a single directory:
for f in *.c; do mv $f "`basename $f .c`".C; done
Modify the script for your username and password, and save it as a script. Run the script, and enjoy ./tweet
Add @mail.com each line of a list
Imagemagick library is used. If image format is not JPEG, the "quality" option should not be issued.
customizable context searches - if you know sed, this is a basis for more complex context control than grep --context offers