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:
Although Exim will purge frozen (undeliverable) messages over time, the command "exim -Mrm #id#" where #id# is a particular message ID will purge a message immediately. Being lazy, I don't want to type the command for each frozen message, so I wrote the one-liner to do it for me.
combines mkdir and cd
added quotes around $_, thanx to flatcap!
With counter format [001, 002, ..., 999] , nice with pictures or wallpapers collections.
Recursively rename .JPG to .jpg using standard find and mv. It's generally better to use a standard tool if doing so is not much more difficult.
In bash, by pressing ALT+n and then a character x, x will be printed n times
I know is not the same as the original command, but is correlated.
sed already has an option for editing files in place and making backup copies of the old file. -i will edit a file in place and if you give it an argument, it will make a backup file using that string as an extension.
Quick and easy way to find out which php.ini file is being used. Especially useful if you just need to find the location of the file for editing purposes.
A really fun vim oneliner for auto documenting your option's parsing in your script.
# print the text embeded in the case that parse options from command line.
# the block is matched with the marker 'CommandParse' in comment, until 'esac'
extract_cmdl_options()
{
# use vim for parsing:
# 1st grep the case block and copy in register @p + unindent in the buffer of the file itself
# 2nd filter lines which start with --opt or +opt and keep comment on hte following lines until an empty line
# 3rd discard changes in the buffer and quit
vim -n -es -c 'g/# CommandParse/+2,/^\s\+esac/-1 d p | % d | put p | %
-c 'g/^\([-+]\+[^)]\+\))/,/^\(\s\+[^- \t#]\|^$\)/-1 p' \
-c 'q!' $0
}
example code:http://snipplr.com/view/25059/display-embeded-comments-for-every-opt-usefull-for-auto-documenting-your-script/
Manpages, command summaries, and pretty much everything else usually have the information you're most likely to want at the beginning. Seeing just the last 40 or so lines of options from a command that has 100 is not super useful, and having to scroll up each time you want to glance at something is spastic.
Run this and then do something like
p do vi --help
and you'll get the first screen(-mostly-)full of vi's usage info and options list
Then use
p d
to page down, and
p u
to page up.
To see the current page again:
p r
Also useful for situations like
p do aptitude search ~dsmorgasbord
p next
#p sudo aptitude -r install libwickedawesome-perl-snoochieboochies
p next
p sudo aptitude -r install libwickedawesome-perl-snoochieboochies snazztasticorama-dev-v0.∞
where you're using readline up-arrow, HOME, END, etc., to quickly recall commented commands.
For the unaware, that option to aptitude search will bring up all of the packages whose descriptions contain the string "smorgasbord". Depending on your distro, there could potentially be hundreds of them.
Displays a scrolling banner which loops until you hit Ctrl-C to terminate it.
Make sure you finish your banner message with a space so it will loop nicely.
If you have some drive imaging to do, you can boot into any liveCD and use a commodity machine. The drives will be written in parallel.
To improve efficiency, specify a larger block size in dd:
dd if=/dev/sda bs=64k | tee >(dd of=/dev/sdb bs=64k) | dd of=/dev/sdc bs=64k
To image more drives , insert them as additional arguments to tee:
dd if=/dev/sda | tee >(dd of=/dev/sdb) >(dd of=/dev/sdc) >(dd of=/dev/sdd) | dd of=/dev/sde
Hi glaudiston, you can save a few chars by leaving out cat and pipe and still enjoy the added flexibility.
Execute this in the root of your music library and this recurses through the directories and normalizes each folder containing mp3s as a batch. This assumes those folders hold an album each. The command "normalize-audio" may go by "normalize" on some systems.
If you are interested in interfaces other than eth0 you will need to change eth0 to your interface name.
You could use this mammoth to nab the ip4 addresses of all your interfaces
perl -e '@_=`ifconfig -a`; sort(@_); foreach(@_) { /(inet addr\:)(\d+.\d+.\d+.\d+ )/; $_=$2; @uniq=grep($_ ne $prev && (($prev) = $_), @_);} print join "\n",@uniq,"\n"; '
it seems silly to have all this code when the following will work fine
ifconfig -a | grep "inet " | awk -F":" ' { print $2 } ' | cut -d " " -f1
You can use [n]> combined with >(cmd) to attach the various output file descriptors to be the input of different commands.
if you still get a permissions error using sudo, then nano the file:
sudo nano -w /sys/block/sdb/queue/rotational
and change 1 to 0
this thread:
http://www.ocztechnologyforum.com/forum/showpost.php?p=369836&postcount=15
says that this will "help the block layer to optimize a few decisions"
The iostat command is used for monitoring system input/output device loading by observing the time the devices are active in relation to their average transfer rates.
in ubuntu to get the iostat program do this:
sudo apt-get install sysstat
i found this command here:
http://www.ocztechnologyforum.com/forum/showthread.php?t=54379
This function displays the latest comic from xkcd.com. One of the best things about xkcd is the title text when you hover over the comic, so this function also displays that after you close the comic.
To get a random xkcd comic, I also use the following:
xkcdrandom(){ wget -qO- dynamic.xkcd.com/comic/random|tee >(feh $(grep -Po '(?<=")http://imgs[^/]+/comics/[^"]+\.\w{3}'))|grep -Po '(?<=(\w{3})" title=").*(?=" alt)';}