With 15 years of experience as a Linux System Administrator, I have developed a deep passion for harnessing the power of open-source technologies to build robust, secure, and scalable IT infrastructures. My love for working with the command line has been a driving force throughout my career, empowering me to efficiently manage and troubleshoot systems. My extensive hands-on experience with various Linux distributions, such as Red Hat, CentOS, Ubuntu, and Debian, coupled with my expertise in system administration tools like Bash scripting, Ansible, Puppet, Docker, and Kubernetes, has enabled me to consistently deliver high-performance solutions. I take pride in my ability to proactively identify and resolve system issues, optimize server performance, and ensure maximum uptime for critical applications. As a strong collaborator and communicator, I effectively bridge the gap between technical and non-technical stakeholders, translating complex concepts into easily digestible terms. With a constant drive to stay at the forefront of industry trends and best practices, I am excited to bring my expertise and enthusiasm to new challenges and contribute to the success of forward-thinking organizations.
Learning the essential Linux commands is crucial for anyone starting their journey with this powerful operating system. In this article, we’ll explore 25 common Linux commands that every beginner should know to navigate, manage, and manipulate files and directories effectively in the command-line interface.
Command | Description | Example 1 | Example 2 | Example 3 |
---|---|---|---|---|
ls | List files and directories | ls (lists files in current directory) | ls -l (lists files with details) | ls /path/to/directory (lists files in specified directory) |
cd | Change directory | cd /path/to/directory (changes to specified directory) | cd .. (moves up one directory level) | cd ~ (changes to home directory) |
pwd | Print working directory | pwd (displays the current working directory) | pwd /path/to/directory (displays the specified directory path) | pwd -P (displays the resolved path without symbolic links) |
mkdir | Make a new directory | mkdir directory_name (creates a new directory) | mkdir -p /path/to/new/directory (creates nested directories) | mkdir -m 700 private_directory (creates a directory with specific permissions) |
rmdir | Remove an empty directory | rmdir directory_name (removes the specified empty directory) | rmdir -p /path/to/nested/directory (removes nested empty directories) | rmdir -v directory_name (removes directory with verbose output) |
cp | Copy files and directories | cp source_file destination (copies a file) | cp -r source_directory destination (copies a directory recursively) | cp -i *.txt backup/ (copies text files with confirmation for overwriting) |
mv | Move or rename files and directories | mv source destination (moves a file/directory) | mv old_name new_name (renames a file/directory) | mv -i *.txt backup/ (moves text files with confirmation for overwriting) |
rm | Remove files and directories | rm file_name (removes a file) | rm -r directory_name (removes a directory recursively) | rm -i *.txt (removes text files with confirmation) |
cat | Display file contents | cat file_name (displays the contents of a file) | cat file1.txt file2.txt (concatenates and displays multiple files) | cat > new_file.txt (creates a new file and allows input from the terminal) |
less | View file contents one page at a time | less file_name (opens the file for viewing) | less +F file_name (opens the file and automatically exits at the end) | less -N file_name (displays line numbers) |
head | Display the first few lines of a file | head file_name (displays the first 10 lines) | head -n 20 file_name (displays the first 20 lines) | head -c 100 file_name (displays the first 100 bytes) |
tail | Display the last few lines of a file | tail file_name (displays the last 10 lines) | tail -n 20 file_name (displays the last 20 lines) | tail -f log_file.txt (displays the last lines and follows the file as it grows) |
grep | Search for a pattern in files | grep pattern file_name (searches for a pattern in a file) | grep -i pattern file_name (case-insensitive search) | grep -r pattern directory (recursive search in a directory) |
find | Search for files in a directory hierarchy | find /path/to/directory -name file_pattern (finds files matching the pattern) | find . -type d -empty (finds empty directories in the current directory tree) | find /path -size +1G (finds files larger than 1GB) |
man | Display the user manual for a command | man ls (displays the manual page for the ls command) | man -k keyword (searches for manual pages containing the keyword) | man 7 overview (displays the manual page with section number 7) |
echo | Print text to the terminal | echo "Hello, World!" (prints the text to the terminal) | echo $PATH (prints the value of the PATH environment variable) | echo "Text" > file.txt (redirects the output to a file) |
chmod | Change file permissions | chmod +x file_name (makes a file executable) | chmod 644 file_name (sets read/write permissions for owner, read for others) | chmod -R 755 directory (changes permissions recursively in a directory) |
sudo | Execute a command as the superuser | sudo command (runs the command with superuser privileges) | sudo -u username command (runs the command as a specific user) | sudo -i (starts an interactive root shell) |
apt or yum | Package management | apt update (updates package lists) | apt install package_name (installs a package) | apt remove package_name (removes a package) |
ssh | Secure Shell for remote login | ssh username@remote_host (connects to a remote host over SSH) | ssh -p 2222 username@remote_host (connects to a remote host on a specific port) | ssh -X username@remote_host (enables X11 forwarding for GUI applications) |
top | Display system resource usage | top (shows real-time system resource usage) | top -o %CPU (sorts processes by CPU usage) | top -u username (shows processes of a specific user) |
ps | List running processes | ps (lists current user’s processes) | ps aux (lists all processes) | `ps -ef |
kill | Stop a running process | kill process_id (stops the process with the specified ID) | kill -9 process_id (forcefully terminates the process) | killall process_name (stops all processes with the specified name) |
tar | Archive and compress files | tar -czf archive.tar.gz directory (creates a compressed archive) | tar -xzf archive.tar.gz (extracts a compressed archive) | tar -xzf archive.tar.gz -C /path/to/directory (extracts to a specific directory) |
wget | Download files from the web | wget https://example.com/file.zip (downloads the specified file) | wget -c https://example.com/large_file.iso (resumes a partially downloaded file) |