Linux is Everywhere!
(I won’t bother you too much with this introduction because I know how excited I was when I started for the first time to learn Linux. You can find here a small Linux Introduction.)
Linux is a very flexible operating system and as you already may know it can be found in everything from automobiles to rockets, phones, servers, personal computers, watches, TVs, IoE devices and the list continues…
I hope that you will find this tutorial very interesting and you will enjoy it!
What do I need in order to learn Linux?
- PC/Notebook (depending on Linux version that you would like to use I recommend: RAM – Min 4GB, CPU – Dual/Quad Core);
- Virtualization Software: Oracle VirtualBox (recommended and also free software) / VMWare (paid software);
- CentOS DVD image file;
Note: I do not recommend to install Linux (at this moment) as a SecondBoot or as a default operating system of your PC/notebook. What I recommend is to install CentOS on a Virtual Machine.
Basic Linux Commands and Syntax
This tutorial deals exclusively with the CLI (Command Line Interface). The CLI is a very powerful interface that allows the users to administer small devices, extremely capable cloud computer servers, network devices and everything between them.
A command is a software program and when executed on the CLI, performs an action on the computer.
First of all install CentOS on the VirtualMachine Software, power on CentOS machine, login on the system and open the terminal window.
To execute a command, first type the command, for example ls, and hit Enter.
Note: The commands are case sensitive, so LS will not execute but ls will execute.
Most of the commands follow a simple syntax: command [options] [arguments]. You have to type the command followed by options and/or arguments and then press Enter. The options usually alter the behavior of commands and arguments.
An argument can be used to specify something that the command should act on. For example you can try the following example:
Example: ls /var/log (ls = “list” lists the contents of directory /var/log)
In this example /var/log/ is the argument used with ls command.
Options are used to alter the behavior of commands. In the next example we will use -l option with ls command and see what happens.
Example: ls -l (-l = “long display”, means that will give more information)
It will output detailed information about the listed files.
Example: ls -r (-r “reverse”, it will reverse the alphabetical order)
Options can be used at once, combined or separated, but the output will be the same. Order of the options does not matter.
Example: ls -r -l (separated)
Example: ls -lr (combined)
Printing Working Directory
To discover where we are located within file-system, we can use pwd command. We will use the term “Print” not to send information to a physical printer, but to send the information to be printed to the screen.
Directories are type of file used to store other files, they also provide hierarchical organization structure. To navigate the filesystem you can use the command cd (Change Directory).
cd [options] [path]
The ls command is used to list the contents of a directory.
To get more details about a file, like permissions, ownerships or timestamps, perform a longlisting using -l option with the ls command.
Example: ls -l /var/log
Each line contain the details about every file in the directory. The details are broken into columns separated by spaces.
The first column contains ten characters, the first character indicates the type of the file and the next nine characters indicates the file permissions:
d | directory | A file that contains other files;
– | regular file | Readable, images, binary and compressed files;
l | symbolic link | Points to other files;
s | socket | Allows for the communication between processes;
p | pipe | Allows for communication between processes;
b | block file | Used to communicate with hardware;
c | character file | Used to communicate with hardware.
Permissions indicate how users can access the files.
Hard Link Count
This number indicates how may hard links point to the file.
When a file is created the ownership is automatically assigned to the user who created it.
Shows which group owns the file.
In case of a file the size is displayed in bytes and in case of a directory, multiple of the block size used by the file system.
Indicates the time when the file’s content was last modified.
The last field contains the name of the file or directory.
Symbolic link name will be displayed along with and arrow and the link to the original file.
The output of the ls command is sorted alphabetically by filename, but it can be modified by ls options. In the example below ls command will be combined with -l option so the relevant details to be displayed and with the -S option which sorts by size.
The -S option will sort the files by size.
The -r option will reverse the order of any type of sort.