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.
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:
if you cd into a directory then cd into another directory somewhere else then you run the cd - command you will go to the previous directory you was in!! To go back to the other directory just run it again. So if you are working in 2 different directories then this is the perfect command for you.
Since none of the systems I work on have readlink, this works cross-platform (everywhere has perl, right?).
Note: This will resolve links.
I did not like two things in the submitted commands and fixed it here:
1) If I do cd - afterwards, I want to go back to the directory I've been before
2) If I call up without argument, I expect to go up one level
It is sad, that I need eval (at least in bash), but I think it's safe here.
eval is required, because in bash brace expansion happens before variable substitution, see http://rosettacode.org/wiki/Repeat_a_string#Using_printf
I realise that this is just a reiteration of another entry (regardless of whether I came up with all this all by myself), but I would like present my additional alias' in context as a method of managing your directories. Rather convenient.
An easy method to generate ISOs from CD/DVD media.
as alternative to cd $OLDPWD
Use shopt -s cdspell to correct the typos in the cd command
manage directory stack
switch to previous directory or toggle
Creates a directory and then cds into it directly
`up 3` will climb the directory tree by three steps. `up asdf` will do nothing, and returns exit code 1 as an error should.
I wrote this a long time ago, wondering why this wasn't floating around somewhere out there (at least not where I could find).. this seems much more simple than multiple aliases and can cd out of directories easier.
Change n directories up, without parameters change one up
This is like `cd -` but doesn't echo the new directory name, which is preferable (to me) for an alias, e.g.
alias cdo="cd $OLDPWD"
work for execute file
Also resolves symlinks, showing the full path of the link target
Sometimes you need the full path to your script, regardless of how it was executed (which starting directory) in order to maintain other relative paths in the script.
If you attempt to just use something simple like:
you will only get the relative path depending on where you first executed the script from.
You can get the relative path to the script (from your starting point) by using dirname, but you actually have to change directories and print the working directory to get the absolute full path.
Usage: upto directory
Usage: jd dir
Requires globstar. To set globstar use:
shopt -s globstar
The biggest advantage of this over the functions is that it is portable.
Put the function in your .bashrc and use "map [alias]" to create the alias you want. Just be careful to not override an existing alias.
Move efficiently between directories.
This command adds a couple of extra features to cd, without affecting normal use.
CDPATH use is also unaffected. It introduces and environment variable CDDIR which is used as an alternate home directory.
Note: I don't want to alter $HOME because then all my dot files will move.
Change directory to "dir" (using CDPATH if necessary)
Change directory to "dir" (containing folder of "file.txt")
This allows you to cut'n'paste, or use
CDDIR is unset
Change directory to $HOME
Change directory to /home/flatcap/work
For convenience, put the command, and the following, in your .bashrc or .bash_profile
I submitted a command like this without $0 if $BASH_SOURCE is unset. Therefor, it did only work when using ./script, not using 'sh script'. This version handles both, and will set $mydir in a script to the current working directory. It also works on linux, osx and probably bsd.