Table of Contents
Heading | Sub-Topics |
---|---|
Introduction to Linux Commands | Overview of Linux, Importance of Learning Commands |
Navigating the Filesystem | pwd, ls, cd |
File Operations | touch, mkdir, rm, rmdir, cp, mv |
Viewing File Contents | cat, less, more, tail, head |
Text Editing | nano, vi, vim |
File Permissions | chmod, chown, chgrp |
Managing Processes | ps, top, kill, pkill |
System Information | uname, df, free, uptime |
Network Commands | ping, ifconfig, netstat, ssh, scp |
Disk Usage and Space | du, df |
Package Management | apt-get, yum, dnf, pacman |
User Management | useradd, userdel, passwd, su, sudo |
File Compression and Archiving | tar, gzip, unzip, zip |
Finding Files | find, locate, grep |
Shell Scripting Basics | Writing and Running Scripts, Basic Syntax |
Redirecting Output | >, >>, <, <<, pipes ( |
Environment Variables | Setting and Using Variables |
Scheduling Tasks | cron, crontab, at |
Monitoring System Performance | top, htop, iotop, vmstat |
Backup and Restore | rsync, tar, backup strategies |
Introduction to Linux Commands
Linux commands form the backbone of managing and interacting with a Linux operating system. These commands allow users to navigate the filesystem, manage files, control processes, and perform a wide array of tasks that enhance productivity and efficiency. Understanding and mastering these commands is crucial for anyone looking to utilize Linux to its full potential.
Navigating the Filesystem
Navigating the Linux filesystem is fundamental for any user. Here’s how you can get around:
pwd: Displays the present working directory.
pwd
ls: Lists directory contents.
ls
cd: Changes the current directory.
cd /path/to/directory
File Operations
File operations are integral to managing your Linux environment. These commands will help you create, move, copy, and delete files and directories:
touch: Creates an empty file.
touch filename
mkdir: Creates a new directory.
mkdir directoryname
rm: Removes files or directories.
rm filename
rmdir: Removes empty directories.
rmdir directoryname
cp: Copies files or directories.
cp source destination
mv: Moves or renames files or directories.
mv oldname newname
Viewing File Contents
Viewing and examining file contents is a daily task for many Linux users. Here are some commands to facilitate that:
cat: Concatenates and displays file content.
cat filename
less: Views file contents one screen at a time.
less filename
more: Similar to less but less advanced.
more filename
tail: Displays the last part of a file.
tail filename
head: Displays the first part of a file.
head filename
Text Editing
Editing text files is often necessary, and Linux offers powerful editors:
nano: A simple text editor.
nano filename
vi/vim: Advanced text editors with more functionality.
vi filename
vim filename
File Permissions
Managing file permissions ensures security and proper access control:
chmod: Changes file permissions.
chmod permissions filename
chown: Changes file owner.
chown owner filename
chgrp: Changes group ownership.
chgrp group filename
Managing Processes
Processes are instances of running programs, and managing them is crucial:
ps: Displays information about running processes.
ps
top: Provides a dynamic real-time view of running processes.
top
kill: Terminates a process by its ID.
kill processID
pkill: Terminates processes by name.
pkill processname
System Information
Gathering system information helps in monitoring and troubleshooting:
uname: Displays system information.
uname -a
df: Reports file system disk space usage.
df -h
free: Displays memory usage.
free -h
uptime: Shows how long the system has been running.
uptime
Network Commands
Networking is a critical part of system administration. Here are some useful commands:
ping: Tests connectivity to another host.
ping hostname
ifconfig: Configures network interfaces.
ifconfig
netstat: Network statistics.
netstat -an
ssh: Securely connects to a remote machine.
ssh user@hostname
scp: Securely copies files between hosts.
scp sourcefile user@hostname:/path/to/destination
Disk Usage and Space
Monitoring disk usage is vital for maintaining system health:
du: Estimates file space usage.
du -h
df: Reports file system disk space usage.
df -h
Package Management
Installing and managing software packages is essential:
apt-get: For Debian-based systems.
sudo apt-get install packagename
yum: For Red Hat-based systems.
sudo yum install packagename
dnf: The next-generation version of yum.
sudo dnf install packagename
pacman: For Arch-based systems.
sudo pacman -S packagename
User Management
Managing user accounts and permissions is a core task:
useradd: Adds a new user.
sudo useradd username
userdel: Deletes a user.
sudo userdel username
passwd: Changes a user’s password.
sudo passwd username
su: Switches to another user.
su username
sudo: Executes a command as another user.
sudo command
File Compression and Archiving
Efficiently manage file storage with compression and archiving:
tar: Archives multiple files.
tar -cvf archive.tar file1 file2
gzip: Compresses files.
gzip filename
unzip: Extracts compressed files.
unzip file.zip
zip: Compresses files into a zip archive.
zip archive.zip file1 file2
Finding Files
Locating files is made easy with these commands:
find: Searches for files in a directory hierarchy.
find /path -name filename
locate: Finds files by name.
locate filename
grep: Searches text using patterns.
grep "pattern" file
Shell Scripting Basics
Automating tasks can save time and effort. Here’s how to get started with shell scripting:
Writing a basic script:
#!/bin/bash
echo "Hello, World!"
Running a script:
bash scriptname.sh
Redirecting Output
Manipulating command output is a powerful feature:
> : Redirects output to a file.
command > file
>> : Appends output to a file.
command >> file
< : Takes input from a file.
command < file
| : Pipes output to another command.
command1 | command2
Environment Variables
Environment variables store data for shell processes:
Setting a variable:
export VARIABLENAME=value
Using a variable:
echo $VARIABLENAME
Scheduling Tasks
Automate tasks with scheduling tools:
cron: Schedules recurring tasks.
crontab -e
at: Schedules one-time tasks.
at now + 5 minutes
Monitoring System Performance
Keep your system running smoothly with performance monitoring:
top: Real-time system monitoring.
top
htop: Interactive process viewer.
htop
iotop: Monitors disk I/O.
iotop
vmstat: Reports virtual memory statistics.
vmstat
Backup and Restore
Protect your data with backup and restore commands:
rsync: Synchronizes files and directories.
rsync -av source destination
tar: Archives files for backup.
tar -cvf backup.tar /path/to/directory
Backup strategies: Ensure regular backups, verify data integrity, and use off-site storage for critical data.