Linux, an open-source operating system, is renowned for its robustness and flexibility. It’s the backbone of many servers, desktops, and even some embedded systems. Whether you’re a beginner or an experienced user, mastering basic Linux commands is essential for navigating and managing your system efficiently. This blog post will cover 25 essential Linux commands along with their flags and usage, providing you with the knowledge needed to get started.
1. ls
The ls command lists directory contents.
- Usage:
ls [option] [directory] - Common Flags:
-l: Use a long listing format-a: List all files, including hidden files-h: With-l, print sizes in human-readable format
ls -alh2. cd
The cd command changes the current directory.
- Usage:
cd [directory] - Example:
cd /home/user/Documents3. pwd
The pwd command prints the current working directory.
- Usage:
pwd - Example:
pwd4. mkdir
The mkdir command creates a new directory.
- Usage:
mkdir [option] directory - Common Flags:
-p: Create parent directories as needed
mkdir -p /home/user/new_folder/sub_folder5. rmdir
The rmdir command removes empty directories.
- Usage:
rmdir [directory] - Example:
rmdir /home/user/empty_folder6. rm
The rm command removes files or directories.
- Usage:
rm [option] file - Common Flags:
-r: Remove directories and their contents recursively-f: Ignore nonexistent files and never prompt
rm -rf /home/user/old_files7. cp
The cp command copies files or directories.
- Usage:
cp [option] source destination - Common Flags:
-r: Copy directories recursively-i: Prompt before overwrite
cp -ri /home/user/source_folder /home/user/destination_folder8. mv
The mv command moves or renames files or directories.
- Usage:
mv [option] source destination - Example:
mv /home/user/old_name /home/user/new_name9. touch
The touch command creates an empty file or updates the timestamp of an existing file.
- Usage:
touch file - Example:
touch /home/user/newfile.txt10. cat
The cat command concatenates and displays file content.
- Usage:
cat [file] - Example:
cat /home/user/file.txt11. more
The more command views file content one screen at a time.
- Usage:
more [file] - Example:
more /home/user/largefile.txt12. less
The less command views file content with backward and forward navigation.
- Usage:
less [file] - Example:
less /home/user/largefile.txt13. head
The head command outputs the first part of files.
- Usage:
head [option] [file] - Common Flags:
-n: Number of lines to show
head -n 10 /home/user/file.txt14. tail
The tail command outputs the last part of files.
- Usage:
tail [option] [file] - Common Flags:
-n: Number of lines to show-f: Output appended data as the file grows
tail -f /var/log/syslog15. grep
The grep command searches for patterns in files.
- Usage:
grep [option] pattern [file] - Common Flags:
-i: Ignore case distinctions-r: Read all files under each directory, recursively
grep -ri "error" /var/log16. find
The find command searches for files in a directory hierarchy.
- Usage:
find [path] [expression] - Example:
find /home/user -name "*.txt"17. chmod
The chmod command changes file modes or Access Control Lists (ACLs).
- Usage:
chmod [option] mode file - Example:
chmod 755 /home/user/script.sh18. chown
The chown command changes file owner and group.
- Usage:
chown [option] owner[:group] file - Example:
chown user:group /home/user/file.txt19. ps
The ps command reports a snapshot of current processes.
- Usage:
ps [option] - Common Flags:
-e: Select all processes-f: Do full-format listing
ps -ef20. kill
The kill command sends a signal to a process.
- Usage:
kill [option] pid - Example:
kill -9 123421. top
The top command displays Linux tasks.
- Usage:
top - Example:
top22. df
The df command reports file system disk space usage.
- Usage:
df [option] - Common Flags:
-h: Human-readable format
df -h23. du
The du command estimates file space usage.
- Usage:
du [option] [directory] - Common Flags:
-h: Human-readable format-s: Display only a total for each argument
du -sh /home/user24. tar
The tar command archives files.
- Usage:
tar [option] [archive-file] [file or directory] - Common Flags:
-c: Create a new archive-x: Extract files from an archive-v: Verbosely list files processed-f: Use archive file
tar -cvf archive.tar /home/user/folder
tar -xvf archive.tar25. wget
The wget command downloads files from the web.
- Usage:
wget [option] [url] - Example:
wget https://example.com/file.zipAdditional Information
Understanding and mastering these basic Linux commands is crucial for effective system management. Each command comes with a plethora of options and flags that can significantly alter their behavior, allowing for highly customized and efficient usage. To dive deeper into each command, use the man command to access the manual pages. For example, man ls will display the manual for the ls command.
Conclusion
This comprehensive guide has covered 25 fundamental Linux commands, their flags, and usage examples. By familiarizing yourself with these commands, you can navigate and manage your Linux system more efficiently. Whether you’re performing basic file operations, searching for files, managing processes, or handling system monitoring, these commands are your foundational toolkit.
For continued learning, consider exploring more advanced commands and shell scripting to automate tasks and further enhance your Linux proficiency. Happy learning and happy coding!