Linux Commands: From Basic to Advanced
This post explores essential Linux commands, covering everything from navigating the file system to managing processes and more. It's a journey from basic to advanced usage.
I. Basic File System Navigation
These commands are your bread and butter for navigating the Linux file system:
Command | Description |
---|---|
ls | Lists files and directories in the current directory. Use ls -l for detailed information, ls -a to show hidden files, and ls -h for human-readable file sizes. |
cd | Changes the current directory. cd .. goes up one directory, cd ~ goes to your home directory. |
pwd | Prints the current working directory. |
mkdir | Creates a new directory (e.g., mkdir my_directory ). Use mkdir -p path/to/new/directory to create parent directories as needed. |
rm | Removes files (e.g., rm my_file.txt ). Use rm -r directory to remove a directory and its contents (be very careful with this!). rm -rf forces removal without prompting (use with extreme caution). |
cp | Copies files or directories (e.g., cp file1.txt file2.txt , cp -r directory1 directory2 ). |
mv | Moves or renames files or directories (e.g., mv old_file.txt new_file.txt , mv file.txt /path/to/destination/ ). |
cat | Displays file content. Use cat file.txt . For large files use less file.txt or more file.txt . |
echo | Prints text to the console (e.g., echo "Hello, world!" ). |
II. Working with Files
Beyond basic manipulation, these commands offer powerful file management:
Command | Description |
---|---|
touch | Creates an empty file (e.g., touch new_file.txt ). Also updates file timestamps. |
nano/vim/vi | Text editors for creating and editing files. |
head | Displays the first few lines of a file (e.g., head -n 10 file.txt for the first 10 lines). |
tail | Displays the last few lines of a file (e.g., tail -f file.txt to follow changes in real-time). |
wc | Counts words, lines, and bytes in a file (e.g., wc -l file.txt for line count). |
grep | Searches for patterns in files (e.g., grep "pattern" file.txt , grep -r "pattern" directory for recursive search). |
find | Finds files based on various criteria (e.g., find . -name "file.txt" , find . -type d for directories). |
III. User and Permissions Management
These commands are crucial for system security:
Command | Description |
---|---|
sudo | Executes a command with superuser privileges. |
useradd | Adds a new user (e.g., sudo useradd -m -s /bin/bash newuser ). |
passwd | Changes a user's password (e.g., sudo passwd newuser ). |
usermod | Modifies user accounts (e.g., sudo usermod -aG groupname username to add a user to a group). |
userdel | Deletes a user (e.g., sudo userdel -r username to remove the user's home directory as well). |
chmod | Changes file permissions (e.g., chmod 755 file.txt ). |
chown | Changes file ownership (e.g., chown user:group file.txt ). |
IV. Process Management
Control and monitor running processes:
Command | Description |
---|---|
ps | Lists running processes (e.g., ps aux for a detailed view). |
top | Displays real-time process activity. |
kill | Terminates a process (e.g., kill 1234 to kill process ID 1234). Use kill -9 (SIGKILL) as a last resort. |
pkill | Kills processes by name (e.g., pkill firefox ). |
bg | Puts a process in the background. |
fg | Brings a background process to the foreground. |
jobs | Lists background jobs. |
V. Networking
Commands for network diagnostics and configuration:
Command | Description |
---|---|
ip a or ifconfig | Displays network interface information. |
ping | Tests network connectivity to a host. |
netstat or ss | Displays network connections, routing tables, and interface statistics. |
traceroute | Traces the route packets take to a destination. |
dig | DNS lookup utility. |
curl or wget | Downloads files from the internet. |
VI. System Information
Retrieve information about the system:
Command | Description |
---|---|
uname | Prints system information (e.g., uname -a for all information). |
df | Displays disk space usage. |
du | Estimates file space usage. |
free | Displays memory usage. |
uptime | Shows how long the system has been running. |
who | Shows who is logged on. |
This is a starting point. Linux has a vast array of commands. Use the man
command (e.g., man ls
) to get detailed information about any command.
Comments
Post a Comment