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:
Allows to copy the file contents to X clipboard, and then be pasted in any application with the middle mouse button.
Write a file you edited in Vim but that you do not have the permissions to write to (unless you use sudo.) Same as #1204 but without the echo to stdout that I find annoying.
This makes an alias for a command named 'busy'. The 'busy' command opens a random file in /usr/include to a random line with vim. Drop this in your .bash_aliases and make sure that file is initialized in your .bashrc.
Assuming only VIM has *~ files in your current dir. If you have usefull data in a file named in the *~ pattern, DO NOT RUN this command!
You can use
vim scp://root@example.com//file
too in a simple case.
Because entering ':' requires that you press shift, sometimes common command-line / mini-buffer commands will be capitalized by accident.
A really fun vim oneliner for auto documenting your option's parsing in your script.
# print the text embeded in the case that parse options from command line.
# the block is matched with the marker 'CommandParse' in comment, until 'esac'
extract_cmdl_options()
{
# use vim for parsing:
# 1st grep the case block and copy in register @p + unindent in the buffer of the file itself
# 2nd filter lines which start with --opt or +opt and keep comment on hte following lines until an empty line
# 3rd discard changes in the buffer and quit
vim -n -es -c 'g/# CommandParse/+2,/^\s\+esac/-1 d p | % d | put p | %
-c 'g/^\([-+]\+[^)]\+\))/,/^\(\s\+[^- \t#]\|^$\)/-1 p' \
-c 'q!' $0
}
example code:http://snipplr.com/view/25059/display-embeded-comments-for-every-opt-usefull-for-auto-documenting-your-script/
For vi(m) users :
Add it in your ~/.bashrc
Add an "exit" @ the end if you are masochist ;)
Put this in your ~/.bashrc file (or the equivalent)
If you use vim a lot, this alias will be immediately obvious. Your brain will thank you.
If you are in ex mode in vim i.e. you've pressed ':'. You can edit the current command by pressing <ctrl-f>
This will diff your local version of the file with the latest version in svn. I put this in a shell function like so:
svd() { vimdiff <(svn cat "$1") "$1"; }
Make sure that find does not touch anything other than regular files, and handles non-standard characters in filenames while passing to xargs.
needs no GNU tools, as far as I see it
saves one command. Needs GNU grep though :-(
The grep switches eliminate the need for awk and sed. Modifying vim with -p will show all files in separate tabs, -o in separate vim windows. Just wish it didn't hose my terminal once I exit vim!!
This will drop you into vim to edit all files that contain your grep string.
By using vim, you can also filter content on stdout, using vim's extra power, like search pattern offset!
No more awk of course, sorry.
details :
-e ex mode
-s silent
-c 'ex command' : global + start and end pattern + offset print (p)
-cq : quit
Whereas ^V is CTRL-V.
converts a dos file to unix by removing 0x13 characters