Linux System Commands Documentation
Introduction
Linux provides a powerful command-line interface that allows users to interact with the system efficiently. This documentation covers essential Linux commands and their explanations.
File and Directory Management
ls
- Usage:
ls [options] [directory]
- Description: Lists files and directories in the specified directory.
- Example:
Lists all files including hidden ones in long format.
ls -la
cd
- Usage:
cd [directory]
- Description: Changes the current working directory.
- Example:
Navigates to the
cd /var/www
/var/www
directory.
pwd
- Usage:
pwd
- Description: Prints the current working directory.
- Example:
Displays the full path of the current directory.
pwd
mkdir
- Usage:
mkdir [directory_name]
- Description: Creates a new directory.
- Example:
Creates a directory named
mkdir new_folder
new_folder
.
rm
- Usage:
rm [options] [file/directory]
- Description: Removes files or directories.
- Example:
Recursively removes
rm -r my_folder
my_folder
and its contents.
User Management
whoami
- Usage:
whoami
- Description: Displays the current logged-in user.
id
- Usage:
id [username]
- Description: Shows user ID (UID) and group ID (GID).
sudo
- Usage:
sudo [command]
- Description: Executes a command as a superuser.
Process Management
ps
- Usage:
ps aux
- Description: Displays running processes.
kill
- Usage:
kill [PID]
- Description: Terminates a process by its process ID.
htop
- Usage:
htop
- Description: Interactive process viewer.
systemctl
- Usage:
systemctl [action] [service]
- Description: Manages system services.
- Example:
Restarts the Apache service.
systemctl restart apache2
service
- Usage:
service [service_name] [action]
- Description: Controls system services.
- Example:
Shows the status of the Nginx service.
service nginx status
Networking
ifconfig
- Usage:
ifconfig
- Description: Displays network interface information.
ping
- Usage:
ping [hostname/IP]
- Description: Checks connectivity to a host.
wget
- Usage:
wget [URL]
- Description: Downloads files from the internet.
ssh
- Usage:
ssh [user]@[host]
- Description: Connects to a remote server via SSH.
- Example:
Connects to the server at
ssh user@192.168.1.1
192.168.1.1
asuser
.
scp
- Usage:
scp [file] [user]@[host]:[destination]
- Description: Securely copies files between local and remote machines.
- Example:
Copies
scp myfile.txt user@192.168.1.1:/home/user/
myfile.txt
to the remote server.
rsync
- Usage:
rsync -avz [source] [destination]
- Description: Synchronizes files between local and remote locations efficiently.
- Example:
Synchronizes
rsync -avz /local/path/ user@remote:/remote/path/
/local/path/
to/remote/path/
on the remote server.
System Monitoring
top
- Usage:
top
- Description: Displays real-time system performance.
df
- Usage:
df -h
- Description: Shows disk space usage.
free
- Usage:
free -m
- Description: Displays memory usage.
uptime
- Usage:
uptime
- Description: Shows how long the system has been running.
netstat
- Usage:
netstat -tulnp
- Description: Displays active network connections.
File Permissions
chmod
- Usage:
chmod [permissions] [file]
- Description: Changes file permissions.
- Example:
Grants execute permissions.
chmod 755 script.sh
chown
- Usage:
chown [owner]:[group] [file]
- Description: Changes file owner and group.
Conclusion
These commands provide a solid foundation for working with Linux systems. Understanding and mastering them will help you efficiently manage files, users, processes, and system resources.