Tyler Muth’s Blog

Technology with a focus on Oracle, Application Express and Linux

A Few Linux Tips and Tricks

Posted by Tyler Muth on April 30, 2008

I feel I’ve neglected the “Linux” aspect of my blog, so here a few tips that I hope you find useful.

What port is the TNS Listener listening on?

sudo netstat -tlnp | grep tns
tcp        0      0  *               LISTEN      15481/tnslsnr

I know this is a simple one, but it never hurts to review the basics.

Can I get to a particular port on a remote server?

netcat -w 3 -z -vvn 79-81
(UNKNOWN) [] 81 (?) : Connection timed out
(UNKNOWN) [] 80 (www) open
(UNKNOWN) [] 79 (finger) : Connection timed out

This example is essentially running a port scan on google.com from port 79 to 81, waiting for 3 seconds for a port to time out. You can see that only port 80 is open. I use this constantly when troubleshooting connections between Application Servers and Databases, especially when firewalls are involved. This is much more meaningful than a simple ping. Note that netcat only accepts IP addresses, not host names, so you can ping a host first to get it’s IP address first. Also note that port scans may violate your own network policies and could be construed as a form of hacking, so use at your own risk and tell someone what you’re going to do before you do it. You can install netcat on Windows using Cygwin (the command is nc in cygwin).

Leave a remote session running without using VNC

I discovered the screen command (documented here) about a year ago and I now use it on a regular basis. For example, I did an APEX install on a remote server yesterday. I connected via SSH using PuTTY, typed screen, then started sqlplus and kicked off the install. I then typed ctrl+a d to disconnect from that screen session. I then exited SSH and closed PuTTY. Without screen, that would have killed my install. Since I started the install in a screen session, in continued on in the background. I could then SSH into the machine later in the day and type screen -r to reattach to the session. Trust me, if you use screen for a week, you’ll wonder how you lived without it.

Share the current directory over http

Add the following line to your .bashrc or .bash_profile file:

alias http='python -m SimpleHTTPServer 8000'

Source the file you added it to or logout / login for the change to be reflected. Now navigate to any directory and type webshare. Presto! You can now access that directory from a browser on port 8000.

When I read this tip here, I was simply blown away. It couldn’t be that easy, could it? Yep, it’s that simple and is one of the first aliases I create on a new system.

Sort folders by size

du --max-depth=1 /home/ | sort -n -r

Blink the lights on network card eth0

sudo ethtool -o eth0

Why in the world would you want to do this? Well, I was at a customer site in Pennsylvania last month assisting with (more observing really) a RAC install. Each of the 2 nodes had 9 network cards! This was a demo system shipped in by a hardware vendor, so the cards weren’t even in matching slots for the 2 nodes. We had no idea what card Linux had assigned eth0,1,2… to. I called Sergio Leunissen for a little help and within a few minutes he had the answer. Ethtool will continue to blink the lights on the card until you press ctrl+c, which made it easy for use to map their locations on paper and get the right cables for each network segment in the right card. Thanks Sergio.

For more information on Linux command-line techniques, take a look at “Guide to Advanced Linux Command Mastery” by Arup Nanda: Part 1 , Part 2.


9 Responses to “A Few Linux Tips and Tricks”

  1. John Scott said


    I love the blinking lights tip, I’ve certainly been in that situation before and it’s a great way to know which cable not to pull out 😉

    The other command that I love for digging down and finding out which programs are listening on which ports is the ‘lsof’ command, it’s a very useful one if you either don’t know which ports a particular program listens on, or (vice-versa) want to know which program is the one listening on a particular port.


  2. Forgive me for playing wiseguy, but disk usage by folder can be done more easy the following way:

    du -sm /home/* | sort -r

    Please mind that (I’ve been told) mii-tool is deprecated and succeeded by ethtool.
    One other very convenient thing of ethtool (and where I used to use mii-tool for) is inspecting network interfaces for connectivity.
    Besides that: ethtool also shows speed and duplex setting, which can influence performance (severely, if NFS is used 😉

  3. Oops! It’s “sort -n” (numeric)

  4. Gandolf989 said

    Great tips!!! Although I am afraid to use python to publish directories. That’s why I have putty…

    Of course being unix/linux you can pipe it to a grep -v “timed out” and then > to a log file and filter out the closed ports leaving only interesting ports. I already did a partial scan of my Debian linux box. I just need to figure out a reasonable max value for the range. I also like this because it lists the default ports for things I did not know had default ports.

    17 (qotd): Connection timed out — quote of the day?!?!?!?


  5. prodlife said

    Excellent tips! Netcat is completely new to me and very cool.

    My favorite linux tricks are rather simple:
    – use of rlwrap to add command line history to sqlplus (learned this from Lutz Hartmann)
    – liberal use of aliases to make everything easier – tailalert, vialert, cdbdump, vitns, etc, etc

  6. psychicchatonline…

  7. Sergio said

    Hey Tyler, my blog has finally settled in its new home: http://blogs.oracle.com/sergio You may want to update the link in this post.


  8. […] https://tylermuth.wordpress.com/2008/04/30/a-few-linux-tips-and-tricks/ […]

  9. linux tips said

    Great tips. You can use multiple windows in screen.

    All commands start with CTRL-A, then another key for the command itself. If you really want to send a CTRL-A to your application (Like to go to the beginning of the current line in bash for example, hit CTRL-A twice.)

    CTRL-A CTRL-D Detach your current session

    “screen -rd” to get back to it

    CTRL-A CTRL-C create another “window”
    CTRL-A CTRL-N next window
    CTRL-A CTRL-P previous window
    CTRL-A ” see list of current windows
    CTRL-A [ Copy mode… you can see the scrollback buffer with this. Esc to exit
    CTRL-A ? Help for further stuff.
    CTRL-A 1 jump to first screen CTRL-A 2 (2nd screen etc)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: