Commands by johnlane (1)

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

Backup with versioning
Apart from an exact copy of your recent contents, also keep all earlier versions of files and folders that were modified or deleted. Inspired by the excellent EVACopy

Use tagged vlans
Great for sysadmins! Don't forget to pass the vlan to your port in a manageable switch. After vconfig, you should use $sudo ifconfig eth0.[VID] up Now the interface is up, you can use dhclient or ifconfig again to get an ip address.

Happy Days
AFAIR this is the wording ;)

Recursive Line Count
We use `-not -name ".*"` for the reason we must omit hidden files (which unnecessary). We can only show up total lines like this: $ find * -type f -not -name ".*" | xargs wc -l | tail -1

Unpack .tgz File On Linux
With -a you don't care about file type (bz2, gzip, etc.)

Most used command

Human readable directory sizes for current directory, sorted descending

View all date formats, Quick Reference Help Alias
If you have used bash for any scripting, you've used the date command alot. It's perfect for using as a way to create filename's dynamically within aliases,functions, and commands like below.. This is actually an update to my first alias, since a few commenters (below) had good observations on what was wrong with my first command. # creating a date-based ssh-key for $ ssh-keygen -f ~/.ssh/`date [email protected]$HOSTNAME-%m-%d-%g` -C '[email protected]' $ # /home/gpl/.ssh/[email protected] # create a tar+gzip backup of the current directory $ tar -czf $(date +$HOME/.backups/%m-%d-%g-%R-`sed -u 's/\//#/g'

Replace multiple file extensions with a single extension
The above is just a prove of concept based around the nested bash substitution. This could be useful in situations where you're in a directory with many filetypes but you only want to convert a few. $ for f in *.bmp *.jpg *.tga; do convert $f ${f%.*}.png; done or you can use ls | egrep to get more specific... but be warned, files with spaces will cause a ruckus with expansion but the bash for loop uses a space delimited list. $ for f in $(ls | egrep "bmp$|jpg$|tga$"); do convert $f ${f%.*}.png; done I'm guessing some people will still prefer doing it the sed way but I thought the concept of this one was pretty neat. It will help me remember bash substitutions a little better :-P

Create a new file

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: