Linux Commands and Architecture Notes
Linux Commands and Architecture
Overview of Linux Architecture
Three Main Components:
Kernel: Core part of the OS, responsible for communication between hardware and applications.
System Libraries: Provide necessary methods for software development, ensuring applications don’t communicate directly with the kernel.
System Utilities: Programs performing individual tasks, e.g., command-line interfaces such as Bash.
Kernel Responsibilities
Device Management: Handles communication with hardware devices.
Memory Management: Allocates and manages computer memory.
Process Management: Controls execution of processes (running programs).
System Call Handling: Manages requests from user applications to the kernel.
Runlevels and System Boot
Boot Process: Initiated by UEFI/Bios reading GPT/MBR, followed by executing boot loaders like GRUB.
Runlevels: Different operational states (e.g., single-user, multi-user).
Example: Runlevel 5 for GUI mode.
Shell and File System
Shell: Command-line interface through which users interact with the system’s kernel.
File System: Organized structure of files and directories in a hierarchical tree format.
Command Structure in Linux
Command: A keyword representing an executable program.
Shell Prompt: User input interface displaying a
$for regular users or#for superusers.
Basic Command Syntax
Syntax: commandname [options] [arguments]
Commandname = the command keyword.
Options = modifiers that change command behavior (e.g., -l).
Arguments = additional input required by the command.
Examples of Basic Commands
who: Display users currently logged in.
$ who
uptime: Shows how long the system has been running.
$ uptime
tty: Displays the current terminal.
$ tty
cal: Displays a calendar (default view is the current month).
$ cal
file: Returns the file type of a specified file.
$ file /etc/passwd
echo: Displays a line of text or variable values.
$ echo "Hello World"
Advanced Command Features
Redirection: Redirect output to a file.
$ command > output.txt
Piping: Passes the output of one command as input to another command.
$ command1 | command2
Chaining Commands: Use
;to execute multiple commands sequentially.
$ command1; command2
Background and Foreground Tasks: Use
&to run a command in the background.
$ command &
The grep Command
Search for Patterns: Searches for lines matching a pattern in a file.
$ grep "pattern" filename
Common Options:
-i: Ignore case distinctions.-c: Count matching lines only.
Searching for Files
locate: Quickly finds files by name.
$ locate filename
find: Searches for files with broader criteria (name, type, size).
$ find /path -name "file.txt"
Help and Documentation
Use
manto access manual pages for detailed command usage.
$ man command
--helpoption offers a brief help message for built-in tools.
$ command --help
Summary of Basic Linux Commands
whoami: Display current username.
pwd: Show current directory.
ls: List directory contents.
cd: Change directory.
touch: Create/modify file timestamps.
wc: Count lines, words, characters in files.
echo: Print text to the terminal.
cat: Display file content, concatenate files.
more/less: View file content page by page.
head/tail: Display first/last n lines of files.
sort: Sort lines in a file.
mkdir: Create a directory.
Conclusion
The Linux command line and file system structure allows effective management and interaction with both the user and the operating system, paving the way for powerful system administration and software development tasks.