Linux For Beginners Part 2 - Terminal and File Systems

Linux For Beginners Part 2 - Terminal and File Systems

In this article, we are going to dive deep into using the Linux terminal. We will cover what the terms 'terminal' and bash mean. We also look deep at the different file directories on the linux system. Here we go!

Prerequisites

I assume you have new to the Linux distro. If you are and want to get a peek of what this sudo life is all about, kindly read part 1 of this series here.

The Terminal

The Linux terminal acts as the medium for input and output operations for a Linux system. A Linux console terminal is similar to the command line in Microsoft Windows but it differs in that it can perform any operation on the system.

With windows, there are some specific operations you can't perform on the regular command prompt, you will need the Windows Powershell to achieve this.

The terminal is basically a GUI where you as the Linux user provides an input, however, The shell is the program that actually processes commands and returns the output. The terminal program just gives it a medium to interact with the graphical environment. There are different types of Linux shell out there, the most popular one is the Bourne-Again-Shell or Bash as it is called.

Now that we have understood what the terminal and bash means, let us go on to some basic terminology(pun intended). Launch to a terminal on your ubuntu-desktop. To do that click the Ubuntu logo on the top left of your computer screen or better still click the home button on your keyboard to display all applications on your ubuntu distro. I use a Lubuntu( a derivative of Ubuntu ), my home button looks like this:

canva-photo-editor.png

When you click on it, locate the terminal and launch it, if you can't find it you can simply search for it in the search bar above.

Once you open your terminal, you are greeted with a terminal like the one on the cover image of this article.

To your left a certain address is displayed in green and it ends with a dollar sign

  jackhoudini@houdini : ~$      

The first word represents the user logged into the Linux system, the @houdini represents the hostname of the Linux computer. The ~$ represents the path at which the bash terminal is now which is the current user's(jackhoudini) home path. In simple words we can represent them as:

     username-@hostname-file-path 

Before we go on, we need to understand that everything in a Linux system comprises files and each file has a particular path. Below is a descriptive picture of what the file system looks like:

/
├── bin
├── boot
├── cdrom
├── dev
├── etc
├── home
├── initrd.img -> boot/initrd.img-4.15.0-106-generic
├── initrd.img.old -> boot/initrd.img-5.3.0-59-generic
├── lib
├── lib32
├── lib64
├── lost+found
├── media
├── mnt
├── opt
├── proc
├── root
├── run
├── sbin
├── snap
├── srv
├── swapfile
├── sys
├── tmp
├── usr
├── var
├── vmlinuz -> boot/vmlinuz-4.15.0-106-generic
└── vmlinuz.old -> boot/vmlinuz-5.3.0-59-generic

The first '/' is the entry point of all file system in Linux, it can be defined as the alpha path of all your Linux file path. I'll be discussing what each of this file does. We begin:

/bin

  • This is the directory that contains and houses all your binary files, that is, some of your applications that you can run on your system. Think of if as a toolbox for housing your Linux tools. This particular bin folder contains the program for some linux commands such as ls which will be discussed later on

/boot

  • This directory contains all the needed files required to start your Linux system. You are not expected to touch this file because any edit or deletion could cause damage to your Linux system. No need to panic as you require Administrative Privileges to do that. Still don't touch it

/cdrom

  • This directory contains all the needed files required to run a program on your cd drive. You should not touch this also. Curiosity should not kill the cat either.

/dev

  • This contains all files needed for your external devices to communicate with your Linux systems. Most of these files are generated at boot time or on the fly. If a new device like a headset is plugged into your computer, the device file will be generated and added to this file.

/etc

  • etc is an acronym for 'Everything to configure'. It contains all system-wide configuration files for your Linux system. It contains the files that contain the name of your system, the configuration for your web servers if you run Linux on the server, the users and their passwords, the names of machines on your network, and when and where the partitions on your hard disks should be mounted are all in here. Again, if you are new to Linux, it may be best if you don’t touch too much in here until you have a better understanding of how things work.

/home

  • This is where you will find your users’ personal directories. Every user created on a Linux system will have a directory that houses all their files and this is where it will be housed.

/initrd

  • initrd is a scheme for loading a temporary root file system into memory, which may be used as part of the Linux startup process.

/lib

  • This is where libraries live. Libraries are files containing code that your applications can use. They contain snippets of code that applications use to draw windows on your desktop, control peripherals, or send files to your hard disk.

  • There are more lib directories scattered around the file system, but this one, the one hanging directly off of / is special in that, among other things, it contains the all-important kernel modules. The kernel modules are drivers that make things like your video card, sound card, WiFi, printer, and so on, work.

/lost + found

  • Supposing you abruptly switch off your computer by pressing the off button as opposed to the normal PC shutdown, while it’s running and files are being written to the hard drive, this directory houses those files that get corrupted or are unsaved during such operation. It is worth to note that you can’t delete the lost+found folder either, since it’s a permanent part of the file system. However, if you find useless file fragments inside the lost+found folder that you can’t piece back together, you can delete them using the terminal to free up space.

/media

  • The /media directory is where external storage will be automatically mounted when you plug it in and try to access it.

/mnt

  • The /mnt directory and its subdirectories are intended for use as the temporary mount points for mounting storage devices, such as CDROMs, floppy disks, and USB (universal serial bus) key drives. However, It is not used very often nowadays.

/opt

  • The /opt directory is often where software you compile (that is, you build yourself from source code and do not install from your distribution repositories) sometimes lands. Applications will end up in the /opt/bin directory and libraries in the /opt/lib directory.

/proc

  • This directory contains information about your computer, such as information about your CPU and the kernel your Linux system is running. As with /dev, the files and directories are generated when your computer starts, or on the fly, as your system is running and things change.

/root

  • This directory is the home directory of the superuser (also known as the “Administrator”) of the system. It is separate from the rest of the users’ home directories BECAUSE YOU ARE NOT MEANT TO TOUCH IT.

/run

  • This directory is used by system programs to temporarily store data. You are advised not to touch this folder either.

/sbin

  • /sbin is similar to /bin, but it contains applications that only the superuser (hence the initial s) will need. You can use these applications with the sudo command that temporarily concedes you superuser powers on many distributions. /sbin typically contains tools that can install stuff, delete stuff and format stuff. As you can imagine, some of these instructions are lethal if you use them improperly, so handle with care.

/snap

  • snap is a package manager on ubuntu. it is used to install applications and programs on linux. This directory houses every program installed on your computer using snap

/srv

  • The srv or serve directory holds site specific data to be served by the system for protocols such as ftp, rsync, www, cvs and many more.

/swapfile

  • A swapfile is a space on a hard disk used as the virtual memory extension of a computer's real memory. It allows your computer's OS to pretend that it possesses mor RAM than it actually has. This directory stores such files

/sys

  • This is a virtual filesystem that stores and allows modification of the devices connected to the system. It stores temporary files for user and system, till next boot time.

/tmp

  • /tmp contains temporary files, usually placed there by applications that you are running. The files and directories often (not always) contain data that an application doesn’t need right now, but may need later on. It is one of the directories that does not require a superuser priviledge to access.

/usr

  • usr is an acronym for 'user system resource'. This directory is by far the largest share of data in a linux system. It contains a mish-mash of directories which in turn contain applications, libraries, documentation, wallpapers, icons and a long list of other stuff that need to be shared by applications and services.

/var

  • The name var as you know stands for 'variable', if you are coming from a programming background and what this means is that it changes frequently. Therefore this directory contains files that change frequently on a linux system, one of such file is the log file. Logs are files that register events that happen on the system. If something fails in the kernel, it will be logged in a file in /var/log; if someone tries to break into your computer from outside, your firewall will also log the attempt here. It also contains spools for tasks. These “tasks” can be the jobs you send to a shared printer when you have to wait because another user is printing a long document, or mail that is waiting to be delivered to users on the system.

Conclusions

Phew! That was a lot of information there, i know. In the final part of this series, we are going to dive deep into some fantastic bash commands. These commands will help you navigate through these directories we have listed here, create new directories, create new files and manipulate the contents of each file created. You will also get a sneek peak of how to automate some repeated task in linux. Stay tuned!

PS: If you love this article, don't forget to click the like button and share with your friends. I always appreciate feedbacks so don't be shy to leave them here or in my DM's on twitter. Follow @jackhoudini__