and, a lot uglier, with sed:
ifconfig | sed -n '/inet addr:/s/[^:]\+:\(\S\+\).*/\1/p'
Edit:
Wanted to be shorter than the perl version. Still think that the perl version is the best..
In edit mode, toggle the case of a single word under the cursor in vim.
This command will generate "CHECK TABLE `db_name.table_name` ;" statements for all tables present in databases on a MySQL server, which can be piped into the mysql command. (Can also be altered to perform OPTIMIZE and REPAIR functions.) Tested on MySQL 4.x and 5.x systems in a Linux environment under bash. Show Sample Output
On Solaris 10 you used dtconfig -d to achieve this. The command will disable X and your system will now boot to a text console.
Get the IP address of all your network cards. Show Sample Output
To change to $HOME in that manner you need to set a shell option. In zsh it is auto_cd, hence
setopt -o auto_cd
in bash4 it is autocd, hence
shopt -s autocd
What the option does is allow you to cd to a directory by just entering its name. This also works if the directory name is stored in a variable:
www=/var/www/lighttpd; $www
sends you to /var/www/lighttpd.
CAUTION: If a command or function name identical to the directory name exists it takes precedence.
Could use your ssh bash history if your known_hosts are hashed and you want to keep it hashed
Busiest seconds:
cat /var/log/secure.log | awk '{print substr($0,0,15)}' | uniq -c | sort -nr | awk '{printf("\n%s ",$0) ; for (i = 0; i<$1 ; i++) {printf("*")};}'
Show Sample Output
Find when debian packages were installed on a system.
A quick and simple way of outputting the start and end date of a certificate, you can simply use 'openssl x509 -in xxxxxx.crt -noout -enddate' to output the end date (ex. notAfter=Feb 01 11:30:32 2009 GMT) and with the date command you format the output to an ISO format. For the start date use the switch -startdate and for end date use -enddate. Show Sample Output
I use this to make skype blend better into my desktop :) --disable-cleanlooks might not be nescessary to achieve the wanted effect.
time perl -e 'if(opendir D,"."){@a=readdir D;print $#a - 1,"\n"}'
205413
real 0m0.497s
user 0m0.220s
sys 0m0.268s
time { ls |wc -l; }
205413
real 0m3.776s
user 0m3.340s
sys 0m0.424s
*********
** EDIT: turns out this perl liner is mostly masturbation. this is slightly faster:
find . -maxdepth 1 | wc -l
sh-3.2$ time { find . -maxdepth 1|wc -l; }
205414
real 0m0.456s
user 0m0.116s
sys 0m0.328s
** EDIT: now a slightly faster perl version
perl -e 'if(opendir D,"."){++$c foreach readdir D}print $c-1,"\n"'
sh-3.2$ time perl -e 'if(opendir D,"."){++$c foreach readdir D}print $c-1,"\n"'
205414
real 0m0.415s
user 0m0.176s
sys 0m0.232s
Add to your bash profile to minimize carpal tunnel syndrome. Doesn't work with user@hostname but appending "-l user" works fine if needed. Works for ping as well.. complete -W "$(echo `cat ~/.ssh/known_hosts | cut -f 1 -d ' ' | sed -e s/,.*//g | uniq | grep -v "\["`;)" ping Show Sample Output
Convert comma separated files to tab separated files. (MySQL eats tab separated files with much less instruction than comma seperated files.) Show Sample Output
substitute the URL with your private/public XML url from calendar sharing settings substitute the dates YYYY-mm-dd adjust the perl parsing part for your needs Show Sample Output
I tried out on my Mac, jot to generate sequence ( 0,25,50,..), you can use 'seq' if it is linux to generate numbers, need curl installed on the machine, then it rocks. @Satya Show Sample Output
prints a random line
Fetches the IPs and ONLY the IPs from ifconfig. Simplest, shortest, cleanest. Perl is too good to be true... (P.S.: credit should go to Peteris Krumins at catonmat.net) Show Sample Output
Limited, but useful construct to extract text embedded in XML tags. This will only work if bar is all on one line. If nobody posts an alternative for the multiline sed version, I'll figure it out later...
If you use 'tail -f foo.txt' and it becomes temporarily moved/deleted (ie: log rolls over) then tail will not pick up on the new foo.txt and simply waits with no output. 'tail -F' allows you to follow the file by it's name, rather than a descriptor. If foo.txt disappears, tail will wait until the filename appears again and then continues tailing.
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: