Commands by mack (10)

What's this? 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

Check disk for bad sectors
Checks HDD for bad sectors, just like scandisk or chkdisk under some other operating system ;-).

Get Cisco network information
This gives you lots of nifty Cisco network information like VLAN tag, port and switch information.

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

Converts uppercase chars in a string to lowercase
Another alternative is to define a function: lower() { echo ${@,,} } lower StrinG

Suspend to ram
Using sys

Follow the most recently updated log files
This command finds the 5 (-n5) most frequently updated logs in /var/log, and then does a multifile tail follow of those log files. Alternately, you can do this to follow a specific list of log files: sudo tail -n0 -f /var/log/{messages,secure,cron,cups/error_log}

Find and display most recent files using find and perl
This pipeline will find, sort and display all files based on mtime. This could be done with find | xargs, but the find | xargs pipeline will not produce correct results if the results of find are greater than xargs command line buffer. If the xargs buffer fills, xargs processes the find results in more than one batch which is not compatible with sorting. Note the "-print0" on find and "-0" switch for perl. This is the equivalent of using xargs. Don't you love perl? Note that this pipeline can be easily modified to any data produced by perl's stat operator. eg, you could sort on size, hard links, creation time, etc. Look at stat and just change the '9' to what you want. Changing the '9' to a '7' for example will sort by file size. A '3' sorts by number of links.... Use head and tail at the end of the pipeline to get oldest files or most recent. Use awk or perl -wnla for further processing. Since there is a tab between the two fields, it is very easy to process.

function to edit your history file
eh stands for Edit History . Frequently, I'll mistype a command, and then step back through my history and correct the command. As a result, both the correct and incorrect commands are in my history file. I wanted a simple way to remove the incorrect command so I don't run it by mistake. . When running this function, first the ~/bash_history file is updated, then you edit the file in vi, and then the saved history file is loaded back into memory for current usage. . while in vi, remember that `Shift-G` sends you to the bottom of the file, and `dd` removes a line. . this command is different than bash built-in `fc` because it does not run the command after editing.

Show latest changed files

Check if running in an X session
If you want to display a dialog (using xdialog/kdialog/zenity) you need to make sure that you have a valid X session. Checks for the existence of the DISPLAY variable.

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.


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: