Linux Administration Basics and Operations of Running System

Essential Commands

apropos list => find existing commands
CMD + A => move to start
CMD + E => move to end
CMD + U => delete to the start of the line
CMD + K => delete to the end of the line
CTRL - R => search in command history
CTRL - C => cancel the command

Linux File System

/bin => binary files
/boot => boot loader and kernel
/dev => device files
/etc => configuration files
/home => user home directory
/lib => library files
/media => temporarily mounted storage
/opt => optional installed software
/proc => kernel processes
/root => root user home folder
/run => information about running processes
/src => files served by device like NFS
/sys => information about system hardware
/tmp => temporary data
/usr => another location for software

File System Operations

ls -R path => recursively print content in a directory
ls -l => show list with info
mkdir -p => create whole path

Creating Links

ln -s filename linkname => create symbolic link
ln filename linkname => create hard link (same size)
file => show file type for links

Finding Files

find . -name apple => search in current directory
find . -name *apple* => search using glob
find . -size -10M => find files smaller than 10 MB
find . -size +10M => find files larger than 10 MB

Outputs and Redirects

  • Standard input (stdin) - 0
  • Standard output (stdout) - 1
  • Standard error (stderr) - 2
  • Redirect output: ls 1> output.txt
  • Redirect error: ls 2> output.txt
  • Append to file: echo 'some text' >> file.txt

File Comparisons

diff -u file1 file2 => show differences (git format)
cmp file1 file2 => compare binary files
cmp -l file1 file2 => show list of differences
hexdump file1 => display hexadecimal representation
stat file1 => show file metadata

Archiving and Compression

tar -cvf archive.tar folder => create an archive
tar -xf archive.tar => extract archive
tar -tf archive.tar => list archive contents
zip -R archive.zip folder => zip a folder
unzip archive.zip => unzip a folder

Security and Administration

File Permissions

chmod => change permission mode
chown, chgrp => change file owner and group
Role Read (4) Write (2) Execute (1) Result
User R W X 7 (rwx)
Group R - X 5 (rx)
Others R - - 4 (r)
vim /etc/sudoers => check users with sudo privileges

Software Management

apt update => update package index
apt upgrade => install updates
apt search package => search for packages
apt remove package => uninstall software

Remote Access and File Transfers

sftp root@ip => connect via SFTP
scp user@host:path-to-file => copy file to remote host

System Operations

Boot Process and Startup

shutdown -r now => restart system
shutdown -h +5 => shutdown in 5 minutes
shutdown -c => cancel shutdown
  • GRUB bootloader loads the kernel.
  • Kernel mounts the root file system.
  • System boots to the configured target.
systemctl isolate reboot.target => reboot using targets
systemctl set-default rescue.target => boot into rescue mode
systemctl set-default graphical.target => restore GUI mode

Process and Service Management

systemctl => list all services
systemctl start|stop service => start or stop service
systemctl disable service => prevent service from starting at boot

Kernel Management

uname -r => show kernel version
dpkg -i kernel_package.deb => update kernel

System Monitoring

df -h => check disk usage
free -h => check memory usage
cat /proc/cpuinfo => CPU information

Scheduling Tasks

  • Cron: Best for always-on machines.
  • Anacron: Best for systems that sleep.
cat /etc/crontab => list cron jobs
cat /etc/anacrontab => list anacron jobs

Disaster Recovery

  • Backup data and configurations regularly.
  • Test backups to ensure reliability.
  • Store backups in multiple locations.
  • Consider off-site replication.

Conclusion

This post covers Linux administration essentials, including file system operations, security management, system monitoring, and automation. Mastering these topics ensures effective Linux system management and troubleshooting.