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:
This loops through all tables and changes their collations to UTF8. You should backup beforehand though in case some data is lost in the process.
Show the number of failed tries of login per account. If the user does not exist it is marked with *.
Just type 'opened' and get all files currently opened for edit.
This command shows if there are any locked AFS volumes.
The output is a list of AFS volume IDs (or nothing if there are none locked).
Takes a input file (count.txt) that looks like:
1
2
3
4
5
It will add/sum the first column of numbers.
This command converts filenames with embedded spaces in the current directory replacing spaces with the underscore ("_") character.
Can pipe to tail or change the awk for for file size, groups, users, etc.
This command will kill all processes using a directory. It's quick and dirty. One may also use a -9 with kill in case regular kill doesn't work. This is useful if one needs to umount a directory.
This adds all new files to SVN recursively. It doesn't work for files that have spaces in their name, but why would you create a file with a space in its name in the first place?
Removes all unversioned files and folders from an svn repository. Also:
svn status --no-ignore | grep ^I | awk '{print $2}' | xargs rm -rf
will remove those files which svn status ignores. Handy to add to a script which is in your path so you can run it from any repository (a la 'svn_clean.sh').
This was useful to generate random passwords to some webpage users, using the sample code, inside a bash script
This command lets you see and scroll through all of the strings that are stored in the RAM at any given time. Press space bar to scroll through to see more pages (or use the arrow keys etc).
Sometimes if you don't save that file that you were working on or want to get back something you closed it can be found floating around in here!
The awk command only shows lines that are longer than 20 characters (to avoid seeing lots of junk that probably isn't "human readable").
If you want to dump the whole thing to a file replace the final '| less' with '> memorydump'. This is great for searching through many times (and with the added bonus that it doesn't overwrite any memory...).
Here's a neat example to show up conversations that were had in pidgin (will probably work after it has been closed)...
sudo cat /proc/kcore | strings | grep '([0-9]\{2\}:[0-9]\{2\}:[0-9]\{2\})'
(depending on sudo settings it might be best to run
sudo su
first to get to a # prompt)
This command is much quicker than the alternative of "sort | uniq -c | sort -n".
grep 'HOME.*' data.txt | awk '{print $2}' | awk '{FS="/"}{print $NF}'
OR
awk '/HOME/ {print $2}' data.txt | awk -F'/' '{print $NF}'
In this example, we are having a text file that is having several entries like:
---
c1 c2 c3 c4
this is some data
HOME /dir1/dir2/.../dirN/somefile1.xml
HOME /dir1/dir2/somefile2.xml
some more data
---
for lines starting with HOME, we are extracting the second field that is a 'file path with file name', and from that we need to get the filename only and ignore the slash delimited path.
The output would be:
somefile1.xml
somefile2.xml
(In case you give a -ive - pls give the reasons as well and enlighten the souls :-) )
This command checks for the number of times when someone has tried to login to your server and failed. If there are a lot, then that user is being targeted on your system and you might want to make sure that user either has remote logins disabled, or has a strong password, or both. If your output has an "invalid" line, it is a summary of all logins from users that don't exist on your system.
You can use multiple field separators by separating them with | (=or).
This may be helpful when you want to split a string by two separators for example.
#echo "one=two three" | awk -F "=| " {'print $1, $3'}
one three
This command kills all processes with 'SomeCommand' in the process name. There are other more elegant ways to extract the process names from ps but they are hard to remember and not portable across platforms. Use this command with caution as you could accidentally kill other matching processes!
xargs is particularly handy in this case because it makes it easy to feed the process IDs to kill and it also ensures that you don't try to feed too many PIDs to kill at once and overflow the command-line buffer.
Note that if you are attempting to kill many thousands of runaway processes at once you should use 'kill -9'. Otherwise the system will try to bring each process into memory before killing it and you could run out of memory. Typically when you want to kill many processes at once it is because you are already in a low memory situation so if you don't 'kill -9' you will make things worse
On the Mac, the format ifconfig puts out is little different from Linux: the IP address is space separated, instead of colon. That makes parsing the IP address easier. See releated command for Linux/Unix:
http://www.commandlinefu.com/commands/view/651/getting-the-ip-address-of-eth0