CourseNotes_Linux CentOS 7 Shells and Processes
CourseNotes_Linux CentOS 7 Shells and Processes
Description: In this course, gain a more thorough understanding of the shell and
system processes to help you work faster and more efficiently in Linux. Follow
computer science instructor and Linux enthusiast Grant McWilliams as he dives into
Linux shells and their environments, and explains how to customize your shell. He
discusses using the Bash shell, and covers topics like command and variable
substitution. Grant also explains how to stack simpler commands together using
named and unnamed pipes and redirects; discusses how to start, pause, and end
processes; shows how to schedule one-time jobs and recurring jobs; and covers
complex system services.
***********************************************
Chapter: 1. Linux Shells Overview
***********************************************
-----------------------------------------------
Video: Shell types
-----------------------------------------------
Note Time: Note Text:
Bourne Shell (sh): One of the earliest shells, basic but POSIX-compliant.
C Shell (csh): Resembles the C programming language, but not commonly used for
scripting anymore.
Korn Shell (ksh): Introduced job control and command history.
Bash (Bourne Again Shell): The most popular shell, combines features from Bourne
and Korn shells and is mostly POSIX-compliant.
Dash: A lightweight shell, uses less memory, popular on Debian-based systems.
Fish: Focuses on user-friendliness with features like syntax highlighting and
command suggestions.
Zsh: Similar to Bash but with enhanced features like better command completion and
pattern matching.
-----------------------------------------------
Video: Variables and shell environment
-----------------------------------------------
Note Time: Note Text:
-----------------------------------------------
Video: Shell tips and tricks
-----------------------------------------------
Note Time: Note Text:
0:02:30 To quickly move between the beginning and end of the line, just
use the Home and End keys
-----------------------------------------------
Video: Shell history tricks
-----------------------------------------------
Note Time: Note Text:
0:02:03 see what commands you've typed in,--> use the history command
to last command u typed --> use !!
to show last n line command -->!-n
to show nth line --> !n
show the line starting with ls--> !ls
If you want to run a command with a previous line's arguments and options--> you
can append !* to the command name --> example : cd !*
-----------------------------------------------
Video: Configure shell history
-----------------------------------------------
Note Time: Note Text:
0:02:16 To keep certain lines from being recorded, we can place them in
the hist ignore variable.
export HISTIGNORE =" history*"-->this is going to ignore any lines that start with
the word history and are followed by any number of characters
0:05:16 our history is saved and the file named .bash_history, in our
home directory.
We can choose how many lines are saved in this file by this command:
export HISTFILESIZE = 10,000.
Set this to zero if you want to turn off saving of your command
history on the disk.
All of these changes we've made so far are just for our current
login session, -- > make it permanent open the directory --> insert mode --> type
same commands
-----------------------------------------------
Video: Pattern matching with globs
-----------------------------------------------
Note Time: Note Text:
-----------------------------------------------
Video: Pattern matching with extended globs
-----------------------------------------------
Note Time: Note Text:
***********************************************
Chapter: 2. Using the Bash Shell
***********************************************
-----------------------------------------------
Video: Escape characters and quotes
-----------------------------------------------
Note Time: Note Text:
0:01:23 To show the value of a variable, you use the echo command with a
$ sign before the variable name.
-----------------------------------------------
Video: Brace and path substitution
-----------------------------------------------
Note Time: Note Text:
-----------------------------------------------
Video: Named and unnamed pipes
-----------------------------------------------
Note Time: Note Text:
0:01:45 If we want to send output from a command in one terminal to
another command in a different terminal, we can use a named pipe or FIFO. FIFO
stands for first in, first out.
-----------------------------------------------
Video: File redirects and tees
-----------------------------------------------
Note Time: Note Text:
***********************************************
Chapter: 3. Linux Processes
***********************************************
-----------------------------------------------
Video: Introduction to processes
-----------------------------------------------
Note Time: Note Text:
-----------------------------------------------
Video: Monitor processes using ps
-----------------------------------------------
Note Time: Note Text:
Typing ps in the terminal shows processes run by the current user, displaying
columns like process ID (PID), terminal, execution time, and command.
Syntax Options:
ps has three syntax types: Unix (e.g., -e), BSD (no dashes, e.g., e), and GNU
(double dashes, e.g., --format).
Displaying All Processes:
Detailed Information:
ps -ef adds more details like user name, parent process ID, CPU usage, start time,
and command with arguments.
ps -eF includes memory usage and the CPU the process is running on.
ps -elF provides even more columns of information.
Customizing Output:
You can customize the output with --format. For example, ps -e --format
uid,pid,ppid,%cpu,cmd shows user ID, process ID, parent process ID, CPU
utilization, and command.
Sorting can be done with --sort. For instance, ps -e --sort %cpu sorts processes by
CPU usage.
Filtering by Command:
-----------------------------------------------
Video: Monitor processes in real time
-----------------------------------------------
Note Time: Note Text:
Renice a Process: Press R, enter the PID, and set a new nice value to
change its priority.
The higher the nice value, the nicer the process is to the CPU and
thus less priority it gets. Lowering the nice value increases its priority.
Quick Sorting
Sort by Memory Usage: Press M.
Sort by CPU Usage: Press P.
Sort by Running Time: Press T.
Sort by Process ID: Press N.
Additional Resources
Manual Page: For more features, type man top
-----------------------------------------------
Video: Monitor processes graphically
-----------------------------------------------
Note Time: Note Text:
-----------------------------------------------
Video: Manage processes
-----------------------------------------------
Note Time: Note Text:
0:00:02 kill -USR1 <PID>: Sends the USR1 signal to a process. Example:
kill -USR1 $(pidof dd)
kill: Use kill <PID> to send a signal to a process. By default, it sends a SIGTERM
signal (15) to terminate the process.
List Signals: kill -l shows all possible signals.
Common Signals:
SIGTERM (15): Gracefully terminate a process.
SIGKILL (9): Forcefully kill a process.
SIGHUP: Often used to reload configuration files.
pidof: Use pidof <process_name> to get the PID of a specific process. Example:
pidof firefox.
pgrep: Similar to pidof, but more powerful. Example: pgrep firefox.
-----------------------------------------------
Video: Process priority
-----------------------------------------------
Note Time: Note Text:
-----------------------------------------------
Video: Manage process jobs
-----------------------------------------------
Note Time: Note Text:
***********************************************
Chapter: 4. Job Scheduling
***********************************************
-----------------------------------------------
Video: One-time jobs using at and batch
-----------------------------------------------
Note Time: Note Text:
At the prompt, type the commands you want to run. For example:
sh
touch ~/batchfile.txt
Verify Jobs: Use atq to list batch jobs. If the job doesn't appear, it has already
run.
Check Job Completion: Verify the job ran by checking if the file was created with
ls -l ~/batchfile.txt.
You'll get a prompt where you can type the commands you want to run.
For example:
sh
mkdir ~/Documents.bak
rsync -a ~/Documents/ ~/Documents.bak/
0:00:07 jobs Command: This command lists all the jobs you have started
in the current terminal session.
bg Command: This command resumes a stopped job in the background.
fg Command: This command brings a background job back to the foreground,
killall Command: This command terminates all processes.
-----------------------------------------------
Video: Reccuring user jobs using cron
-----------------------------------------------
Note Time: Note Text:
* * * * * /path/to/command
| | | | |
| | | | +---- Day of the week (0 - 7) (Sunday is both 0 and 7)
| | | +------ Month (1 - 12)
| | +-------- Date (1 - 31)
| +---------- Hour (0 - 23)
+------------ Minute (0 - 59)
*/10 * * * * your_command
Minute: (0-59) When the task will run within the hour.
Hour: (0-23) When the task will run within the day.
Day of Month: (1-31) When the task will run within the month.
Month: (1-12 or JAN-DEC) When the task will run within the year.
Day of Week: (0-6 or SUN-SAT) When the task will run within the week.
Command: The command to execute.
System Crontab:
Managed by the superuser.
Stored in /etc/cron.d.
-----------------------------------------------
Video: Reccuring system jobs using cron
-----------------------------------------------
Note Time: Note Text:
0:01:35 By default, the allow file does not exist so all users are
allowed.
0:02:12 We can also control access to the cron service using pluggable
authentication modules or PAM. PAM provides a modular authentication system for all
Linux services.
***********************************************
Chapter: 5. System Services
***********************************************
-----------------------------------------------
Video: Introduction to system services
-----------------------------------------------
Note Time: Note Text:
0:00:50 System services are processes that are started by the OS and sit
in the background waiting to answer requests. These services might include web
servers, file servers, mail servers, and others. In Linux, a system service is
called a daemon,
-----------------------------------------------
Video: Get systemd service status
-----------------------------------------------
Note Time: Note Text:
0:00:21 System D objects are called units and for each unit, there's a
unit file for configuration.
0:00:49 The command that System D uses to manage these units is system
CTL.
-----------------------------------------------
Video: Manage systemd services
-----------------------------------------------
Note Time: Note Text:
systemctl list-unit-files -t service: Lists all services and shows if they are
enabled or disabled.
Stop a Service:
Start a Service:
Restart a Service:
0:02:25 EXTRA
Understanding systemctl Commands
systemctl list-unit-files -t service: Shows all service unit files and their status
(enabled, disabled, or static).
Columns:
Service Name: Name of the service.
Loaded: Whether the unit file is loaded.
Active: General state (active, inactive).
Sub: Detailed state (running, exited).
Description: Brief description of the service.
systemctl list-units -t service --state running: Lists only the currently running
services.
systemctl cat [service_name]: Displays the unit file for a specific service.
Example: systemctl cat rsyslog shows the configuration for the rsyslog service.
Example: systemctl status rsyslog shows the status, process ID, and log messages
for the rsyslog service.
Summary
Use systemctl commands to check the status and configuration of services.
list-unit-files shows all services and their startup settings.
list-units shows active services.
status gives detailed info about a specific service.
-----------------------------------------------
Video: Make systemd services persistant
-----------------------------------------------
Note Time: Note Text: