commandlinefu.com is the place to record those command-line gems that you return to again and again.
Delete that bloated snippets file you've been using and share your personal repository with the world. 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.
If you have a new feature suggestion or find a bug, please get in touch via http://commandlinefu.uservoice.com/
You can sign-in using OpenID credentials, or register a traditional username and password.
First-time OpenID users will be automatically assigned a username which can be changed after signing in.
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
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:
Files containing ascii art (e.g. with .nfo extension) are typically not correctly reproduced at the command line when using cat. With iconv one can easily write a wrapper to solve this:
#!/bin/bash
if [ -z "$@" ]; then echo "Usage: $(basename $0) file [file] ..."
else iconv -f437 -tutf8 "$@"; fi
exit 0
print multiple increasing years using cal - calendar -. You can also try
seq Start Increment End
gemInst.sh:
#!/bin/bash
for i in $@; do
if [ "$1" != "$i" ]
then
echo /newInstall/gem install $1 -v=\"$i\"
/newInstall/gem install $1 -v="$i"
if [ "$?" != "0" ]
then
echo -e "\n\nGEM INSTALL ERROR: $1\n\n"
echo "$1" > gemInst.err
fi
fi
done
When you use a "for" construct, it cycles on every word. If you want to cycle on a line-by-line basis (and, well, you can't use xargs -n1 :D), you can set the IFS variable to .
Generates a frequency sweep from $x to $y, with $d numbers inbetween each step, and with each tone lasting $l milliseconds.
defines a handy function for quick calculations from cli.
once defined:
? 10*2+3
Useful if non-ascii characters in filenames have been improperly encoded. Replace "PROBLEM" with the incorrect characters (e.g. 'é'), and "FIX" with the correct ones (e.g. '?').
If you should happen to find yourself needing some binary numbers, this is a quickie way of doing it. If you need more digits, just add more "{0..1}" sequences for each digit you need. You can assign them to an array, too, and access them by their decimal equivalent for a quickie binary to decimal conversion (for larger values it's probably better to use another method). Note: this works in bash, ksh and zsh. For zsh, though, you'll need to issue a setopt KSH_ARRAYS to make the array zero-based.
binary=({0..1}{0..1}{0..1}{0..1})
echo ${binary[9]}
curl doesn't provide url-encoding for 'GET' data, it have an option '--data-urlencode', but its only for 'POST' data. Thats why I need to write down this commandline. With 'perl', 'php' and 'python', this is one liner, but just I wrote it for fun. Works in Ubuntu, will work in all linux varients(I hope it will work in unix varients also).
Chronic Bash function:
chronic 3600 time # Print the time in your shell every hour
chronic 60 updatedb > /dev/null # update slocate every minute
Note: use 'jobs' to list background tasks and fg/bg to take control of them.
Useful for use in other scripts for renaming, testing for extensions, etc.
Lists revisions in a Subversion repository with a timestamp that doesn't follow the revision numbering order. If everything is OK, nothing is displayed.
Print out list of all branches with last commit date to the branch, including relative time since commit and color coding.
exported files will get a .r23 extension (where 23 is the revision number)
echo "http%3A%2F%2Fwww.google.com" | sed -e's/%\([0-9A-F][0-9A-F]\)/\\\\\x\1/g' | xargs echo -e
Works under bash on linux. just alter the '-e' option to its corresponding equivalence in your system to execute escape characters correctly.
It can be hard to spot differences in reformatted files, because of all the diff noise created by word wrapped lines. This command removes all the noise and performs a word-by-word diff. To ignore empty lines, add -B to the diff command. Also, if this is something you do often, you might want to check out the wdiff(1) program.
This uses Bash's "process substitution" feature to compare (using diff) the output of two different process pipelines.
This command create a new temp directory using mktemp (to avoid collisions) and change the current working directory to the created directory.
With this command you can use shell variables inside sed scripts.
This is useful if the script MUST remain in an external file, otherwise you can simply use an inline -e argument to sed.
This opens up nautilus in the current directory, which is useful for some quick file management that isn't efficiently done from a terminal.
The colors are defined as variables.
e.g.
RED="\[\033[01;31m\]"
BLUE="\[\033[01;34m\]"
Since bash 4.0, you can use ** to recursively expand to all files in the current directory. This behaviour is disabled by default, this command enables it (you'd best put it in your .profile). See the sample output for clarification.
In my opinion this is much better than creating hacks with find and xargs when you want to pass files to an application.
This is the alias command that I discussed in my prior release which you can add to your ~/.bashrc.
This command asks for the station name and then connects to somafm, Great for those who have linux home entertainment boxes and ssh enabled on them, just for the CLI fiends out there ( I know I'm one of them ;)
You can find future releases of this and many more scripts at the teachings of master denzuko - denzuko.co.cc.