Commands using head (314)

What's this?

commandlinefu.com 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

Show log message including which files changed for a given commit in git.

Converts to PDF all the OpenOffice.org files in the directory
Requieres unoconv (debian package)

Title Case Files
All words of the filenames except "a", "of", "that" and "to" are capitalized. To also match words which begin with a specific string, you can use this: $ rename 's/\b((?!hello\b|t)[a-z]+)/\u$1/g' * This will capitalize all words except "hello" and words beginning with "t".

Multiline Search/Replace with Perl
from http://stackoverflow.com/questions/1030787/multiline-search-replace-with-perl added greedy trick in wildcard match (.*?) from http://www.troubleshooters.com/codecorn/littperl/perlreg.htm#Greedy

Unaccent an entire directory tree with files.
This command changes all filename and directories within a directory tree to unaccented ones. I had to do this to 'sanitize' some samba-exported trees. The reason it works might seem a little difficult to see at first - it first reverses-sort by pathname length, then it renames only the basename of the path. This way it'll always go in the right order to rename everything. Some notes: 1. You'll have to have the 'unaccent' command. On Ubuntu, just aptitude install unaccent. 2. In this case, the encoding of the tree was UTF-8 - but you might be using another one, just adjust the command to your encoding. 3. The program might spit a few harmless errors saying the files are the same - not to fear.

Convert seconds to [DD:][HH:]MM:SS
Converts any number of seconds into days, hours, minutes and seconds. sec2dhms() { declare -i SS="$1" D=$(( SS / 86400 )) H=$(( SS % 86400 / 3600 )) M=$(( SS % 3600 / 60 )) S=$(( SS % 60 )) [ "$D" -gt 0 ] && echo -n "${D}:" [ "$H" -gt 0 ] && printf "%02g:" "$H" printf "%02g:%02g\n" "$M" "$S" }

convert a line to a space

Shows how many percents of all avaliable packages are installed in your gentoo system

Mount a .iso file in UNIX/Linux
"-o loop" lets you use a file as a block device

'hpc' in the shell - starts a maximum of n compute commands modulo n controlled in parallel, using make
this oneliner uses make and it's jobserver for parallel execution of your script. The '-j' flag for make defines number of subprocesses to launch, '-f' tells make use stdin instead of Makefile. Also make have neat flag '-l', which "Specifies that no new jobs (commands) should be started if there are others jobs running and the load is at least load (a floating-point number)." Also you can use plain Makefile, for better readability: targets = $(subst .png,.jpg,$(wildcard *.png)) $(targets): echo convert $(subst .jpg,.png,$@) $@ all : $(targets)


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.

» http://twitter.com/commandlinefu
» http://twitter.com/commandlinefu3
» http://twitter.com/commandlinefu10

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: