Some cool quick Linux command line tricks - gHacks Tech News

Some cool quick Linux command line tricks

If you've used Linux long enough, you know there are some seriously cool tricks you can pull from the command line. Some of these tricks are just for fun, but the vast majority of them actually serve a purpose. It is the latter type of trick I want to highlight here. The purpose they serve will all vary so you might only find one or two that are of use to you. But no matter if you find a command you can use immediately, you might be able to find one that you can modify to fit some need or other. With that said, let's dig in.

NOTE: Since each of the below command serves a different purpose, you might have to install a piece of software to get it working. If there is a piece of software not included in the base Linux installation, I will make not of it and how to install the software.

Monitor changing files in real time

This command is fairly useful to watch your file system as it changes. It is more useful in just watching where changing files and percentages of drive space are critical. The command uses watch, df, and ls like so:

watch -d -n 2 'df; ls -FIAt;'

The above command will refresh every 2 seconds and show you what is being changed on your file system.

Check your Amazon paid ranking

I am a writer of novels (Check out my work on Amazon.com) and frequently check my paid rankings on Amazon.com. By using the Linux operating system I am privy to the tools necessary to create a cron job to dump the rankings into a file for me to check. The command to do this makes use of wget, grep, cut, and sed and looks like:

wget -q -O - http://www.amazon.com/gp/product/XXXXXXXXXX | grep 'Paid in' | cut -d' ' -f1 | sed 's/[#,]//g' >> rank.log

Where XXXXXXXX is the code for the title you want to follow.

Check your unread Gmail email

Here's a very handy command for those of you who use Gmail and would like to check for unread email without having to fire up a browser. This command makes use of: curl, tr, awk, and sed and looks like:

curl -u GMAIL_ADDRESS:GMAIL_PASSWORD --silent "https://mail.google.com/mail/feed/atom" | tr -d '\n' | awk -F '<entry>' '{for (i=2; i<=NF; i++) {print $i}}' | sed -n "s/<title>\(.*\)<\/title.*name>\(.*\)<\/name>.*/\2 - \1/p"

Where GMAIL_ADDRESS is your actual gmail address and GMAIL_PASSWORD is your gmail password. Upon successful authentication the sender and subject of your unread Gmail will be printed out.

Display a directory as a web page

This command is incredibly handy. Say you want to allow someone access to files quickly via a web browser on your machine. You can do that with the help of python. All you do is change into the directory you want to serve up and then run the command:

python -m SimpleHTTPServer

Now, whoever needs to view that page simply points their browser to http://ADDRESS_OF_MACHINE:8000

Where ADDRESS_OF_MACHINE is either the IP Address or Domain of the machine (whichever applies). The user will then be able to navigate the files and folders within the directory you are serving up.

Advertisement

We need your help

Advertising revenue is falling fast across the Internet, and independently-run sites like Ghacks are hit hardest by it. The advertising model in its current form is coming to an end, and we have to find other ways to continue operating this site.

We are committed to keeping our content free and independent, which means no paywalls, no sponsored posts, no annoying ad formats or subscription fees.

If you like our content, and would like to help, please consider making a contribution:


Previous Post: «
Next Post: »

Comments

  1. robin said on February 22, 2011 at 4:21 am
    Reply

    http://localhost:8000 worked for me, might help others.

    really useful tip about firing up a local http server!

  2. BalaC said on February 22, 2011 at 11:41 am
    Reply

    Correction

    “I will make not of it and how to install the software.”

    Do you mean note?

Leave a Reply

Check the box to consent to your data being stored in line with the guidelines set out in our privacy policy

Please note that your comment may not appear immediately after you post it.