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:
sudo pmset -a hibernatemode 1 sets hiberate on.
sudo pmset -a hibernatemode 0 sets hibernate off.
from the pmset man page:
0001 (bit 0) enables hibernation; causes OS X to write memory state to
hibernation image at sleep time. On wake (without bit 1 set) OS X will
resume from the hibernation image. Bit 0 set (without bit 1 set) causes
OS X to write memory state and immediately hibernate at sleep time.
I often change my MacBook's sleep state. So I created a function for bash to make it a little easier.
Usage:
hibernate (on | off)
"hibernate on" will set your laptop to hibernate if the lid is closed.
"hibernate off" will set your laptop to sleep if the lid is closed.
### note : "proper" indentation isn't preserved on the website
function hibernate()
{
case "${1}" in
on)
sudo pmset -a hibernatemode 1
echo Hibernate mode on.
;;
off)
sudo pmset -a hibernatemode 0
echo Hiberate mode off.
;;
*)
echo "I'm sorry Dave, but I can't do that."
;;
esac
}
To make things easier, add the proper line in your /etc/sudoers file so that your user may invoke pmset without a password. Here's how mine looks:
bwayne luna = NOPASSWD: /usr/bin/pmset
Don't forget that you must edit sudoers with `sudo visudo` from Terminal.app, and not by another text editor.
Sorry this is so Mac OS specific.
Bulk downloads the comic strip JPG files for the adult cartoon Savitabhabhi, storing each set in it's own folder. Requires manual removal of "non-image" files that maybe created because each series may differ in length. The command can be easily adapted for UNIX flavours. You need to have cURL in your path.
This must be run the first time while logged into your Mac desktop, as it will graphically prompt for access permissions. Subsequent uses will not prompt, assuming you select "Always allow".
Counts Mysql Threads
mysql switches
-N skip column names (remove headers)
-s silent mode (removes separator chars)
-r raw output
-e execute
grep switches
-c count lines
-v invert match (match all except)
Very useful for finding all the source code that should be compiled.
Here $HOME/shots must exist and have appropriate access rights and sitecopy must be correctly set up to upload new screen shots to the remote site.
Example .sitecopyrc (for illustration purposes only)
site shots
server ftp.example.com
username user
password antabakadesuka
local /home/penpen/shots
remote public_html/shots
permissions ignore
The command uses scrot to create a screen shot, moves it to the screen shot directory, uploads it using screen uses xsel to copy the URL to the paste buffer (so that you can paste it with a middle click) and finally uses feh to display a preview of the screen shot.
Note that $BASE stands for the base URL for the screen shots on the remote server, replace it by the actual location; in the example http://www.example.com/~user/shots would be fitting.
Assign this command to a key combination or an icon in whatever panel you use.
awk extract every nth line.
Generic is:
awk '{if (NR % LINE == POSITION) print $0}' foo
where "last" position is always 0 (zero).
You must spezify /where folder and / folder
If you have another camera you must experiment with Exif data (after -g and after grep) and mask of your photo files IMG_????.JPG
I have do it on Knoppix 6.7.0
You must have installed exiv2.
you can use a pair of commands to test firewalls.
1st launch this command at destination machine
ncat -l [-u] [port] | cat
then use this command at source machine to test remote port
echo foo | ncat [-u] [ip address] [port]
First command will listen at specified port.
It will listen TCP. If you use -u option will listen UDP.
Second command will send "foo" through ncat and will reach defined IP and port.
The J option is a recent addition to GNU tar. The xz compression utility is required as well.
polls the pirate bay mirrors list and chooses a random site and opens it for you in firefox
Can use a cookie from Rapidshare, as created by the command on http://www.commandlinefu.com/commands/view/1756/download-from-rapidshare-premium-using-wget-part-1
!! will expand to your previous command, thus creating the alias "foo" (does not work consistently for commands with quotation marks)
This particular combination of flags mimics Try CoffeeScript (on http://coffeescript.org/#try:) as closely as possible. And the `tail` call removes the comment `// Generated by CoffeeScript 1.6.3`.
See `coffee -h` for explanation of `coffee`'s flags.
This is a handy way to find which modules are loaded with Apache web server.
`tar xfzO` extracts to STDOUT which got redirected directly to mysql. Really helpful, when your hard drive can't fit two copies of non-compressed database :)
Today many hosts are blocking traditional ICMP echo replay for an "security" reason, so nmap's fast ARP scan is more usable to view all live IPv4 devices around you. Must be root for ARP scanning.
Calculate foldersize for each website on an ISPConfig environment. It doesn't add the jail size. Just the "public_html".
# Limited and very hacky wildcard rename
# works for rename *.ext *.other
# and for rename file.* other.*
# but fails for rename file*ext other*other and many more
# Might be good to merge this technique with mmv command...
mv-helper() {
argv="`history 1 | perl -pe 's/^ *[0-9]+ +[^ ]+ //'`"
files="`echo \"$argv\"|sed -e \"s/ .*//\"`"
str="`history 1 | perl -pe 's/^ *[0-9]+ +[^ ]+ //' | tr -d \*`"
set -- $str
for file in $files
do
echo mv $file `echo $file|sed -e "s/$1/$2/"`
mv $file `echo $file|sed -e "s/$1/$2/"`
done
}
alias rename='mv-helper #'
To get information at your fingertips about Apache compilation.