
Top 40 Basic Linux Commands: A Comprehensive Guide
Linux is a powerful operating system that uses command-line instructions to navigate, manage files, and control the system. Below is an extensive list of essential Linux commands that every beginner should know, along with explanations and sample outputs.
1. ls – List Directory Contents
- Purpose: Lists all files and directories in the current working directory.
- Example:
ls
Sample Output:
file1.txt file2.txt directory1
2. pwd – Print Working Directory
- Purpose: Displays the current directory’s full path.
- Example:
pwd
Sample Output:
/home/user/documents
3. cd – Change Directory
- Purpose: Changes the current directory.
- Example:
cd /home/user/downloads
Tip: Use cd .. to move up one directory level.
4. mkdir – Make Directory
- Purpose: Creates a new directory.
- Example:
mkdir new_folder
Tip: Use mkdir -p /path/to/new_folder to create nested directories.
5. rmdir – Remove Directory
- Purpose: Deletes an empty directory.
- Example:
rmdir empty_folder
Note: Use rm -r for directories containing files.
6. rm – Remove Files or Directories
- Purpose: Deletes files or directories.
- Example:
rm file1.txt
For directories: rm -r directory_name
7. cp – Copy Files or Directories
- Purpose: Copies files or directories to another location.
- Example:
cp file1.txt /destination/path
For directories: cp -r folder1 /destination/path
8. mv – Move or Rename Files
- Purpose: Moves or renames files and directories.
- Example:
mv old_name.txt new_name.txt
9. cat – Concatenate and Display File Content
- Purpose: Displays the contents of a file.
- Example:
cat file1.txt
10. nano – Text Editor
- Purpose: Opens the Nano text editor.
- Example:
nano new_file.txt
Tip: Use Ctrl + O to save and Ctrl + X to exit.
11. touch – Create a New File
- Purpose: Creates an empty file or updates the timestamp of an existing file.
- Example:
touch new_file.txt
12. chmod – Change File Permissions
- Purpose: Changes file or directory permissions.
- Example:
chmod 755 file1.txt
13. chown – Change File Ownership
- Purpose: Changes the owner of a file or directory.
- Example:
chown new_owner file1.txt
14. find – Search for Files
- Purpose: Searches for files and directories.
- Example:
find /path -name "file1.txt"
15. grep – Search Within Files
- Purpose: Finds specific text in files.
- Example:
grep "keyword" file1.txt
16. df – Disk Space Usage
- Purpose: Shows disk space usage.
- Example:
df -h
Sample Output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 100G 50G 50G 50% /
17. du – Disk Usage
- Purpose: Displays the size of files and directories.
- Example:
du -h /path/to/directory
18. top – Display Running Processes
- Purpose: Shows real-time system processes and resource usage.
- Example:
top
19. ps – List Processes
- Purpose: Lists currently running processes.
- Example:
ps aux
20. kill – Terminate a Process
- Purpose: Stops a running process using its process ID (PID).
- Example:
kill 1234
21. man – Manual Pages
- Purpose: Displays the manual for a command.
- Example:
man ls
22. echo – Print Text
- Purpose: Displays text or variables on the screen.
- Example:
echo "Hello, world!"
23. whoami – Display Current User
- Purpose: Shows the username of the current user.
- Example:
whoami
24. hostname – Display System Name
- Purpose: Shows the system’s hostname.
- Example:
hostname
25. uptime – Display System Uptime
- Purpose: Shows how long the system has been running.
- Example:
uptime
26. clear – Clear Terminal Screen
- Purpose: Clears all text from the terminal screen.
- Example:
clear
27. history – Command History
- Purpose: Displays a list of previously entered commands.
- Example:
history
28. tar – Archive Files
- Purpose: Creates or extracts tar archives.
- Example:
tar -cvf archive.tar file1 file2
29. zip – Compress Files
- Purpose: Compresses files into a .zip archive.
- Example:
zip archive.zip file1 file2
30. unzip – Extract Zip Files
- Purpose: Extracts files from a .zip archive.
- Example:
unzip archive.zip
31. scp – Secure File Copy
- Purpose: Copies files between systems securely.
- Example:
scp file1.txt user@remote:/path
32. wget – Download Files
- Purpose: Downloads files from the internet.
- Example:
wget https://example.com/file.zip
33. curl – Transfer Data
- Purpose: Transfers data from or to a server.
- Example:
curl https://example.com
34. ping – Test Network Connection
- Purpose: Tests connectivity to another host.
- Example:
ping google.com
35. ifconfig – Network Configuration (Deprecated)
- Purpose: Displays or configures network interfaces.
- Example:
ifconfig
Note: Use ip addr in newer systems.
36. netstat – Network Statistics
- Purpose: Displays network connections and statistics.
- Example:
netstat -an
Note: Use ss in newer systems.
37. iptables – Firewall Management
- Purpose: Configures the Linux firewall.
- Example:
iptables -L
38. ssh – Secure Shell
- Purpose: Connects to remote systems securely.
- Example:
ssh user@remote_host
39. cron – Schedule Tasks
- Purpose: Schedules tasks to run at specific times.
- Example:
crontab -e
40. uptime – System Uptime
- Purpose: Shows how long the system has been running.
- Example:
uptime
Conclusion These extensive Linux commands are essential for navigating, managing, and controlling your Linux system effectively. Mastering these commands will enhance your confidence and efficiency when working with Linux.
test