Commands by hans (3)

What's this? is the place to record those command-line gems that you return to again and again. 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.

Share Your Commands

Check These Out

get the oldest file in a directory
reverse the sorting of ls to get the newest file: $ls -1tr --group-directories-first /path/to/dir/ | tail -n 1 Problems: If there are no files in the directory you will get a directory or nothing.

back ssh from firewalled hosts
host B (you) redirects a modem port (62220) to his local ssh. host A is a remote machine (the ones that issues the ssh cmd). once connected port 5497 is in listening mode on host B. host B just do a ssh -p 5497 -l user and reaches the remote host'ssh. This can be used also for vnc and so on.

Securely destroy data on given device
Intentional hash in the beginning. May run a looong time. Wipes your data for real. Was meant to be /dev/urandom - I mistyped it. :-)

Find the package that installed a command

print java packages by using unix tree and sed
if you need a quick way of printing out all the packages that contain classes this command will print the directory structure and replace '/' with '.' It will also ignore CVS directories (we use CVS here)

Cut/Copy everything arround brackets or parentheses on vim (in normal mode)
Put the cursor on either curly braces ( {, } ). Then press d% The d is delete command, and % is movement command that move the cursor to another matching parentheses (or curly braces in this case). This action will delete every character that was on the way of the movement (from the first curly braces to the second).

Test file system performance
You need bonnie++ package for this. More detail than a simple hdparm -t /dev/sda would give you. the -d is the directory where it performs writes/reads for example I use /tmp/scratch with 777 permissions Bonnie++ benchmarks three things: data read and write speed, number of seeks that can be performed per second, and number of file metadata operations that can be performed per second.

Quickly generate an MD5 hash for a text string using OpenSSL
Here Strings / A variant of here documents, the format is:

disable caps lock
a quick one-line way to disable caps lock while running X.

Apply permissions only to files
To apply only to dirs: $ chmod 755 $(find . -type d) Use -R parameters for recursive walk.

Stay in the loop…

Follow the Tweets.

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.


Subscribe to the feeds.

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: