Watch a TiVo file on your computer.
If you are interested in interfaces other than eth0 you will need to change eth0 to your interface name. You could use this mammoth to nab the ip4 addresses of all your interfaces perl -e '@_=`ifconfig -a`; sort(@_); foreach(@_) { /(inet addr\:)(\d+.\d+.\d+.\d+ )/; $_=$2; @uniq=grep($_ ne $prev && (($prev) = $_), @_);} print join "\n",@uniq,"\n"; ' it seems silly to have all this code when the following will work fine ifconfig -a | grep "inet " | awk -F":" ' { print $2 } ' | cut -d " " -f1 Show Sample Output
Manpages, command summaries, and pretty much everything else usually have the information you're most likely to want at the beginning. Seeing just the last 40 or so lines of options from a command that has 100 is not super useful, and having to scroll up each time you want to glance at something is spastic.
Run this and then do something like
p do vi --help
and you'll get the first screen(-mostly-)full of vi's usage info and options list
Then use
p d
to page down, and
p u
to page up.
To see the current page again:
p r
Also useful for situations like
p do aptitude search ~dsmorgasbord
p next
#p sudo aptitude -r install libwickedawesome-perl-snoochieboochies
p next
p sudo aptitude -r install libwickedawesome-perl-snoochieboochies snazztasticorama-dev-v0.∞
where you're using readline up-arrow, HOME, END, etc., to quickly recall commented commands.
For the unaware, that option to aptitude search will bring up all of the packages whose descriptions contain the string "smorgasbord". Depending on your distro, there could potentially be hundreds of them.
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/ Show Sample Output
This version makes uses of Bash shell expansion, so it might not work in all other shells.
A command to find out what the day ends in. Can be edited slightly to find out what "any" output ends in. NB: I haven't tested with weird and wonderful output. Show Sample Output
Press > or < to go to the next or previous track. Space to toggle play/pause, etc. It creates a temp file descriptor. To see where the file descriptor gets created type: echo <(echo foo) This works better than running find first, then piping to mplayer with xargs or something, because that won't let you use keyboard shortcuts.
If you have lots of subversion working copies in one directory and want to see in which repositories they are stored, this will do the trick. Can be convenient if you need to move to a new subversion server. Show Sample Output
I rarely need this, but I have a hard time remembering the command when I need it. Admit it. This has happened to you. Yes this is bad, and you better clean up now. Borrowed from http://thoughtsbyclayg.blogspot.com/2008/02/how-to-delete-last-command-from-bash.html Show Sample Output
Define commands that you always invoke with an appended '&disown'. In the example:
gvim foo.txt
will open gvim dettached from the current terminal.
I wrote this script to speed up Nginx configs. This (long) one liner can be run via BASH. You will see that we set a variable in bash called 'foo' and the streamline editor (sed) finds 'bar' in 'foo.conf' next it writes that output to a temp file (foo.temp) and removes the first 5 lines (that aren't needed in this case) & lastly it moves (overwrites) foo.temp to foo.conf Show Sample Output
I used to do a lot of path manipulation to set up my development environment (PATH, LD_LIBRARY_PATH, etc), and one part of my environment wasn't always aware of what the rest of the environment needed in the path. Thus resetting the entire PATH variable wasn't an option; modifying it made sense.
The original version of the functions used sed, which turned out to be really slow when called many times from my bashrc, and it could take up to 10 seconds to login. Switching to parameter substitution sped things up significantly.
The commands here don't clean up the path when they are done (so e.g. the path gets cluttered with colons). But the code is easy to read for a one-liner.
The full function looks like this:
remove_path() {
eval PATHVAL=":\$$1:"
PATHVAL=${PATHVAL//:$2:/:} # remove $2 from $PATHVAL
PATHVAL=${PATHVAL//::/:} # remove any double colons left over
PATHVAL=${PATHVAL#:} # remove colons from the beginning of $PATHVAL
PATHVAL=${PATHVAL%:} # remove colons from the end of $PATHVAL
export $1="$PATHVAL"
}
append_path() {
remove_path "$1" "$2"
eval PATHVAL="\$$1"
export $1="${PATHVAL}:$2"
}
prepend_path() {
remove_path "$1" "$2"
eval PATHVAL="\$$1"
export $1="$2:${PATHVAL}"
}
I tried using regexes to make this into a cleaner one-liner, but remove_path ended up being cryptic and not working as well:
rp() { eval "[[ ::\$$1:: =~ ^:+($2:)?((.*):$2:)?(.*):+$ ]]"; export $1=${BASH_REMATCH[3]}:${BASH_REMATCH[4]}; };
Show Sample Output
Use this if you're using vi editing mode.
Example use :
sudo vim /root/bin/ ##uh... autocomplete doesn't work... dd sudo ls /root/bin
##ah! that's the name of the file!
<p> sudo vim /root/bin/ ##resume here! Thanks readline!
Problem arises when ebuild gets removed from portage and you end up with old and unmaintained package that you cannot find standard way. This oneliner will give you list of those packages. Show Sample Output
This is similar to using `!!` or In bash 4.1 it seems you can bind directly to a shell command, but I'm not running that version. Show Sample Output
This function displays the latest comic from xkcd.com. One of the best things about xkcd is the title text when you hover over the comic, so this function also displays that after you close the comic.
To get a random xkcd comic use the following:
xkcdrandom() { wget -qO- http://dynamic.xkcd.com/comic/random | sed -n 's#^<img src="\(http://imgs.[^"]\+\)"\s\+title="\(.\+\?\)"\salt.\+$#eog "\1"\necho '"'\2'#p" | bash; }
These are just a bit shorter than the ones eigthmillion wrote, however his version didn't work as expected on my laptop for some reason (I got the title-tag first), so these build a command which is executed by bash.
Say you want to time how long a task you're performing takes. Start this simple timer and you're done! Show Sample Output
Grabs the ip2location site and removes everything but the span tag containing the country value. Place it inside your .bashrc or .bash_aliases file. Show Sample Output
Normally the bash builtin command 'set' displays all vars and functions. This just shows the vars. Useful if you want to see different output then env or declare or export.
Alias 'sete' shows sets variables
alias sete='set|sed -n "/^`declare -F|sed -n "s/^declare -f \(.*\)/\1 ()/p;q"`/q;p"'
Alias setf shows the functions.
alias setf='set|sed -n "/^`declare -F|sed -n "s/^declare -f \(.*\)/\1 ()/p;q"`/,\$p"'
Also see: http://www.commandlinefu.com/commands/view/6899/print-all-environment-variables-including-hidden-ones
At the very least, some cool sed commands!
From my .bash_profile http://www.askapache.com/linux-unix/bash_profile-functions-advanced-shell.html
Show Sample Output
You have to install the package macchanger but this command will create a random mac from a list of known manufacturers. If you want to make a complete random mac, use the -r option .
Tested with bash v4.1.5 on ubuntu 10.10 Limitations: as written above, only works for programs with no file extention (i.e 'proggy', but not 'proggy.sh') because \eb maps to readine function backward-word rather then shell-backward-word (which is unbinded by default on ubuntu), and correspondingly for \ef. if you're willing to have Ctrl-f and Ctrl-g taken up too , you can insert the following lines into ~/.inputrc, in which case invoking Ctrl-e will do the right thing both for "proggy" and "proggy.sh". -- cut here -- \C-f:shell-backward-word \C-g:shell-forward-word "\C-e":"\C-f`which \C-g`\e\C-e" -- cut here -- Show Sample Output
http://en.wikipedia.org/wiki/Pascal%27s_triangle This one's for bartonski. Enjoy. 132 characters. I'm sure we can do better. Note: after row 64 we overflow integer maths. Show Sample Output
commandlinefu.com is the place to record those command-line gems that you return to again and again. 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.
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: