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:
Useful for quick calculations at the command line. $math_expr is any arithmetic expression (see sample output):
4.5*16+3^2
s(3.1415926/2)
More options in the bc man page.
The file .my.cnf located at user's home directory is used for mysql login. If this file exists, then
mysql -uYOURUSERNAME -pYOURPASSWORD database -e 'SOME SQL COMMAND'
can be replaced with
mysql database -e 'SOME SQL COMMAND'
It saves you from typing!
This is valid for mysqladmin and mysqldump commands as well.
An alias i made for myself to play music in a faster way.
Works great when you have Guake / Tilda installed (Console that drops down like in the game QUAKE)
---
I put this in my bash_alias file (I'm on ubuntu, the bash_alias file does autostart with the right config) but it works putting it in bashrc too. Or anything that autostarts when the console is opened.
---
Needs Mplayer and music files to work. With out music theres nothing to play!
Oh, and also, without modification, this alias will try to play stuff from your ~/Music folder! (case sensitive). Make sure that folder exists and has music OR edit this alias to fit your needs.
If you want to operate on a set of items in Bash, and at least one of them contains spaces, the `for` loop isn't going to work the way you might expect. For example, if the current dir has two files, named "file" and "file 2", this would loop 3 times (once each for "file", "file", and "2"):
for ITEM in `ls`; do echo "$ITEM"; done
Instead, use a while loop with `read`:
ls | while read ITEM; do echo "$ITEM"; done
The brace expansion also allows you to count backward:
for i in {15..1}; do echo $i; done
You can also use this construct to create new file or new directory:
mkdir dir{1..3} # Same as mkdir dir1 dir2 dir3
Replace "url" with the correct address of what your're downloading. Replace 01:00 with what time you want. (24-hour clock).
This command will grep the entire directory looking for any files containing the list of files. This is useful for cleaning out your project of old static files that are no longer in use. Also ignores .svn directories for accurate counts. Replace 'static/images/' with the directory containing the files you want to search for.
I think it would be wise if anyone voting down left a comment indicating the reason for that action. Don't keep it to yourself. Thanks.
The output of "echo $PATH" is hard to read, this is much easier. The parentheses ensure that the change to the input field separator (IFS) only happens the the sub shell and not affecting the current shell.
I am new to linux, and I was trying to figure out why I could not sudo with my username in Fedora 10. This command, when run as root, will add a line to the sudoers file allowing the loginname supplied to sudo. The above line will require a password when you sudo, if you wish to sudo without password, use:
echo 'loginname ALL=(ALL) NOPASSWD:ALL' >> /etc/sudoers
instead. you have to run this command as su, and this is just an easier way of using visudo, just adds it right from the terminal.
Issues a scan command on the given scsi host adapter (ex. a fibre channel adapter, in the example above on host0). Output can be watched in the messages log or in "dmesg"
Thanks to OpenSSL, you can quickly and easily generate MD5 hashes for your passwords.
Alternative (thanks to linuxrawkstar and atoponce):
echo -n 'text to be encrypted' | md5sum -
Note that the above method does not utlise OpenSSL.
This command is a bit Linux specific, as --stdin doesn't exist for passwd on many Unix machines. Further, useradd is high level in most distributions and Unix derivatives except for the Debian family of distros, where adduser would be more appropriate. The last bit, with chage, will force the user to change their password on new login.
Replace (as opposed to insert) hex opcodes, data, breakpoints, etc. without opening a hex editor.
HEXBYTES contains the hex you want to inject in ascii form (e.g. 31c0)
OFFSET is the hex offset (e.g. 49cf) into the binary FILE
This is quite usefull in Unix system share via NFS or AppleTalk with OSX clients that like to populate your filesystem with these pesky files
A useful way to generate the MD5 hash for a string by command line
What this does is, if I type ?ssh ? then hit the page-up key, it will complete the line to the last time in my history file that I typed ssh. Hitting page up again will go to the 2nd to last time I typed it. Incredibly handy if you ever type the same commands more than once.
credit goes to http://www.sharms.org/blog/2009/03/10/make-your-bash-shell-cool-again/
echo "\"\e[6~\": history-search-forward" >> ~/.inputrc
This was useful to generate random passwords to some webpage users, using the sample code, inside a bash script