Linux – Learning the Shell (Part 4)

Today I’ve reached a benchmark. I’ve completed all 10 sections of Learning the Shell from The Linux Command Line by William Shotts. The last two sections I had remaining were sections 9 and 10, which cover Permissions and Job Control. These sections were mostly a refresher for me, as I was already familiar with the material from when I previously ran various flavors of Linux some years ago. Still, I found it beneficial to go through each example and ensure that I fully understood the concepts and commands presented.

For documentation purposes, and without further comment, here are my notes from Learning the Shell, Sections 9 – 10:

9. Permissions

Linux is a multi-user system; permissions control who can read, write, or execute files.

File ownership:

Each file has an owner (user) and a group.

Permission categories:

User (u): the file’s owner.
Group (g): members of the file’s group.
Others (o): everyone else.

Permission types:

r (read): view contents (or list directory contents).
w (write): modify contents (or add/remove files in a directory).
x (execute): run as a program (or enter a directory).

Viewing permissions:

# Shows file permissions in symbolic form (e.g., -rw-r--r--
ls -l

Changing permissions:

# Modifies permissions.
chmod

Symbolic mode:

# Adds execute for user.
chmod u+x file

Numeric mode:

# Sets rwx for user, r-x for group/others.
chmod 755 file

Changing ownership:

# Changes file owner.
chown
# Changes file group.
chgrp

Special permissions:

setuid/setgid: run with file owner/group privileges.
sticky bit: restricts file deletion in shared directories (e.g., /tmp).

10. Job Control

The shell can run multiple processes (jobs) simultaneously.

Foreground vs. background:

Foreground: job runs interactively, blocking the shell.
Background: job runs without blocking (command &).

Managing jobs:

# Lists current jobs.
jobs
# Brings jobs to foreground.
fg %n
# Resumes job "n" in background.
bg %n

Suspending jobs:

# Suspends a foreground job.
CTRL+Z

Process management:

# Lists running processes.
ps
# Terminates a process (kill -9 PID for force).
kill

Practical examples:

# Runs sleep in background.
sleep 100 &
# Brings it back to foreground.
fg
# Kills job number 1.
kill %1

This is just me demonstrating ps in my shell.

Next on the agenda is to work through the 15 sections of Writing Shell Scripts. This is the part I’ve been looking forward to. I’ve written some simple Bash scripts before (and have done some batch file scripting in Windows), but most of that work was done ad hoc without really delving into the fundamental principles. Using this online resource as a formal introduction to Bash, and the Linux terminal in general, has been helpful in preparing me to move on to other materials that go more in depth, such as the LPIC-1 Study Guide.