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:
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.
In Debian based distros, this command will list 'binutils' package details which contains 'nm' command. You can replace 'nm' to any other command.
Depending on the speed of you system, amount of RAM, and amount of free disk space, you can find out practically how fast your disks really are. When it completes, take the number of MB copied, and divide by the line showing the "real" number of seconds. In the sample output, the cached value shows a write speed of 178MB/s, which is unrealistic, while the calculated value using the output and the number of seconds shows it to be more like 35MB/s, which is feasible.
Scan for open ports on the target device/computer (192.168.0.10) while setting up a decoy address (192.168.0.2). This will show the decoy ip address instead of your ip in targets security logs. Decoy address needs to be alive. Check the targets security log at /var/log/secure to make sure it worked.
ps command gives the possibility to display information with custom formatting with the -o options followed by the format specifier list.
Redirects the contents of your clipboard through a pipe, to a remote machine via SSH.
Using 7z to create archives is OK, but when you use tar, you preserve all file-specific information such as ownership, perms, etc. If that's important to you, this is a better way to do it.
greps using only ascii, skipping the overhead of matching UTF chars.
$ export LANG=C; time grep -c Quit /var/log/mysqld.log
$ export LANG=en_US.UTF-8; time grep -c Quit /var/log/mysqld.log
Try strace-ing grep with and without LANG=C
I've used technicalpickles command a lot, but this one handles whitespaces in filenames. I'm sure you want to create an alias for it :)
Just a handy way to get all the unique links from inside all the html files inside a directory. Can be handy on scripts etc.
Handy when you need to create a list of files to be updated when subversion is not available on the remote host. You can take this tar file, and upload and extract it where you need it. Replace M and N with the revisions specific to yours. Make sure you do this from an updated (svn up) working directory.