Introduction
Welcome to the world of Linux administration! As a new Linux administrator, understanding the core components and commands is crucial. This detailed guide will help you get started with essential Linux tasks and concepts.
Understanding the Linux Filesystem Hierarchy
Linux uses a hierarchical filesystem structure. Here are some key directories:
/: The root directory, where everything begins./bin: Essential command binaries (e.g.,ls,cp)./sbin: Essential system binaries (e.g.,iptables,reboot)./etc: Configuration files for the system./home: Home directories for users./var: Variable files, like logs and databases./usr: User binaries and read-only data./tmp: Temporary files.
Basic Linux Commands
Navigating the Filesystem
pwd: Print Working Directory. Shows your current directory.
pwdls: List directory contents. Usels -lfor a detailed list.
ls
ls -lcd: Change Directory.
cd /etc
cd /home/yourusernameFile Operations
cp: Copy files or directories.
cp source_file destination_file
cp -r source_directory destination_directorymv: Move or rename files or directories.
mv old_name new_name
mv file_name /path/to/new_location/rm: Remove files or directories. Userm -rfor directories.
rm file_name
rm -r directory_namemkdir: Create a new directory.
mkdir new_directoryUser and Group Management
Managing Users
adduser: Add a new user.
sudo adduser newusernamepasswd: Change user password.
sudo passwd usernamedeluser: Remove a user.
sudo deluser usernameManaging Groups
groupadd: Add a new group.
sudo groupadd newgroupusermod: Modify a user account (e.g., add a user to a group).
sudo usermod -aG groupname usernamegroups: Display group memberships for a user.
groups usernameFile Permissions and Ownership
Understanding Permissions
ls -l: Lists files with permissions.
ls -lThe output looks like:
-rwxr-xr-- 1 owner group size date time filenamer(read),w(write),x(execute) for user (owner), group, and others.
Changing Permissions
chmod: Change file permissions.
chmod u+x filename # Add execute permission for the user
chmod g-w filename # Remove write permission for the group
chmod o+r filename # Add read permission for others
chmod 755 filename # Set permissions to rwxr-xr-xChanging Ownership
chown: Change file owner and group.
sudo chown newowner:newgroup filename
sudo chown newowner filename
sudo chown :newgroup filenameProcess Management
Viewing Processes
ps: Report a snapshot of current processes.
ps auxtop: Display Linux tasks.
tophtop: Interactive process viewer (requires installation).
sudo apt install htop
htopManaging Processes
kill: Terminate a process.
kill PID
kill -9 PID # Force killpkill: Kill processes by name.
pkill process_nameNetwork Management
Viewing Network Configuration
ifconfig: Interface configuration (useipin newer systems).
ifconfig
ip addr showping: Check connectivity.
ping 8.8.8.8Managing Network Interfaces
ifupandifdown: Bring network interfaces up or down.
sudo ifup eth0
sudo ifdown eth0Package Management
Debian-Based Systems (e.g., Ubuntu)
apt-get: Package handling utility.
sudo apt-get update # Update package lists
sudo apt-get upgrade # Upgrade all packages
sudo apt-get install package_name # Install a package
sudo apt-get remove package_name # Remove a package
sudo apt-get autoremove # Remove unnecessary packagesRed Hat-Based Systems (e.g., CentOS)
yum: Package manager for RPM-based distributions.
sudo yum update # Update package lists
sudo yum upgrade # Upgrade all packages
sudo yum install package_name # Install a package
sudo yum remove package_name # Remove a package
sudo yum autoremove # Remove unnecessary packagesSystem Monitoring and Logs
Viewing Logs
dmesg: Print kernel ring buffer messages.
dmesgjournalctl: Query and display messages from the journal.
journalctl- Log files are generally located in
/var/log/. For example:
cat /var/log/syslog # View system log
tail -f /var/log/syslog # Continuously view the latest log entriesShell Scripting
Creating a Basic Shell Script
- Create a new file with a
.shextension.
nano myscript.sh- Add the following content:
#!/bin/bash
echo "Hello, World!"- Save and exit (Ctrl+X, then Y, then Enter).
- Make the script executable.
chmod +x myscript.sh- Run the script.
./myscript.shConclusion
These foundational commands and concepts are essential for every Linux administrator. As you become more comfortable, you’ll explore advanced topics like shell scripting, system security, and automation. Remember, the man command is your friend for detailed information about any command:
man command_nameI hope this guide serves as a valuable resource as you begin your journey as a Linux administrator!


