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:
root@wow/var/spool/clientmqueue # rm spam-*
/bin/rm: Argument list too long.
This command is more robust because it handles spaces, newlines and control characters in filenames. It uses printf, not ls, to determine file size.
Takes a directory name as an argument (defaults to current directory if no arguments are given). Prints the newest file in the directory.
This will copy the first 1MB of your /dev/sdX volume to your /root/sdX.bin file, where SDX is the name of the device you wish to copy the data from (Usually a hard disk)
NOTE: Make sure you capitalize the M in field for BS.
This command kills all wine instances and each EXE application working on a PC.
Here is command info:
1) ps ax > processes = save process list to file named "processes" (we save it because we don't wont egrep to be found in the future)
2) cat processes | egrep "*.exe |*exe]" = shows the file "processes" and after greps for each *.exe and *exe] in it
3) | awk '{ print $1 }' > pstokill = saves processes PID's to file "pstokill" using awk filter
4) kill $(cat pstokill) = kills each PID in file pstokill, which is shown by cat program
5) rm processes && rm pstokill = removes temporary files
Use the following key binding to search
----------------------------------------------------------------
ng
: Jump to line number n. Default is the start of the file.
nG
: Jump to line number n. Default is the end of the file.
/pattern
: Search for pattern. Regular expressions can be used. [/ = slash] Press / and then Enter to repeat the previous search pattern. Press ESC and then u to undo search highlighting.
n
: Go to next match (after a successful search).
N
: Go to previous match.
mletter
: Mark the current position with letter.
'letter
: Return to position letter. [' = single quote]
'^ or g
: Go to start of file.
'$ or G
: Go to end of file.
s
: Save current content (got from another program like grep) in a file.
= or Ctrl+g
: File information.
F
: continually read information from file and follow its end. Useful for logs watching. Use Ctrl+c to exit this mode.
-option
: Toggle command-line option -option.
h
: Help.
This command might not be useful for most of us, I just wanted to share it to show power of command line.
Download simple text version of novel David Copperfield from Poject Gutenberg and then generate a single column of words after which occurences of each word is counted by sort | uniq -c combination.
This command removes numbers and single characters from count. I'm sure you can write a shorter version.
It extracts X number of lines from file1 and dumps them to file2.Using grep with the empty string '' extracts the complete lines (i.e. no filtering takes place) and the -m flag indicates how many lines to extract out from the given file. Then using the redirect > operator we send the extracted lines to a new file.
See smbstatus Output within a 5 second interval (for monitoring smb access)
After a command is run in bash, !$ is set to the last (space-delimited) argument of the command. Great for running several commands against the same file in a row.
# define user pid to kill
PID=httpd ;
# kill all pids
ps aux | grep $PID | grep -v grep | awk '{print $2}' | xargs kill -9
I use these command to validate twitter accounts, we can use a "for a in $(cat list.txt)" to validate a complete list of twitter accounts.
The sample output, is the command with a ?, to show you all the stuff you can look at.