Commands by jtypical (5)

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

open path with your default GNOME program
Another step to bring cli and gui closer together: gnome-open It opens a path with the default (gui) application for its mime type. I would recommend a shorter alias like alias o=gnome-open More examples: $ gnome-open . [opens the current folder in nautilus / your default file browser] $ gnome-open some.pdf [opens some.pdf in evince / your default pdf viewer] $ gnome-open trash:// [opens the trash with nautilus] $ gnome-open http://www.commandlinefu.com [opens commandlinefu in your default webbrowser]

Find files and list them sorted by modification time
This uses the ability of find (at least the one from GNU findutils that is shiped with most linux distros) to display change time as part of its output. No xargs needed.

Ensure that each machine that you log in to has its own history file
On systems where your home directory is shared across different machines, your bash history will be global, rather than being a separate history per machine. This setting in your .bashrc file will ensure that each machine has its own history file.

Set file access control lists
The file myfile is owned by tom and has read and write permissions for tom. Group and other permissions are empty which make myfile readable and writable only by tom. setfacl enables user tom to give read permission to user john only. The command 'ls -l' shows a '+' sign telling us that file access control list has been setup for myfile.

vim as a pager - similar to less command but with color
use vim like less command pager but with color highlighting = pretty :p also u can use /usr/share/vim/vim73/macros/less.sh

Loop over the days of a month, in $YYYY$MM$DD format
Edit YYYY and MM at the beginning of the command with the year and month you want. Note that `DD=$(printf "%02d" $d)` will pad single digit integers with a leading zero. Substitute `echo $YYYY$MM$DD` at the end of the line with the command you want to launch, for instance script.pl --yyyymmdd $YYYY$MM$DD Also available on GitHub as bash util: https://github.com/fibo/yyyymmdd

Convert CSV to JSON
Replace 'csv_file.csv' with your filename.

Deal with dot files safely

Edit a file in vim (at the first error) if it is not well formed xml.
Validate a file using xmllint. If there are parser errors, edit the file in vim at the line of the first error.

Create a tar file with the current date in the name.
Same, but count of signs is little less :) .


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: