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:
Multi-argument version, but with VIM loveliness :D
you should choose proper color to make comments invisible.
Enhancement for the 'busy' command originally posted by busybee : less chars, no escape issue, and most important it exclude small files ( opening a 5 lines file isn't that persuasive I think ;) )
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.
Takes the same arguments that ack does. E.g. ack-open -i "searchterm" opens all files below the current directory containing the search term. The search term is also highlighted within vim if you have hlsearch set. Works on zsh, unsure if it works on bash.
Note: ubuntu users have to change ack to ack-grep unless you already have it aliased (as I do)
Some people put spaces in filenames. Others have an $EDITOR environment variable set. This defaults to vim, but you can use whatever you wish: emacs, nano, ed, butterflies, etc.
In this case, we'll be editing every PHP file from the current location down the tree.
You can show all the files in the vim buffer with :buffers which outputs something like,
:buffers
1 %a "./config/config.php" line 1
2 "./lib/ws-php-library.php" line 0
3 "./lib/css.php" line 0
4 "./lib/mysqldb.class.php" line 0
5 "./lib/config.class.php" line 0
6 "./lib/actions.php" line 0
Press ENTER or type command to continue
If you'd like to edit ./lib/mysqldb.class.php for example, enter :b4 anytime you're editing a file. You can switch back and forth.
The sample command searches for PHP files replacing tabs with spaces.
-u NONE # don't use vimrc
Instead of
retab!
one may pass
retab! 4
for instance.
Look at this http://susepaste.org/69028693 also
This will skip all initializations. Especially useful when your ~/.vimrc has something wrong.
The first argument is the interpreter for your script, the second argument is the name of the script to create.
This is one of those 'nothing' shell functions ...which I use all the time.
If the command contains spaces, it must be quoted, e.g.
vimcmd 'svn diff' /tmp/svndiff.out
If I want to keep the output of the command that I'm running, I use vimcmd. If I don't need to keep the output, I use this:
vim <( ... my command ... )
Checks the apache configuration syntax, if is OK then restart the service otherwise opens the configuration file with VIM on the line where the configuration fails.
This will save and execute your python script every time your press the F5 function key.
It can also be added to your .vimrc:
autocmd BufRead *.py nmap :w^M:!python %
NOTE: the ^M is not just caret-M, it can be created by type: ctrl-v ctrl-m
Like the http://www.commandlinefu.com/commands/view/6327/open-file-with-sudo-when-there-is-no-write-permission, but works (in zsh; my commandlinefu is not strong enough to understand why bash don't like it) with vim options, like -O, and many input files.
There could be other mistakes.
this avoids several VIM warnings, which I seem too stupid to disable: warning, readonly! and: file and buffer have changed, reload?!
the second command 'vim !$' will open test.txt to edit
The above output is for a custom compiled version of Vim on Arch Linux.
Just a quick shell one liner, and presents a list of all the enabled and disabled (those prefixed with a '-') features.
this is great if you loose you ssh connection (with out a screen session) or are working on a laptop with a bad battery, or just a power outage.
Modifications: you may not need the -print; the mtime is last modified time in days
vix /tmp/script.sh
Open a file directly with execution permission.
Put the function in your .bashrc
You can also put this in your vimrc:
command XX w | set ar | silent exe "!chmod +x %" | redraw!
and open a new file like this:
vi +XX /tmp/script.sh
Catches .swp, .swo, .swn, etc.
If you have access to lsof, it'll give you more compressed output and show you the associated terminals (e.g., pts/5, which you could then use 'w' to figure out where it's originating from): lsof | grep '\.sw.$'
If you have swp files turned off, you can do something like: ps x | grep '[g,v]im', but it won't tell you about files open in buffers, via :e [file].