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 is better than doing a "for `find ...`; do ...; done", if any of the returned filenames have a space in them, it gets mangled. This should be able to handle any files.
Of course, this only works if you have rename installed on your system, so it's not a very portable command.
no grep, no perl, no pipe.
even better in zsh/bash4:
for i in **/*oldname*; do "mv $i ${i/oldname/newname/}"; done
No find, no grep, no perl, no pipe
Great for sites like Gigapedia.org that give away great free rar'd books.
More similar commands here: http://www.howtogeek.com/howto/ubuntu/unzip-or-unrar-many-files-at-once-in-linux/
Just copy and paste the code in your terminal.
Note : sudo apt-get for debian versions , change as per your requirement .
Source : www.h3manth.com
Good for fixing web permissions. You might also want to do something like this and skip files or directories that begin with a period:
find public_html/stuff -not -name ".*" \( -type d -exec chmod 755 {} + -o -type f -exec chmod 644 {} + \)
...or include a special case for scripts:
find public_html/stuff -type d -exec chmod 755 {} + -or -type f -name "*.pl" -exec chmod 755 {} + -or -exec chmod 644 {} +
This should work anywhere perl and grep is available. :P
Stop tormenting the poor animal cat. See http://sial.org/howto/shell/useless-cat/.
Edit:
replaced
sort | uniq
by
sort -u
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.
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.
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("*")};}'
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.
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