LowEndBox - Cheap VPS, Hosting and Dedicated Server Deals

Finding your way on your first ever VPS - Part III

lowendtutorial

Part III of the “Finding your way on your first ever VPS” series is right in front of you right now! This time I’m going to focus on some powerful tools which can make your day-to-day life a lot easier.

I am going to assume a Debian-based distribution in my examples. I’m using Ubuntu 14.04 more specifically. Most commands should work on any Linux distribution; the only distribution-specific commands are those for the package manager.

Let’s get to work!

cat

With ‘cat’, you can print the contents of a file to the standard output, which is usually your terminal. This allows you to quickly see the contents of files without having to leave your terminal for another application. It works best with small files, for example, your resolv.conf or your hosts file. But, if you combine it with another piece of software I’ll cover later on, this will be quite useful for large files as well.

Let’s say you want to quickly see the contents of your resolv.conf, you type:

cat /etc/resolv.conf

You could get an output like this:

# Dynamic resolv.conf(5) file for glibc resolver(3) generated by resolvconf(8)
#     DO NOT EDIT THIS FILE BY HAND — YOUR CHANGES WILL BE OVERWRITTEN
nameserver 8.8.8.8
nameserver 8.8.4.4
nameserver 2001:4860:4860::8888
search example.net

cat was primarily designed to concatenate files, though, rather than printing to your terminal. You could, for example, cat two files and then convert those into a single file. That’s for another time, though.

pipe (|)

A pipe | is not an application, but a tool. It allows you to send the output from one application to another. This is a very powerful tool which allows you to combine the power of multiple applications together.

A good example for the use of a pipe is piping the output from a certain command to ‘less’ so you can calmly look at it or even search through it. The command ‘lsof’ (which lists all the open files on a system) usually has a long output and it may be a pain to work with. If you pipe this to ‘less’, you can browse through it and search through it like it’s a regular text file.

To do this, type:

lsof | less

Which should open ‘less’ with the output of ‘lsof’ in it. Once you exit less, the contents are lost, so this is no way to save content.

grep

grep allows you to search a file or multiple files for a pattern. grep prints every line the pattern is found in to your terminal. A pattern can be something as simple as a word or an IP address, or something as complicated as a long regular expression. In my experience it is extremely useful to quickly search several log files at once.

Say you want to find a certain domain name or IP address in a log file, you would type something like this:

grep 8.8.8.8 /var/log/syslog

The above command searches the file /var/log/syslog for the IP 8.8.8.8 and prints any lines from the file that IP address is on. But, it could also be that you want to search multiple files, or even all files in a directory. In the last case, you would type:

grep 8.8.8.8 *

Where * tells grep to use all files in the current directory (not subdirectories).

grep can also be used in combination with the pipe, so you want search through data coming from another application.

top

top is an application that shows you all the running processes on a system in a single list. Not only does it show the running applications, but also how much CPU and memory an application uses, which user it runs under, how long it has been running, and quite some other things. If you want to know the current status of your system, top is there to help you.

You can open top by typing ‘top’ and quit it by pressing q.

Inside top you have a lot of options, for example to sort or filter the list. There are too many option to highlight right here, so your best option is to type ? or h when in top to see the in-application help, or to use ‘man top’ to view it’s manual.

htop

Or you can install htop, top’s better alternative. To install it, type:

sudo apt install htop

Once done, you can open it by typing:

htop

You will now get to see a more colorful application with some bars at the top. htop has a more graphical display of the system’s used and free resources. Better than that, it can work with your mouse and it works nicely with the F-keys as well as your arrow keys. You can easily sort the columns and you know where to go in this application. Have a look around and enjoy.

My recommendation is to always install htop on any server and it’s simply a lot better than top. It may not be available on any system, however, so in those cases top is what you’ll have to work with.

Final notes

For now, this is the last in the series ‘Finding your way on your first ever VPS’. After having read these three tutorials and having practiced a bit, you should have sufficient information to investigate other parts of your VPS on your own.

Enjoy!

mpkossen

5 Comments

  1. Paul:

    Very good tutorial for beginners.

    Just one suggestion: add the origin of the words used as command, like “cp” comes from “copy”. I know that some words are obvious, but others don’t.

    Thanks!

    October 11, 2014 @ 5:52 pm | Reply
  2. David:

    cat /proc/cpuinfo is the 1st command at 1st login on VPS. ;-)

    October 11, 2014 @ 11:06 pm | Reply
    • Andrew:

      For me, it’s dd if=/dev/zero of=lowendboxisawesome bs=64k count=16k conv=fdatasync :P

      October 12, 2014 @ 5:07 am | Reply
  3. Recommended iotop !!
    http://guichaz.free.fr/iotop/

    October 12, 2014 @ 9:48 am | Reply
  4. Magwinya Wired:

    Excellence Linux tutorials and knowledge base for IT professionals. Keep-up the good work!

    March 15, 2015 @ 10:42 am | Reply

Leave a Reply

Some notes on commenting on LowEndBox:

  • Do not use LowEndBox for support issues. Go to your hosting provider and issue a ticket there. Coming here saying "my VPS is down, what do I do?!" will only have your comments removed.
  • Akismet is used for spam detection. Some comments may be held temporarily for manual approval.
  • Use <pre>...</pre> to quote the output from your terminal/console, or consider using a pastebin service.

Your email address will not be published. Required fields are marked *