Aim :
Gain knowledge about Linux system commands.
Linux System Commands: A Comprehensive Guide
Understanding and mastering Linux system commands is crucial for effective system administration and development. This guide will walk you through some fundamental Linux commands to enhance your command-line skills.
Guidance on How to Use:
Prerequisite:
Ensure that your system has the necessary permissions to execute commands.
- Update the package list using the following command:
sudo apt update
Explore these fundamental Linux commands to improve your command-line proficiency:
User Management
- Add a new user :
sudo useradd -m username
Creates a new user with the specified username and home directory.
- Change password for a specific user:
sudo passwd username
Changes the password for the specified user.
- Delete a user :
sudo userdel -r username
Deletes the specified user and removes the home directory and mail spool.
- List all users:
cat /etc/passwd
Displays a list of all users on the system.
- Change user:
su username
Switches to the specified user account.
- Change user and open a new shell:
su - username
Switches to the specified user and opens a new login shell.
- Add a new user :
File Manipulation
- Create an empty file:
touch new_file.txt
Creates a new, empty file with the specified name.
- Edit a file using the Nano text editor:
nano file.txt
Opens the Nano text editor for editing the content of the specified file.
- Display the first 10 lines of a file:
head file.txt
Shows the first 10 lines of the specified file.
- Display the last 10 lines of a file:
tail file.txt
Shows the last 10 lines of the specified file.
- Compress a file using gzip:
gzip file.txt
Compresses the specified file using gzip.
- Extract files from a tar archive:
tar -xvf archive.tar
Extracts files from a tar archive.
List files with human-readable sizes and sort by size and date:
ll -h --sort=size,date
- Create an empty file:
Directory Manipulation
- Create a new directory:
mkdir new_directory
Creates a new directory with the specified name.
- Remove an empty directory:
rmdir empty_directory
Removes an empty directory.
- List files in the current directory and subdirectories:
ls -R
Lists files and directories recursively.
- Copy a directory and its contents:
cp -r source_directory destination
Copies the source_directory and its contents to the specified destination.
- Move or rename a directory:
mv old_directory new_directory
Moves or renames the specified directory.
- Show directory size:
du -sh /path/to/directory
du -sh *| sort -h
Displays the size of the specified directory.
- Create a new directory:
System Level Commands
- Show available memory and swap space:
free -m
Displays information about the system's memory and swap space in megabytes.
- Display disk space usage by directories:
du -h --max-depth=1 /
Shows disk space usage for top-level directories in the root filesystem.
- Display system information:
uname -a
Shows detailed information about the system.
- Display and update sorted information about system processes:
top
Displays real-time information about system processes.
- Display information about running processes:
ps aux
Lists all running processes on the system.
- Show disk space usage for each partition:
df -h
Displays disk space usage information for each partition.
- Show available memory and swap space:
Network Related Commands
- Show network interface information:
ifconfig
Displays information about all network interfaces on the system.
- Display routing table:
route -n
Shows the kernel routing table, including destination, gateway, and interface information.
- Search for files with a specific name:
find /path/to/search -name filename.txt
Searches for files with the specified name in the specified directory and its subdirectories.
Find the file named "restore_database.sh" in the entire filesystem:
sudo find / -name restore_database.sh 2>/dev/null
- Filter and transform text with awk:
awk '{print $2}' file.txt
Prints the second column of a space-separated file.
- Replace text in a file using sed:
sed 's/old_text/new_text/' file.txt
Replaces occurrences of "old_text" with "new_text" in the file.
- Show network interface information:
Verification:
Verify your Linux distribution information:
lsb_release -a