Linux Beginner’s Guide Part 1

Linux for beginners

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/IoT 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?

  1. PC/Notebook (depending on Linux version that you would like to use I recommend: RAM – Min 4GB, CPU – Dual/Quad Core)
  2. Virtualization Software: Oracle VirtualBox (recommended and also free software) / VMWare (paid software)
  3. Ubuntu 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 Ubuntu 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 Ubuntu on the VirtualMachine Software, power on Ubuntu machine, login on the system and open the terminal window.

To execute a command, first type the command, for example ls, and hit Enter.

[email protected]:~$ ls
Downloads                  Pictures          snap             Public            Templates                  Desktop           Videos           Documents                 Music

Note: The commands are case sensitive, so LS will not execute but ls will execute.

[email protected]:~$ LS
LS: command not found

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 behaviour of commands and arguments.

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.

[email protected]:~$ ls /var/log
alternatives.log  dist-upgrade    gdm3             openvpn
apt               dmesg           gpu-manager.log  private
auth.log          dmesg.0         hp               speech-dispatcher
boot.log          dmesg.1.gz      installer        syslog
bootstrap.log     dpkg.log        journal          ubuntu-advantage.log
btmp              faillog         kern.log         unattended-upgrades
cups              fontconfig.log  lastlog          wtmp

Options

Options are used to alter the behaviour 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.

[email protected]:~$ ls -l
total 34
drwxr-xr-x  2 sulthan sulthan  4096 Aug  7 21:53  Desktop
drwxr-xr-x  5 sulthan sulthan  4096 Aug  8 00:27  Documents
drwxr-xr-x  3 sulthan sulthan  4096 Aug  8 19:00  Downloads
drwxr-xr-x  2 sulthan sulthan  4096 Aug  7 21:53  Music
drwxr-xr-x  7 sulthan sulthan  4096 Aug  8 02:47  Pictures
drwxr-xr-x  2 sulthan sulthan  4096 Aug  7 21:53  Public
drwxr-xr-x  3 sulthan sulthan  4096 Aug  7 22:16  snap
drwxr-xr-x  2 sulthan sulthan  4096 Aug  7 21:53  Templates
drwxr-xr-x  8 sulthan sulthan  4096 Aug  7 23:46  Videos

Example: ls -r (-r “reverse”, it will reverse the alphabetical order)

[email protected]:~$ ls -r
 Music             Documents         Videos            Desktop
 Templates        Public             snap              Pictures           Downloads

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)

[email protected]:~$ ls -r -l
total 34
drwxr-xr-x  8 sulthan sulthan  4096 Aug  7 23:46  Videos
drwxr-xr-x  2 sulthan sulthan  4096 Aug  7 21:53  Templates
drwxr-xr-x  3 sulthan sulthan  4096 Aug  7 22:16  snap
drwxr-xr-x  2 sulthan sulthan  4096 Aug  7 21:53  Public
drwxr-xr-x  7 sulthan sulthan  4096 Aug  8 02:47  Pictures
drwxr-xr-x  2 sulthan sulthan  4096 Aug  7 21:53  Music
drwxr-xr-x  3 sulthan sulthan  4096 Aug  8 19:00  Downloads
drwxr-xr-x  5 sulthan sulthan  4096 Aug  8 00:27  Documents
drwxr-xr-x  2 sulthan sulthan  4096 Aug  7 21:53  Desktop

Example: ls -lr (combined)

[email protected]:~$ ls lr
total 34
drwxr-xr-x  8 sulthan sulthan  4096 Aug  7 23:46  Videos
drwxr-xr-x  2 sulthan sulthan  4096 Aug  7 21:53  Templates
drwxr-xr-x  3 sulthan sulthan  4096 Aug  7 22:16  snap
drwxr-xr-x  2 sulthan sulthan  4096 Aug  7 21:53  Public
drwxr-xr-x  7 sulthan sulthan  4096 Aug  8 02:47  Pictures
drwxr-xr-x  2 sulthan sulthan  4096 Aug  7 21:53  Music
drwxr-xr-x  3 sulthan sulthan  4096 Aug  8 19:00  Downloads
drwxr-xr-x  5 sulthan sulthan  4096 Aug  8 00:27  Documents
drwxr-xr-x  2 sulthan sulthan  4096 Aug  7 21:53  Desktop

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.

pwd [options]

[email protected]:~$ pwd
/home/sulthan

Changing Directories

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]

[email protected]:~$ cd Desktop
[email protected]:~/Desktop$

Listing files

The ls command is used to list the contents of a directory.

ls [options][path]

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

[email protected]:~$ ls -l /var/log
total 5376
-rw-r--r--  1 root              root              37174 Aug  8 02:33 alternatives.log
drwxr-xr-x  2 root              root               4096 Aug  8 12:40 apt
-rw-r-----  1 syslog            adm               45255 Aug  8 19:30 auth.log
-rw-------  1 root              root              24051 Aug  8 09:56 boot.log
-rw-r--r--  1 root              root             104003 Jul 31 21:57 bootstrap.log
-rw-rw----  1 root              utmp                  0 Jul 31 21:57 btmp
drwxr-xr-x  2 root              root               4096 Aug  7 21:52 cups
drwxr-xr-x  2 root              root               4096 Jul 21 05:53 dist-upgrade
-rw-r--r--  1 root              adm               78208 Aug  8 09:57 dmesg
-rw-r--r--  1 root              adm               79444 Aug  8 01:36 dmesg.0
-rw-r--r--  1 root              adm               19850 Aug  7 21:52 dmesg.1.gz
-rw-r--r--  1 root              root            1395217 Aug  8 12:40 dpkg.log
-rw-r--r--  1 root              root              32064 Aug  7 22:53 faillog
-rw-r--r--  1 root              root              11126 Aug  8 02:33 fontconfig.log
drwx--x--x  2 root              gdm                4096 Oct  7  2019 gdm3
-rw-r--r--  1 root              root               1242 Aug  8 09:56 gpu-manager.log
drwxr-xr-x  3 root              root               4096 Jul 31 21:59 hp
drwxr-xr-x  2 root              root               4096 Aug  7 21:50 installer
drwxr-sr-x+ 3 root              systemd-journal    4096 Aug  7 21:51 journal
-rw-r-----  1 syslog            adm              767403 Aug  8 19:19 kern.log
-rw-rw-r--  1 root              utmp             292584 Aug  7 22:53 lastlog
drwxr-xr-x  2 root              root               4096 Sep  5  2019 openvpn
drwx------  2 root              root               4096 Jul 31 21:57 private
drwx------  2 speech-dispatcher root               4096 Jan 19  2020 speech-dispatcher
-rw-r-----  1 syslog            adm             2799670 Aug  8 19:42 syslog
-rw-------  1 root              root                  0 Jul 31 21:57 ubuntu-advantage.log
drwxr-x---  2 root              adm                4096 Aug  7 21:52 unattended-upgrades
-rw-rw-r--  1 root              utmp               4992 Aug  8 10:10 wtmp

Each line contains the details about every file in the directory. The details are broken into columns separated by spaces.

File Types

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
Permissions indicate how users can access the files.

Hard Link Count

This number indicates how many hard links point to the file.

User Owner

When a file is created the ownership is automatically assigned to the user who created it.

Group Owner

Shows which group owns the file.

File Size

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.

Timestamp

Indicates the time when the file’s content was last modified.

Filename

The last field contains the name of the file or directory.

Symbolic Links

Symbolic link name will be displayed along with an arrow and the link to the original file.

Sorting

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.

 

Author: Sulthan

Author, Blogger and Assistant Professor in Finance

Leave a Reply

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