๐ง Linux Shell Basics
Linux provides a rich shell environment with extensive customization options and powerful built-in tools.
๐งญ Linux Shell Ecosystem
Linux supports multiple shells:
- bash - Default on most distributions
- zsh - Advanced features, popular with power users
- dash - POSIX-compliant, lightweight
- fish - User-friendly with modern features
- ksh - KornShell, compatible with Bourne shell
Default Shell Identification
| # Check current shell
echo $SHELL
# Check login shell
getent passwd $USER | cut -d: -f7
# Check available shells
cat /etc/shells
|
| # Basic system info
uname -a
lsb_release -a # Distribution info
cat /etc/os-release
# Hardware information
lscpu # CPU info
free -h # Memory usage
df -h # Disk usage
lsblk # Block devices
|
Process Management
| # Process monitoring
ps aux --forest
top
htop # If installed
pstree
# System activity
sar # System Activity Reporter
iostat # I/O statistics
vmstat # Virtual memory statistics
|
๐ง Linux-Specific Features
Advanced File Permissions
| # ACL support
setfacl -m u:username:rwx file.txt
getfacl file.txt
# SELinux contexts
ls -Z # Show SELinux contexts
chcon # Change SELinux context
|
Extended Attributes
| # Set extended attributes
setfattr -n user.comment -v "important file" file.txt
# Get extended attributes
getfattr -n user.comment file.txt
# List all attributes
getfattr --dump file.txt
|
File System Capabilities
| # Set capabilities
setcap cap_net_bind_service=+ep /path/to/binary
# View capabilities
getcap /path/to/binary
# Remove capabilities
setcap -r /path/to/binary
|
๐งช Package Management Integration
Major Package Managers
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 | # Debian/Ubuntu (APT)
sudo apt update
sudo apt install package-name
apt search keyword
apt show package-name
# Red Hat/CentOS (YUM/DNF)
sudo yum install package-name
sudo dnf install package-name
# Arch Linux (Pacman)
sudo pacman -S package-name
pacman -Ss keyword
# SUSE (ZYPPER)
sudo zypper install package-name
zypper search keyword
|
Container Package Management
| # Snap packages
snap install package-name
snap list
# Flatpak packages
flatpak install flathub org.application.Name
flatpak list
|
Service Management
| # systemd (modern)
systemctl status service-name
systemctl start service-name
systemctl enable service-name
# SysV init (legacy)
service service-name status
chkconfig service-name on
|
Log Management
| # Journalctl (systemd logs)
journalctl -u service-name
journalctl -f # Follow logs
journalctl --since "1 hour ago"
# Traditional logs
tail -f /var/log/syslog
tail -f /var/log/messages
|
| # Network interface information
ip addr show
ip route show
# Network troubleshooting
ss -tuln # Socket statistics
netstat -tuln # Legacy
nmap # Port scanning
tcpdump # Packet capture
|
๐งช Linux Shell Customization
Shell Configuration Files
| # Bash configuration
~/.bashrc # Interactive shell settings
~/.bash_profile # Login shell settings
/etc/bash.bashrc # System-wide bash settings
# Zsh configuration
~/.zshrc # Main configuration
~/.oh-my-zsh/ # Oh My Zsh framework
|
Prompt Customization
| # Advanced bash prompt
export PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
# With git branch information
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/(\1)/'
}
export PS1='\u@\h:\w \[\e[0;32m\]$(parse_git_branch)\[\e[0m\]\n\$ '
|
Shell Aliases and Functions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 | # Useful aliases
alias ll='ls -la'
alias la='ls -la'
alias ..='cd ..'
alias ...='cd ../..'
# System monitoring functions
sysinfo() {
echo "=== System Information ==="
uname -a
echo "Uptime: $(uptime)"
echo "Load: $(cat /proc/loadavg)"
free -h
df -h
}
# Quick navigation
mkcd() {
mkdir -p "$1" && cd "$1"
}
|
๐ง Linux Security Features
User and Group Management
1
2
3
4
5
6
7
8
9
10
11
12 | # User management
sudo adduser username
sudo usermod -aG groupname username
sudo deluser username
# Group management
sudo groupadd groupname
sudo groupdel groupname
# Password management
sudo passwd username
chage -l username # View password aging
|
Firewall Management
| # iptables (traditional)
sudo iptables -L # List rules
sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
# firewalld (modern)
sudo firewall-cmd --list-all
sudo firewall-cmd --add-service=ssh --permanent
sudo firewall-cmd --reload
|
Security Auditing
| # Audit subsystem
sudo auditctl -l # List audit rules
sudo ausearch -m EXECVE # Search execution events
# Security scanning
sudo clamscan -r /home # Antivirus scan
sudo rkhunter --check # Rootkit detection
|
๐งพ Summary
Linux provides a powerful and flexible shell environment with:
- Multiple shell options for different needs
- Extensive system administration tools
- Advanced file system features (ACLs, extended attributes)
- Robust package management systems
- Comprehensive security features
- Rich ecosystem of command-line tools
Linux shells benefit from:
- Strong POSIX compliance
- Active development community
- Extensive documentation
- Enterprise support options
- Container integration capabilities
๐ Continue to: Linux Proc and FS Semantics