All commands (14,187)

What's this?

commandlinefu.com is the place to record those command-line gems that you return to again and again. 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.

Share Your Commands


Check These Out

save command output to image

show installed but unused linux headers, image, or modules
will show: installed linux headers, image, or modules: /^ii/!d avoiding current kernel: /'"$(uname -r | sed "s/\(.*\)-\([^0-9]\+\)/\1/")"'/d only application names: s/^[^ ]* [^ ]* \([^ ]*\).*/\1/ avoiding stuff without a version number: /[0-9]/!d

Which processes are listening on a specific port (e.g. port 80)
swap out "80" for your port of interest. Can use port number or named ports e.g. "http"

Scan LAN and get Windows host names

Quickly batch resize images
-geometry (preserves values of height and width given, and aspect ratio). WARNING: While 'resize' creates resized copies of original files, 'mogrify' works on the original files, replacing them. It will overwrite the source files, use with caution, and backup regularly.

Create backup copy of file, adding suffix of the date of the file modification (NOT today's date)
When I go to change a configuration file I always like to make a backup first. You can use "cp -p" to preserve the modification time, but it gets confusing to have file.prev, file.prev2, etc. So I like to add a YYMMDD suffix that shows when the file was last changed. "stat -c %Y" gives you the modification time in epoch seconds, then "date -d @" converts that to whatever format you specify in your "+format" string.

Get AWS temporary credentials ready to export based on a MFA virtual appliance
You might want to secure your AWS operations requiring to use a MFA token. But then to use API or tools, you need to pass credentials generated with a MFA token. This commands asks you for the MFA code and retrieves these credentials using AWS Cli. To print the exports, you can use: `awk '{ print "export AWS_ACCESS_KEY_ID=\"" $1 "\"\n" "export AWS_SECRET_ACCESS_KEY=\"" $2 "\"\n" "export AWS_SESSION_TOKEN=\"" $3 "\"" }'` You must adapt the command line to include: * $MFA_IDis ARN of the virtual MFA or serial number of the physical one * TTL for the credentials

Remove comments from files
Use sed to remove comments from a file. In this example the comments begin with #. The command '/^#/d' remove line starting with #. The command 's/#.*$//' remove comments at end of lines.

list offsets from HEAD with git log.

find text in a file
this will find text in the directory you specify and give you line where it appears.


Stay in the loop…

Follow the Tweets.

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

Subscribe to the feeds.

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: