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.
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:
To ensure that it will never come back, you can edit /etc/modprobe.d/blacklist
Add "blacklist pcspkr" sans quotes
short command to find a string in all text files in all subdirectories, excluding all files grep does not deem text files.
Also useful with iostat, or pretty much anything else you want timestamped.
Assume that you have a form , in the source look for something similar to :
input name="rid" type="TEXT"
input name="submit" value="SUBMIT" type="SUBMIT" align="center"
Then exec the command to get the response into html
More info : www.h3manth.com
Adjust Google domain and window width
Next time you are leaching off of someone else's wifi use this command before you start your bittorrent ...for legitimate files only of course.
It creates a hexidecimal string using md5sum from the first few lines of /dev/urandom and splices it into the proper MAC address format. Then it changes your MAC and resets your wireless (wlan0:0).
put down the joint and rtfm :)
grep -o puts each occurrence in a separate line
I don't know why this ain't written as simply as it is. I always see it's just used as parameter, like: vi `!!`
But i use it to repeat a command, as i always work on several shells and check the result of one shell on a second.
The -p parameter tell the netstat to display the PID and name of the program to which each socket belongs or in digestible terms list the program using the net.Hope you know what pipe symbol means!
Presently we wish to only moniter tcp connections so we ask grep to scan for string tcp, now from the op of grep tcp we further scan for regular expression /[a-z]*.
Wonder what that means ?
If we look at the op of netstat -p we can see that the name of the application is preceded by a / ( try netstat -p ) so,now i assume application name contains only characters a to z (usually this is the case) hope now it makes some sense.Regular expression /[a-z]* means to scan a string that start with a / and contains zero or more characters from the range a-z !!. Foof .. is t
If you frequently need to connect to your ubersecure mainframe from various uberunsafe machines, you have to face difficult decision: (a) type the password everytime during the session (lame), (b) add local public key to mainframes authorized_keys file (unsafe), (c) as above, but remove this key at the end of the session (pain in the a55). So let's say you save The Command to tempauth file in bin directory of your mainframe's account and make it executable. Then, while you're on one of these unsafe ones, do:
cat $HOME/.ssh/id_rsa.pub|ssh firstname.lastname@example.org bin/tempauth 30
and password prompts stop the harassment for 30 minutes and you don't have to care to remove the unsafe key after that.
Say you want to execute 'file' on the command 'top' (to determine what type of file it is); but you don't know where 'top' resides: preface the argument with = and zsh will implicitly prepend the path.
Sometimes it is handy to be able to list contents of a tar file within a compressed archive, such as 7Zip in this instance, without having to extract the archive first. This is especially helpful when dealing with larger sized files.
say you want to edit your PATH variable using bash/zsh commandline editing, this will put something like this in history so you can edit it:
to make this a shell function such that:
will put /home/dave in the last history event:
print -s "$1='$(eval echo \$$1)'"
Don't track in history commands starting with whitespace.
Moreover ignore duplicates from history.
To be set in .bashrc
$ export HISTCONTROL=ignoreboth
$ echo antani
$ history|grep -c antani
say you've just found all the config files with this command
find . -name '*.config'
and you need to edit them all
will re-execute the command and present them to vi in the argument list
don't use if the list is really long as it may overflow the command buffer
grep's -c outputs how may matches there are for a given file as "file:N", cut takes the N's and awk does the sum.
I often use "vim -p" to open in tabs rather than buffers.
You got some results in two variables within your shell script and would like to find the differences? Changes in process lists, reworked file contents, ... . No need to write to temporary files. You can use all the diff parameters you'll need. Maybe anything like $ grep "^>"
is helpful afterwards.
Let dd use direct I/O to write directly to the disk without any caching. You'll encounter very different results with different block sizes (try with 1k, 4k, 1M, ... and appropriate count values).
This will create the file /tmp/pkgdetails, which will contain a listing of all the files installed on your RPM-based system (RedHat, Fedora, CentOS, etc). Useful should the RPM system/database become corrupted to find which package installed which files.
Note, the [remotePort] should be opened in the firewall first. First, start the destination box listening, then fire off the sending box. Data from the /dev/zero device in memory of the source machine is read out using dd, sent over the network with nc, and read back in from the other side of the network with nc, going to the /dev/null device. Essentially, it is a memory-network-memory copy operation, the output of dd will tell you how fast your network really is performing.