Commands tagged expansion (7)

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

cd into another dir to run a one-liner, but implicitly drop back to your $OLD_PWD after
Obviously the example given is necessarily simple, but this command not only saves time on the command line (saves you using "cd -" or, worse, having to type a fully qualified path if your command cd's more than once), but is vital in scripts, where I've found the behaviour of "cd -" to be a little broken at times.

Backup of a partition
Clone a partion with tar.

Convert GoogleCL gmail contacts to cone adress book
Full Command: $ google contacts list name,name,email|perl -pne 's%^((?!N\/A)(.+?)),((?!N\/A)(.+?)),([a-z0-9\._-]+\@([a-z0-9][a-z0-9-]*[a-z0-9]\.)+([a-z]+\.)?([a-z]+))%${1}:${3} %imx'|grep -oP '^((?!N\/A)(.+?)) ' | sort You'll need googlecl and python-gdata. First setup google cl via: $ google Then give your PC access $ google contacts list name,email Then do the command, save it or use this one to dump it in the cone-address.txt file in your home dir: $ google contacts list name,name,email | perl -p -n -e 's%^((?!N\/A)(.+?)),((?!N\/A)(.+?)),([a-z0-9\._-]+\@([a-z0-9][a-z0-9-]*[a-z0-9]\.)+([a-z]+\.)?([a-z]+))%${1}:${3} %imx' | grep -o -P '^((?!N\/A)(.+?)) ' | sort > ~/cone-adress.txt Then import into cone. It filters out multiple emails, and contacts with no email that have N/A. (Picasa photo persons without email for example...)

Determine space taken by files of certain type
Just how much space are those zillions of database logs taking up ? How much will you gain on a compression rate of say 80% ? This little line gives you a good start for your calculations.

How to pull out lines between two patterns
This command will display all lines between 2 patterns: word-a and word-b useful for grepping command outputs from file

find out how many days since given date
Exactly the same number of characters, exactly the same results, but with bc

Get your current Public IP

Multi-line grep
Using perl you can search for patterns spanning several lines, a thing that grep can't do. Append the list of files to above command or pipe a file through it, just as with regular grep. If you add the 's' modifier to the regex, the dot '.' also matches line endings, useful if you don't known how many lines you need are between parts of your pattern. Change '*' to '*?' to make it greedy, that is match only as few characters as possible. See also to do a similar thing with awk. Edit: The undef has to be put in a begin-block, or a match in the first line would not be found.

Grep recursively for a pattern and open all files that match, in order, in Vim, landing on 1st match

Octal ls
Do ls with permissions written in octal form.

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: