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:
It starts in the current working directory.
It removes the empty directory and its ancestors (unless the ancestor contains other elements than the empty directory itself).
It will print a failure message for every directory that isn't empty.
This command handles correctly directory names containing single or double quotes, spaces or newlines.
If you do not want only to remove all the ancestors, just use:
find . -empty -type d -print0 | xargs -0 rmdir
This command removes and then cvs removes all files in the current directory recursively.
use it to add a random boolean switch to your script
use it to stagger cronjob or to get a random number
increase the range by replacing 100 with your own max value
I don't like doing a massive sort on all the directory names just to get a small set of them. the above shows a sorted list of all directories over 1GB. use head as well if you want.
du's "-x" flag limits this to one file system. That's mostly useful when you run it on "/" but don't want "/proc" and "/dev" and so forth. Remember though that it will also exclude "/home" or "/var" if those are separate partitions.
the "-a" option is often useful too, for listing large files as well as large directories. Might be slower.
list the top 15 folders by decreasing size in MB
This commands queries the delicious api then runs the xml through xml2, grabs the urls cuts out the first two columns, passes through uniq to remove duplicates if any, and then goes into linkchecker who checks the links. the links go the blacklist in ~/.linkchecker/blacklist. please see the manual pages for further info peeps. I took me a few days to figure this one out. I how you enjoy it. Also don't run these api more then once a few seconds you can get banned by delicious see their site for info. ~updated for no recursive
POSIX compliant arithmetic evaluation.
echo 'alias monitor_off="sleep 1; xset dpms force standby"' >> ~/.bash_aliases ; . ~/.bash_aliases # now monitor_off does what you think
This keeps the user logged in but shows the login screen. Very useful when connecting remotely to an OSX-Server via VNC
This allows you to search through your history using the up and down arrows ? i.e. type "cd /" and press the up arrow and you'll search through everything in your history that starts with "cd /".
Only requirement is bash shell. No functions needed.
this bash command sets it so that when you type "screen ", it searches your running screens, and present valid auto-complete choices. The output is .
Note: You must have programmable completion enabled. Check with "shopt progcomp", set with "shopt -s progcomp"
This exports all lines of input file as environment variables, assuming each line is like these:
echo "ls" > script.bash;
This is my script, a simple 'ls'.
gpg -c script.bash;
Here I encrypt and passord-protect my script. This creates file script.bash.gpg.
cat script.bash.gpg | gpg -d --no-mdc-warning | bash
Here I open file script.bash.gpg, decrypt it and execute it.
The original command doesn't work for me - does something weird with sed (-r) and xargs (-i) with underscores all over...
This one works in OSX Lion. I haven't tested it anywhere else, but if you have bash, gpg and perl, it should work.
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..
Also detaches session if attached from somewhere else.
Runs a diff on two files ignore comments and blank lines (diff -I=RE does not work as expected). Adapted from a post found on stackexchange.
I used to do this sorting with:
sort file.txt | uniq -c | sort -nr
But this would cause the line (2nd column) to be sorted in descending (reverse) order as well sa the 1st column. So this will ensure the 2nd column is in ascending alphabetical order.