Linux

This Page is a Cheat Sheet for Linux. I have collected Info. from the internet and listed it here for easy access for me. If you find it useful then great!

” Everything in a file! ” Even your hardware! e.g. So when you play a movie it is moved into the Monitor file & Speaker file. Your just moving data from 1 file to another!. (This simple fact helped me understand how it all worked)

 

 

  • All software must be installed as Admin – Sudo (super user do!)
  • User accounts can use that software. A User can’t install software (That’s the security part of Linux) Viruses are software so if a user can’t install it …. Viruses can’t run!
  • Daemons are the system software that runs in the background & is controlled by systemd.

The following illustration shows the architecture of a Linux system −

Linux Operating System Architecture

The architecture of a Linux System consists of the following layers −

  • Hardware layer − Hardware consists of all peripheral devices (RAM/ HDD/ CPU etc).

  • Kernel − It is the core component of Operating System, interacts directly with hardware, provides low level services to upper layer components.

  • Shell − An interface to kernel, hiding complexity of kernel’s functions from users. The shell takes commands from the user and executes kernel’s functions.

  • Utilities − Utility programs that provide the user most of the functionalities of an operating systems.

Linux Operating System has primarily three components

  • Kernel − Kernel is the core part of Linux. It is responsible for all major activities of this operating system. It consists of various modules and it interacts directly with the underlying hardware. Kernel provides the required abstraction to hide low level hardware details to system or application programs.

  • System Library − System libraries are special functions or programs using which application programs or system utilities accesses Kernel’s features. These libraries implement most of the functionalities of the operating system and do not requires kernel module’s code access rights.

  • System Utility − System Utility programs are responsible to do specialized, individual level tasks.

Linux Operating System

Kernel Mode vs User Mode

Kernel component code executes in a special privileged mode called kernel mode with full access to all resources of the computer. This code represents a single process, executes in single address space and do not require any context switch and hence is very efficient and fast. Kernel runs each processes and provides system services to processes, provides protected access to hardware to processes.

Support code which is not required to run in kernel mode is in System Library. User programs and other system programs works in User Mode which has no access to system hardware and kernel code. User programs/ utilities use System libraries to access Kernel functions to get system’s low level tasks.

Basic Features

Following are some of the important features of Linux Operating System.

  • Portable − Portability means software can works on different types of hardware in same way. Linux kernel and application programs supports their installation on any kind of hardware platform.

  • Open Source − Linux source code is freely available and it is community based development project. Multiple teams work in collaboration to enhance the capability of Linux operating system and it is continuously evolving.

  • Multi-User − Linux is a multiuser system means multiple users can access system resources like memory/ ram/ application programs at same time.

  • Multiprogramming − Linux is a multiprogramming system means multiple applications can run at same time.

  • Hierarchical File System − Linux provides a standard file structure in which system files/ user files are arranged.

  • Shell − Linux provides a special interpreter program which can be used to execute commands of the operating system. It can be used to do various types of operations, call application programs. etc.

  • Security − Linux provides user security using authentication features like password protection/ controlled access to specific files/ encryption of data.

Custom Kernels are also called micro-kernels, they are striping down versions of the full Kernel with everything you don’t need removed and only the hardware drivers needed.

A perfect example of this is the Raspberry Pi

Here is a guide for you. I always watch his videos,

Love this guys channel defensively bookmark it.

Another Kernel for Gamers & Streamers is XANMOD.

It’s a gaming Kernel, it fine for everyday workloads but with gaming & streaming is optimized.

 

Libraries are short scripts/programs that are used “in” other software. e.g.

Pick any program that has a menu. The menu (it has File, Edit, View, Options & Help.) Because Linux is open source, you can read the software! Most software would have the same code for there menu or very similar, so why code more than you need too. That’s where Libraries come in! Think LEGO for coders.

This makes coding faster on Linux. Less mistakes too and stops security issues from coming up. “OPEN SOURCE”

This “Libraries usage” extend into Drivers & Basic OS functions too. The Kernel is basically a collections of Libraries with priority assigned to them(Who gets processed first).

In Windows it’s “closed source” so each and every piece of software must be complete and you download the complete software on every update.

In Linux only the code that has to be updated/changed gets downloaded. As most of the program are Libraries only the main code that points to each library needs updating. This makes updating fast and small.

If you can think of 2 separate software on Linux that has the “same fetchers” odds are there is a Lib file or soon will be.

In Short Lib’s are “Common code that doesn’t change” that are used by many other programs.

This is why Linux is so small! (Linux iso size 2Gb(with all software) vs Windows 10 iso 8Gb!)

Linux filesystem structures and understand the meaning of individual high-level directories.

/ – Root

  • Every single file and directory starts from the root directory.

  • Only root user has write privilege under this directory.

  • Please note that /root is root user’s home directory, which is not same as /.

/bin – User Binaries

  • Contains binary executables.

  • Common linux commands you need to use in single-user modes are located under this directory.

  • Commands used by all the users of the system are located here.

  • For example: ps, ls, ping, grep, cp.

/sbin – System Binaries

  • Just like /bin, /sbin also contains binary executables.

  • But, the linux commands located under this directory are used typically by system aministrator, for system maintenance purpose.

  • For example: iptables, reboot, fdisk, ifconfig, swapon

/etc – Configuration Files

  • Contains configuration files required by all programs.

  • This also contains startup and shutdown shell scripts used to start/stop individual programs.

  • For example: /etc/resolv.conf, /etc/logrotate.conf

/dev – Device Files

  • Contains device files.

  • These include terminal devices, usb, or any device attached to the system.

  • For example: /dev/tty1, /dev/usbmon0

/proc – Process Information

  • Contains information about system process.

  • This is a pseudo filesystem contains information about running process. For example: /proc/{pid} directory contains information about the process with that particular pid.

  • This is a virtual filesystem with text information about system resources. For example: /proc/uptime

/var – Variable Files

  • var stands for variable files.

  • Content of the files that are expected to grow can be found under this directory.

  • This includes — system log files (/var/log); packages and database files (/var/lib); emails (/var/mail); print queues (/var/spool); lock files (/var/lock); temp files needed across reboots (/var/tmp);

/tmp – Temporary Files

  • Directory that contains temporary files created by system and users.

  • Files under this directory are deleted when system is rebooted.

/usr – User Programs

  • Contains binaries, libraries, documentation, and source-code for second level programs.

  • /usr/bin contains binary files for user programs. If you can’t find a user binary under /bin, look under /usr/bin. For example: at, awk, cc, less, scp

  • /usr/sbin contains binary files for system administrators. If you can’t find a system binary under /sbin, look under /usr/sbin. For example: atd, cron, sshd, useradd, userdel

  • /usr/lib contains libraries for /usr/bin and /usr/sbin

  • /usr/local contains users programs that you install from source. For example, when you install apache from source, it goes under /usr/local/apache2

/home – Home Directories

  • Home directories for all users to store their personal files.

  • For example: /home/john, /home/nikita

/boot – Boot Loader Files

  • Contains boot loader related files.

  • Kernel initrd, vmlinux, grub files are located under /boot

  • For example: initrd.img-2.6.32-24-generic, vmlinuz-2.6.32-24-generic

/lib – System Libraries

  • Contains library files that supports the binaries located under /bin and /sbin

  • Library filenames are either ld* or lib*.so.*

  • For example: ld-2.11.1.so, libncurses.so.5.7

/opt – Optional add-on Applications

  • opt stands for optional.

  • Contains add-on applications from individual vendors.

  • add-on applications should be installed under either /opt/ or /opt/ sub-directory.

/mnt – Mount Directory

  • Temporary mount directory where sysadmins can mount filesystems.

/media – Removable Media Devices

  • Temporary mount directory for removable devices.

  • For examples, /media/cdrom for CD-ROM; /media/floppy for floppy drives; /media/cdrecorder for CD writer

/srv – Service Data

  • srv stands for service.

  • Contains server specific services related data.

  • For example, /srv/cvs contains CVS related data.

The file system is the same for all Linux/Android systems, no matter how big or small they are! But How!?! Right!

A OS is not Installed on a Hard-drive, it is installed on a Partition. A Partition can be made up of several drives like in a RAID. Your BIOS of your computer points to a hard-drive that has a Bootable Partition = MBR or GPT. This then boots the OS Partition.

The hardware (hard-drives) & File structure are separate because of Partitions!

Think of C:/ on windows as Root (/). In Windows you can add a hard-drive as an extended partition(a folder on C:/) but if the original hard-drive dies then it’s dead too which is why it is generally given the D:/ and a shortcut is used.

But in Linux….

Linux is designed for expansion. Expansion while the machine is still running(Servers). Each folder can be moved to a new “Partition” while running & then the “daemon” can be reloaded for fstab (the file system software).

For example.

“ROOT” (/) & all software can be on a Very Fast but Small NVMe drives partition saving money and have “/Home”(Where your user data is stored) on a Huge slower spinning hard-drives partition or RAID’s partition!

https://help.ubuntu.com/community/Partitioning/Home/Moving

Remember Linux was made for Universities & Businesses where there are hundreds of users. Which is why there are 2 types : ADMIN vs USER.

This is also why your tweaks to programs are stored in your /Home folder too. Each user can tweak the same software but those “tweaks” only affect that user. Only a Admin account can make system wide changes like installing software.

If you want to really get into Linux, the only real way is to build it. Now there are 2 ways. Gentoo or Actually building Linux from scratch.

Which one should you do? First! Well that’s an easy one! Gentoo.

After if you really want to learn how everything, I mean everything works. Build your own!

I personally have not done this as I’m just a “User”! & I don’t care how it works just that it does! I Know I should but….. I don’t need to know how to bake a cake to be able to eat it! If you want deep knowledge of Linux these 2 are your best bet, and after your learning bug is satisfied you can join me on Kubuntu! LOL

Here is a video on KDE & it explains it all. KDE NEON might be a better fit for you!

There are 4 main branches of Linux: Debian, Red Hat, SuSe & Arch.

From the diagram you can see that there are many different distributions of Linux, in fact there are thousands and each one is unique. But that’s a longer story, and for another time!

The distro. that we are interested in is Debian.Why?

Debian is considered the grand father of Linux because it has been around from just about the beginning. It is a slow and stable distro. and so a lot of other distro.’s are based on it, like Ubuntu. (But the most important os is SteamOS. Steam has made Industry standards for game developers making Linux compatable for AAA games.)

Ubuntu is backed by a company called Canonical. There main focus is business software like servers and IOT devices. The desktop is a side business for them. So what’s different? PPA’s & SNAP’s…. How software is installed. We will get into installing software later.

User Interface (UI) or Desktop Enviroment (DE)

Unlike Apple or Microsoft that only have one desktop environment Linux has many, like – Gnome, KDE, LXqt, LXde, XFCE, i3, Mate, Cinnimon, budgie etc, etc. With each one being slightly different from the other.

Here is a site that has them all! “Distro Hopping” is a favorite past-time for every Linux user. Finding the right Linux for the job & hardware is always fun. The reason I have Guided you the Debian side is Help websites. Most will reference Ubuntu so it’s a great place to start! Have fun!

Distrowatch.com

Understanding Basic File Permissions and ownership in Linux

You should understand “system software”,”user software”, Who has permissions to all files for reading, writing & execution. & How to install software for users.

There is you the owner “User”, group for your files is normally you too.

But there are system files so group “Sudo” needs access to execute a system program. & groups for each part of the OS , sound, USB, graphics etc etc …. All with permissions creating more security!