Categories
Linux Tutorial Series

Linux Tutorial Series – 197 – Recap

Here is the video version, if you prefer it:

Let’s recap what we learned about shell scripting:

  • Shell scripts are files that contain commands (alongside some shell scripting keywords)
  • Use shell scripts to manipulate files; if you find yourself manipulating strings or doing arithmetic work, do something else
  • A line starting with #! is called a shebang
  • A line starting with a # is called a comment – it is ignored by the interpreter and serves only for human understanding of the shell script
  • Use single quotations unless you have a very good reason not to
  • There are special variables – for example, $1 corresponds to the first argument in your script – as well as some other ones
  • Exit codes tell you “how did the command do”
  • If statement follows the logic of “if this then that”
  • Else statement follows the logic of “if this then that, if not (else) then the other thing”
  • Logical operators are used to combine tests together
  • You can test for various conditions in a test
  • Use a case construct instead of a lot of elifs
  • for is used for iteration
  • Command substitution can be used to put the output of the command in a variable or to pass it as input to another command
  • You can read user input with read variableName

I hope you refreshed your memory!

Categories
Linux Tutorial Series

Linux Tutorial Series – 176 – Review

Here is the video version, if you prefer it:

Let’s recap the main points:

  • Use cron to schedule things periodically; use at to schedule things only once
  • Every single computer in a computer network has an IP address through which it can be addressed
  • ip command is used to see information about your network interfaces
  • Use ping someWebsite to check your Internet connection (you should have no packet loss)
  • Use ssh to login to a remote host
  • Use scp for copying files to/from a remote host
  • X Window System is related to the Linux desktop
  • Build systems exist to ease the process of creating an executable from source code
  • To build something from source code do the following: 1. Download the folder with the source code; 2. Run ./configure; 3. Run make; 4. Run make install

Hope you refreshed your memory!

Categories
Linux Tutorial Series

Linux Tutorial Series – 159 – Review

Here is the video version, if you prefer it:

Let’s review what we learned.

Here is how your computer boots up:

  1. A boot loader is ran by machine’s BIOS or boot firmware
  2. The boot loader finds the kernel image on disk, loads it into memory, and starts it
  3. The kernel initializes the hardware devices and its drivers
  4. The kernel mounts the root filesystem
  5. The kernel starts a program called init; init has PID equal to 1
  6. init starts all of the other necessary system processes
  7. At some point at or near the end of this entire process, you get the option to log in to your system

Here is how the user space starts up:

  1. init
  2. Essential low-level services which enable managing hardware devices and system logging
  3. Network configuration
  4. Mid and high-level services (such as cron (used for scheduling tasks) and printing)
  5. Login prompts, GUIs, and other high-level applications

When shutting down your computer, the following goes on:

  1. init asks every process to shut down
  2. If some processes (or a process) don’t respond, init initiates a kill with a TERM signal
  3. If some processes (or a process) don’t respond still, init initiates a kill with a KILL signal
  4. The system makes preparations for a shutdown
  5. The system unmounts all of the other filesystems other than root
  6. The system remounts the root filesystem in read-only mode (meaning you can’t write, only read)
  7. The system writes out all of the data left over in the buffers to the filesystem (this happens during the remounting process)
  8. The kernel reboots or stops the system

Other things to mention:

  • Boot loaders job is to load the kernel into memory and start it with a set of parameters
  • demsg command is used to display kernel messages, or you can look at /var/log/kern.log
  • init is the process which starts all system services
  • shutdown command is used to shut down or restart your system

Talk soon!

Categories
Linux Tutorial Series

Linux Tutorial Series – 150 – Review

Here is the video version, if you prefer it:

Let’s review what we learned:

  • Permanent storage device is the physical device your data is stored on
  • Partitions are subdivisions of the whole disk
  • A filesystem is a hierarchy of files and directories you are accustomed to interacting
  • Files and directories are represented as inodes
  • Link is a pointer to a file or a directory
  • Hard links point to the underlying data and symbolic links are like shortcuts
  • Devices (represented as files) are located in the /dev folder
  • Mounting is the process of attaching your device (your device’s storage) in the Linux directory structure; unmounting is the reverse process
  • Unmounting is important because it writes the data in the buffer to the device
  • Hash functions are used for checking file integrity

Talk soon!

Categories
Linux Tutorial Series

Linux Tutorial Series – 136 – Review

Here is the video version, if you prefer it:

We talked about compression and package management. Here is a review of the most important things:

  • Use gzip fileName and gunzip fileName for archives ending in gz
  • Use tar cvf archiveName.tar file1 file2 … for creating a tar archive file and use tar xvf archiveName.tar to extract a tar archive
  • To update your package list, run apt-get update (prefixed with sudo)
  • apt-get install packageName to install packages from a package repository or dpgk -i packageFileName to install a package from a file
  • sudo apt --purge remove packageName to remove a package, then sudo apt --purge autoremove to remove its dependencies
  • To upgrade your packages, run apt-get upgrade
  • /etc/apt/sources.list keeps a list of repositories Linux looks into when it is searching for new packages

I hope you refreshed your memory!

Categories
Linux Tutorial Series

Linux Tutorial Series – 123 – Review

Here is the video version, if you prefer it:

We talked about file modes and permissions. Let’s review that on an example:

-rw-r--r--

First character (looking from left to right) tells us if we are talking about a file or a directory or something else, the next three characters tell us user permissions, the next three tell us group permissions and the next three tell us world permissions.

Then we talked about the following:

  • chmod is used to change file permissions
  • chown is used to change file owner
  • umask defines the default permissions (keep in mind the octal to binary conversion we talked about and how it relates to permissions)
  • passwd is used to change users password
  • adduser is used to add users
  • userdel command is used to delete users
  • /etc/passwd keeps users and their IDs, while /etc/sudoers keeps the list of users who can execute the sudo command

Hope you refreshed your memory!

Categories
Linux Tutorial Series

Linux Tutorial Series – 113 – Review – revisiting top’s columns

Here is the video version, if you prefer it:

Let’s look at the output produced by top and explain what does it all mean:

mislav@mislavovo-racunalo:~/Linux_folder$ top

top - 13:15:58 up 101 days, 19:37, 1 user, load average: 0.44, 0.42, 0.44

Tasks: 241 total, 1 running, 239 sleeping, 0 stopped, 1 zombie

%Cpu(s): 0.2 us, 0.1 sy, 0.0 ni, 99.7 id, 0.0 wa, 0.0 hi, 0.0 si, 0.0 st

MiB Mem : 7853.8 total, 127.8 free, 4300.2 used, 3425.8 buff/cache

MiB Swap: 8066.0 total, 6694.0 free, 1372.0 used. 2891.4 avail Mem

PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND

8770 mislav 20 0 3002016 320192 111444 S 1.0 4.0 5:46.85 Web Content

8357 mislav 20 0 3524552 369556 151704 S 0.3 4.6 5:26.81 firefox-esr

14417 mislav 20 0 4222052 321880 168376 S 0.3 4.0 0:31.67 anki

...

  • First we have some information about current time, how long my machine has been running and how many users are logged in (Shotts, 2019)⁠
  • load average – how many processes is your computer executing in the last minute, last 5 minutes, last 15 minutes
  • Tasks – how many tasks are there on the computer – 1 is running (meaning being actively executed), 239 are sleeping (meaning waiting for something to happen (such as data from a device) to resume their execution), 0 stopped (meaning no processes whose execution was paused manually) and 1 zombie process (zombie process is a process whose parent process doesn’t exist anymore)
  • %Cpu(s) tells us what percentage of the CPU is being used on what kinds of processes: us is for user processes, sy is for system (kernel) processes, ni is for nice (low-priority) processes, id is for the percentage of the CPU that is idle, wa is for percentage of the CPU waiting for some input/output tasks, hi is the time spent processing hardware interrupts, si is the time processing software interrupts and st is relevant to virtual environments – if you don’t know what virtual environments are, that needn’t concern you (“Linux ‘top’ command: What are us, sy, ni, id, wa, hi, si and st (for CPU usage)?,” n.d.)⁠
  • MiB Mem and MiB swap tell you how much RAM and how much swap space is being used (measured in mebibytes (“Mebibyte,” n.d.)⁠)

Let’s now look at the columns available for each process: (“A Guide to the Linux ‘Top’ Command,” n.d.)⁠

  • PID – proces ID
  • USER – user who owns the process
  • PR – process priority
  • NI – niceness (nice value) of a process
  • VIRT – total amount of memory consumed by the process (permanent storage device + RAM – the basic idea is that if the operating system runs out of RAM, it can use some memory available on the permanent storage device in addition to the RAM; this concept is called virtual memory – look it up on Google if you are interested)
  • RES – memory consumed by the process in RAM
  • SHR – amount of memory shared with other processes (processes can share memory)
  • S – process state (is the process running, is it sleeping, …)
  • %CPU – how much CPU is the process using (in percentages)
  • %MEM – how much memory is the process using (in percentages)
  • TIME+ – total time used by the process since it started
  • COMMAND – the name of the process

Hope you understand the output of top in detail now and hope you refreshed your memory!

References

A Guide to the Linux “Top” Command. (n.d.). Retrieved February 19, 2020, from https://www.booleanworld.com/guide-linux-top-command/#Understanding_top8217s_interface_the_task_area

Linux “top” command: What are us, sy, ni, id, wa, hi, si and st (for CPU usage)? (n.d.). Retrieved February 19, 2020, from https://unix.stackexchange.com/questions/18918/linux-top-command-what-are-us-sy-ni-id-wa-hi-si-and-st-for-cpu-usage

Mebibyte. (n.d.). Retrieved February 19, 2020, from https://en.wikipedia.org/wiki/Mebibyte

Shotts, W. (2019). The Linux Command Line, Fifth Internet Edition. Retrieved from http://linuxcommand.org/tlcl.php. Pages 137-139

Categories
Linux Tutorial Series

Linux Tutorial Series – 94 – Review

Here is the video version, if you prefer it:

We looked at both Emacs and vi and took a stroll around their basic commands. Here are the most essential of the essential:

Emacs:

  • C-x 1 (C-x means CTRL + x) for closing all but one window
  • C-x C-s for saving a file
  • C-Space, then C-w for cutting (killing) a piece of text
  • C-y for pasting (yanking) a piece of text

vi:

  • There are two modes – insert and command
  • To enter insert mode, press i, or to append to the end of the line the cursor is on, press A
  • Escape insert mode with Esc
  • Delete characters (while in command mode) with x
  • Save and quit by writing :wq and pressing Enter

Talk soon!

Categories
Linux Tutorial Series

Linux Tutorial Series – 88 – Review

Here is the video version, if you prefer it:

We looked at history and variables. In particular, we looked at:

  • history is used to look at history; use CTRL + R for reverse search in history and CTRL + J to copy the command to your clipboard
  • Dot files (files whose filenames begin with a dot) are hidden by default
  • Variables are named parts of computer memory where values are stored
  • Environment variables are variables passed to the shell by the operating system
  • Shell variables are local to the shell
  • Command path stores all of the places to look for executables
  • Interactive shells require user input, non-interactive don’t
  • Login shells exist to do some things only once
  • Your Terminal application is an interactive, non-login shell
  • Place almost all changes you want permanently in .bashrc file in your home directory

Let’s carry on with our Linux journey!

Categories
Linux Tutorial Series

Linux Tutorial Series – 75 – Review

Here is the video version, if you prefer it:

We talked about command types, which there are 4 – executables, shell built-ins, shell functions and aliases, as well as the commands used to determine the type of a particular command. We also talked about finding files – both locate and find – and (hopefully) memorized the syntax find dir -name file -print.

We also covered some other stuff, but the above ones are the most important.