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.
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:
This command dumps all SVN repositories inside of folder "repMainPath" (not recursively) to the folder "dumpPath", where one dump file will be created for each SVN repository.
search argument in PATH
accept grep expressions
without args, list all binaries found in PATH
This command displays a simple menu of file names in the current directory. After the user made a choice, the command invokes the default editor to edit that file.
* Without the break statement, the select command will loop forever
* Setting the PS3 prompt is optional
* If the user types an invalid choice (such as the letter q), then the variable $f will become an empty string.
* For more information, look up the bash's select command
This version uses Pipes, but is easier for the common user to grasp... instead of using sed or some other more complicated method, it uses the tr command
When using reverse-i-search you have to type some part of the command that you want to retrieve. However, if the command is very complex it might be difficult to recall the parts that will uniquely identify this command. Using the above trick it's possible to label your commands and access them easily by pressing ^R and typing the label (should be short and descriptive).
UPDATE:
One might suggest using aliases. But in that case it would be difficult to change some parts of the command (such as options, file/directory names, etc).
This is the way how you can find header and cpp files in the same time.
Based on the MrMerry one, just add some visuals to differentiate files and directories
Based on the MrMerry one, just add some visuals and sort directory and files
checkfor: have the shell check anything you're waiting for.
'while : ; do' is an infinite loop
'$*' executes the command passed in
'sleep 5' - change for your tastes, sleep for 5 seconds
bash, ksh, likely sh, maybe zsh
Ctrl-c to break the loop
fcd : file change directory
A bash function that takes a fully qualified file path and cd's into the directory where it lives. Useful on the commadline when you have a file name in a variable and you'd like to cd to the directory to RCS check it in or look at other files associated with it.
Will run on any ksh, bash, likely sh, maybe zsh.
If you need to ssh into a computer on the local network but you're unsure of the ip to use, then ping them and see if you get a response. If you do, print out the address you got it from. Adjust the range to suit your network.
"&&" runs sed if and only if the backup completed and /bin/cp exited cleanly. Works for multiple files; just specify multiple filenames (or glob). Use -v switch for cp to play it safe.
The coolest way I've found to backup a wordpress mysql database using encryption, and using local variables created directly from the wp-config.php file so that you don't have to type them- which would allow someone sniffing your terminal or viewing your shell history to see your info.
I use a variation of this for my servers that have hundreds of wordpress installs and databases by using a find command for the wp-config.php file and passing that through xargs to my function.
Best to put it in a file somewhere in your path. (I call the file spath)
#!/bin/bash
IFS=:; find $PATH | grep $1
Usage: $ spath php
The original doesn't work for me - but this does. I'm guessing that Youtube updated the video page so the original doesn't work.
( IFS=:; for i in $PATH; do echo $i; done; )
echo $PATH|sed -e 's/:/\n/g' # but the tr one is even better of course
echo $PATH|xargs -d: -i echo {} # but this comes up with an extra blank line; can't figure out why and don't have the time :(
echo $PATH|cut -d: --output-delimiter='
' -f1-99 # note -- you have to hit ENTER after the first QUOTE, then type the second one. Sneaky, huh?
echo $PATH | perl -l -0x3a -pe 1 # same darn extra new line; again no time to investigate
echo $PATH|perl -pe 's/:/\n/g' # too obvious; clearly I'm running out of ideas :-)
This command allows you to see a preview of a picture via the terminal. It can be usefull when you are ssh'ing your server without X-forwarding.
To have en example of the output you can get with this command see http://www.vimeo.com/3721117
Download at http://inouire.net/image-couleur.html
Sources here: http://inouire.net/archives/image-couleur_source.tar.gz
In Bash, when defining an alias, one usually loses the completion related to the function used in that alias (that completion is usually defined in /etc/bash_completion using the complete builtin).
It's easy to reuse the work done for that completion in order to have smart completion for our alias.
That's what is done by this command line (that's only an example but it may be very easy to reuse).
Note 1 : You can use given command line in a loop "for old in apt-get apt-cache" if you want to define aliases like that for many commands.
Note 2 : You can put the output of the command directly in your .bashrc file (after the ". /etc/bash_completion") to always have the alias and its completion
Uses the last argument of the last executed command, and gets the directory name from it.
Use $!:t for the filename alone, without the dirname.