Servers 101: Managing your serversteemCreated with Sketch.

in #tutorial8 years ago

On the 3rd chapter of Servers 101, named Management Series, we will start viewing log files to monitor our server, we'll learn some more commands and we will consider adding some more stuff to our server for better monitoring


Other stuff in the Server 101 series:

Read the last part of Web Server series, in case you missed it!


On this post of the Management series we will start with some much needed commands. It will get very long, as I will add some example responses from each command -where needed-, so be prepared!


Basic Linux Commands

In this section, I will assume that you know almost nothing about linux terminals. If you have a basic knowledge, I would suggest that you have a look (though you won't have to spend a lot of time)

In an ironic way, the first command you will learn, will be how to shutdown your system, and the second one is to restart your system!

shutdown -h now - Power off the system!

shutdown -r now - Restart the system!


cd /path/to/folder - Will enter the folder "/path/to/folder".


cp origin destination - Will copy the file origin to the file destination.

cp -a origin destination - The same as above, but in directories it will copy all files & subfolders below it, as well as metadata of the files (perimissions, times of access/creation/modification etc)

Note: if the destination file exists, it will be overwritten, unless you also add the -i switch. In this case, you will be asked before overwriting.


mv origin destination - This command is used to move or rename files.

Note: in contrast to the cp command above, if the destination exists, you will get an error saying that the file already exists. You can add the -f switch to force this to happen.


rm /path/to/file or rm file - Remove a file. This WON'T remove a folder.

rm -r /path/to/folder - Remove a folder, and all files/folders inside.

Note: if you have a write protected file or folder, you can also add the -f switch to force the removal.

Note 2: "rm -rf /" will corrupt your system. NEVER, EVER, EVER RUN THIS COMMAND!


mkdir /path/to/foldername - Create a folder named "foldername", under "/path/to"

rmdir /path/to/foldername - Remove the folder "foldername", under "/path/to". If the folder is not empty, it will not get removed! In this case, rm -rf is easier to use, but it is also easier to make a mistake.

touch /path/to/filename - Create an empty file named "filename", under "/path/to"

clear - Clear the terminal output!

pwd - Print the current working directory.


ls - List all files on the current directory. The list of files will be horizontal, as such:

alternatives.log auth.log btmp daemon.log.1 debug.1 exim4 fail2ban.log.1 installer kern.log.1 messages syslog syslog.2.gz syslog.4.gz syslog.6.gz wtmp

ls -l - List all files in a long format (-l switch). The list will be vertical, with some details:

total 3716
-rw-r--r-- 1 root        root   17902 Jul 10 18:25 alternatives.log
drwxr-xr-x 2 root        root    4096 Jul 10 22:06 apt
-rw-r----- 1 root        adm     7329 Jul 17 13:50 auth.log
-rw-r----- 1 root        adm  1012499 Jul 16 06:25 auth.log.1
...

Quick note. If we have 2 or more "one character switches" that don't take arguments, we can either combine them, as in the commands below, or you can seperate them with a space and a dash (for example: ls -l -t is the same with ls -lt)

ls -lt - The same as the one above, but the files will be sorted out by modification date (-t switch), as such:

total 3716
-rw-r----- 1 root        adm     3449 Jul 17 13:53 daemon.log
-rw-r----- 1 root        adm     2807 Jul 17 13:53 syslog
-rw-rw-r-- 1 root        utmp  292292 Jul 17 13:50 lastlog
-rw-rw-r-- 1 root        utmp    8832 Jul 17 13:50 wtmp
...



ls -ltr - The same as above, but in reverse (-r switch):

total 3716
-rw-r--r-- 1 root        root   17902 Jul 10 18:25 alternatives.log
drwxr-xr-x 3 root        root    4096 Jul 10 18:26 installer
-rw-r----- 1 root        adm    17358 Jul 10 18:35 debug.1
drwxr-xr-x 2 root        root    4096 Jul 10 22:06 apt
...



ls -lth - The same as "ls -lt", but more "human readable" (-h switch):

total 3.7M
-rw-r----- 1 root        adm  3.4K Jul 17 13:53 daemon.log
-rw-r----- 1 root        adm  2.8K Jul 17 13:53 syslog
-rw-rw-r-- 1 root        utmp 286K Jul 17 13:50 lastlog
-rw-rw-r-- 1 root        utmp 8.7K Jul 17 13:50 wtmp
...


These are the "MUST KNOW" switches! To find out more switches and what they are, you can always do ls --help (that's a long switch, not as easy to work with as you may end up writing a command that expands to multiple lines, but it is more self-explained)

Some Notes:

In most cases (the exceptions being "clear" and "pwd"), if we specify a directory, the command will run the result in this directory. For example, we can run "ls -lth /var/www" from our home directory and we will get a list of all files inside "/var/www".

Also, wherever I have specified "/path/to/", you can skip it if you want to create/copy/delete/etc a file or folder in the current directory.

The list of commands and switches are in no way a "definitive list for administrators". It's just the first step of learning linux commands. There are whole books dealing with linux commands, and I would say that most of them miss a think or two. You need years of experience to know "everything inside out".


The first part is over. We have learned a lot of commands today, and it is time to put a stop here. Pat yourself in the back!

In the next part, we will learn some more commands (like, showing the free disk space, or reading how much RAM our system has)


If you need a place to host your servers consider Vultr, Digital Ocean and BuyVM.

These are affiliate links. If you sign up through them, you support me and I will have more free time to write more content like this.

Also If you signup for Digital Ocean through my affiliate link, you will get $10 to try them out. Note: to battle abusers of this offer, you'll have to make a $5 deposit via Paypal or add your credit/debit card, so they can confirm that you are a new user. I did a deposit via Paypal to test them out, and then I added my credit card so I won't have to deposit money manually every now and then.


Also, I am running a witness server.

Please consider voting me, dimitrisp, for a witness if you find what I post helpful.

You can read my witness declaration here

Sort:  

Congratulations! This post has been upvoted from the communal account, @minnowsupport, by dimitrisp from the Minnow Support Project. It's a witness project run by aggroed, ausbitbank, teamsteem, theprophet0, and someguy123. The goal is to help Steemit grow by supporting Minnows and creating a social network. Please find us in the Peace, Abundance, and Liberty Network (PALnet) Discord Channel. It's a completely public and open space to all members of the Steemit community who voluntarily choose to be there.

If you like what we're doing please upvote this comment so we can continue to build the community account that's supporting all members.

Coin Marketplace

STEEM 0.12
TRX 0.33
JST 0.032
BTC 112107.57
ETH 4134.64
USDT 1.00
SBD 0.76