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 have long and complicated folder names this might ease your work.
add this into .bashrc
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.
Pros: Works in all Windows computers, most updated and compatible command.
Cons: 3 liner
Replace fcisolutions.com with your site name.
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"
Somehow, i prefer forcing to rm interactively to accidently rm'ing everything...
Output of this command is the difference of recursive file lists in two directories (very quick!).
To view differences in content of files too, use the command submitted by mariusbutuc (very slow!):
diff -rq path_to_dir1 path_to_dir2
echo /mnt/*/* |sed '
case $# in
echo "usage: ff glob [sed-cmds] [--|var-name]"
_ff $1 |sed =
case $2 in
--) _ff $1 |less -SN
*) _ff $1 |sed -n ''"$2"''|tr '\n' '\040' |sed 's/.*/export '"$3"'=\"&/;s/=\" /=\"/;s/ $/\"/' > $HOME/.ff;
case $# in
s/export .*=\"/\$'"$3"' = \"/;' $HOME/.ff;\
s/export /less -n \$/;
' $a/.ff > $a/.v ;
. $a/.v ;
Another approach using ls(1)
ls -l $3 /mnt/*/$1* 2>/dev/null;
case $# in
echo "usage: lsl pat [ls-options|result-no]";
echo "usage: lsle pat [sed-cmds]"
_lsl $1 |sed =
case $2 in
-*) _lsl $1 $@;;
_lsl $1 |sed 's/.* //;
'"$2"'q' > $HOME/.lsl ;
export v=$(sed 1q $HOME/.lsl);
echo \$v = $v
echo "%s/\$/ /";
echo "s/^/export v=\"";
echo "s/ \"\$/\"";
lsl $1 -1 |sed $2 > .lsl&&
exp |ed -s .lsl >&-&&
echo \$v = $v;
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.
Let's say you have a set of files in tree A that you want duplicated to tree B while preserving their directory structure / hierarchy. (For example, you might want to copy your 'profile' model/views/controller from one Rails application to another.) The "pax" command will copy all matching files to the destination while creating any necessary directories.
Testing in a TTY terminal , not emulator .
I was surprised to find that with RedHat bash, I could not find any comment lines (begining with #) in my bash shell history. Surprised because in Mageia Linux this works. It turns out that RedHat's bash will keep comment lines if in my .bashrc, I define:
export HISTIGNORE=' cd "`*: PROMPT_COMMAND=?*?'
Why have comment lines in shell history? It's a handy and convenient way to make proto-commands (to be completed later) and for storing brief text data that is searchable in shell history.
Usage: upto directory
Usage: jd dir
Requires globstar. To set globstar use:
shopt -s globstar
This is how I've done it in the past
Simple tar pipe to be used to copy directories while including hidden files and maintaining file permissions
PmWiki stores wiki pages as Group.Name. Simply split the directory listing and count frequency of group occurances.