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.
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.
» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10
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:
Recursively remove .svn directories from the current location.
This deals nicely with files having special characters in the file name (space ' or ").
Parallel is from https://savannah.nongnu.org/projects/parallel/
CHANGELOG
Version 1.1
removedir () { echo "You are about to delete the current directory $PWD Are you sure?"; read human; if [[ "$human" = "yes" ]]; then blah=$(echo "$PWD" | sed 's/ /\\ /g'); foo=$(basename "$blah"); rm -Rf ../$foo/ && cd ..; else echo "I'm watching you" | pv -qL 10; fi; }
BUG FIX:
Folders with spaces
Version 1.0
removedir () { echo "You are about to delete the current directory $PWD Are you sure?"; read human; if [[ "$human" = "yes" ]]; then blah=`basename $PWD`; rm -Rf ../$blah/ && cd ..; else echo "I'm watching you" | pv -qL 10; fi; }
BUG FIX:
Hidden directories (.dotdirectory)
Version 0.9
rmdir () { echo "You are about to delete the current directory $PWD. Are you sure?"; read human; if [[ "$human" = "yes" ]]; then blah=`basename $PWD`; rm -Rf ../$blah/ && cd ..; else echo "I'm watching you" | pv -qL 10; fi; }
Removes current directory with recursive and force flags plus basic human check. When prompted type yes
1. [[email protected] ~]$ ls
foo bar
2. [[email protected] ~]$ cd foo
3. [[email protected] foo]$ removedir
4. yes
5. rm -Rf foo/
6. [[email protected] ~]$
7. [[email protected] ~]$ ls
bar
Remove everything except that file with shell tricks inside a subshell to avoid changes in the environment.
help shopt
You're a developer - but it doesn't mean you have to slum it! Why not spice up your man page lookups by using a decent PDF viewer. I use 'xpdf' - maybe you prefer acroread, whatever, it's just as fast as plain dull ASCII on today's machines and you can still search for stuff - that's the main reason I use PDF and not PS.
Convert all PNG images in directory to JPEG using ImageMagick, and delete the old PNG images.
This uses mpg123 to convert the files to wav before burning, but you can use mplayer or mencoder or ffmpeg or lame with the --decode option, or whatever you like.
remove files with access time older than a given date.
If you want to remove files with a given modification time replace %[email protected] with %[email protected] Use %[email protected] for the modification time.
The time is expressed in epoc but is easy to use any other format.
This command creates and burns a gapless audio CD with 99 tracks. Each track is a 30 second sine wave, the first is 1 Hz, the second 2 Hz, and so on, up to 99 Hz. This is useful for testing audio systems (how low can your bass go?) and for creating the constant vibrations needed to make non-Newtonian fluids (like cornstarch and water) crawl around.
Note, this temporarily creates 500MB of .cdda files in the current directory. If you don't use the "rm" at the end of the command, you can burn more disks using
cdrdao write cdrdao.toc
Prerequisites: a blank CD-R in /dev/cdrw, sox (http://sox.sourceforge.net/), and cdrdao (http://cdrdao.sourceforge.net/). I'm also assuming a recent version of bash for the brace expansion (which just looks nicer than using seq(1), but isn't necessary).
Note the space before the command; that prevents your history eliminating command from being recorded. ' history -c && rm -f ~/.bash_history' Both steps are needed. 'history -c' clears what you see in the history command. 'rm -f ~/.bash_history' deletes the history file in your home directory.
For all of the jpgs in a directory, determine their size and if below a threshold remove them forcefully.
plays with bash arrays. instead of storing the list of files in a temp file, this stores the list in ram, retrieves the last element in the array (the last html file), then removes it.
Converts a .vdi file to a .vmdk file for use in a vmware virtual machine. The benefit: using this method actually works. There are others out there that claim to give you a working .vmdk by simply using the qemu-img command alone. Doing that only results in pain for you because the .vmdk file will be created with no errors, but it won't boot either.
Be advised that these conversions are very disk-intensive by nature; you are probably dealing with disk images several gigabytes in size.
Once finished, the process of using the new .vmdk file is left as an exercise to the reader.
Some malicious program appends a iframe or script tag to you web pages on some server, use this command to clean them in batch.
Check out the usage of 'trap', you may not have seen this one much. This command provides a way to schedule commands at certain times by running them after sleep finishes sleeping. In the example 'sleep 2h' sleeps for 2 hours. What is cool about this command is that it uses the 'trap' builtin bash command to remove the SIGHUP trap that normally exits all processes started by the shell upon logout. The 'trap 1' command then restores the normal SIGHUP behaviour.
It also uses the 'nice -n 19' command which causes the sleep process to be run with minimal CPU.
Further, it runs all the commands within the 2nd parentheses in the background. This is sweet cuz you can fire off as many of these as you want. Very helpful for shell scripts.
Best way I know to get rid of .bash_history and don't allow bash to save the current one on exit
Edit: added ~/ before .bash_history, just in case... ;)
this string of commands will release your dhcp address, change your mac address, generate a new random hostname and then get a new dhcp lease.