skip to content
aMIrmxc-blog ⚙

Table of Contents

Essential Linux Commands – From Beginner to Pro

alt text

Linux 🐧 is one of the world’s most powerful and popular operating systems, used across servers, personal computers, mobile devices, and embedded systems. One of its defining features is the Terminal (command-line interface), which gives users complete control over the system by typing commands. This guide covers the most important Linux commands every user should know.

Learning Linux commands isn’t just essential for sysadmins and developers — it gives you a deep understanding of how the OS actually works. Unlike a graphical interface, the command line enables task automation, remote management, and access to advanced capabilities that are difficult or impossible to achieve through a GUI.

1. Sudo Access (Super User Do)

The root account in Linux has the highest level of system access — it can make any change to the system. Most administrative and configuration tasks require root privileges.

Setting a Password for the Root Account

By default, root has no password on many Linux distributions. To set or change it:

Terminal window
sudo -i passwd

The system will prompt you to enter the new password twice. Note that nothing appears on screen while typing — this is a security feature called “blind input.”

Entering the Sudo Environment

To switch into a full root session (where you don’t need to prefix every command with sudo):

Terminal window
sudo -i

After entering your current user’s password, the prompt changes from $ to #, indicating root access. Be very careful in this mode — a wrong command can delete data or break the system. Only sensitive administrative commands require sudo or a root session; regular commands do not.

2. clear – Clear the Terminal Screen

After extended terminal use, the screen fills with output and becomes cluttered. The clear command gives you a clean workspace:

Terminal window
clear

Important: This doesn’t actually delete previous output — it just scrolls it out of view. You can still scroll up to see it.

💡 Shortcut: Ctrl+L does the same thing, faster.

3. pwd – Print Working Directory

pwd shows the full absolute path of the directory you’re currently in. This is especially useful when navigating deeply nested folder structures.

/home/username
pwd

Knowing your current location is critical because many Linux commands operate relative to your working directory. Misidentifying your location is a common source of errors for beginners.

4. cd – Change Directory

cd is the primary command for navigating the Linux file system. Paths can be absolute (starting from /) or relative (starting from your current location).

CommandAction
cd /path/to/dirGo to a specific directory
cd /Go to the root of the file system
cd ~ or cdGo to your home directory
cd ..Go up one level (parent directory)
cd -Go back to the previous directory

The cd - command is particularly handy — it toggles between your current and last visited directory, like an “undo” for navigation.

5. ls – List Directory Contents

ls is one of the most frequently used Linux commands. It lists the files and subdirectories within a directory.

CommandAction
lsList current directory contents
ls /pathList contents of a specific path
ls ..List parent directory contents
ls *Recursively list subdirectories
ls -lDetailed (long) listing

The -l flag provides a detailed view with the following columns:

ColumnDescription
1stFile permissions (e.g., -rwxr-xr-x)
2ndNumber of hard links
3rdOwner name
4thGroup name
5thFile size in bytes
6thLast modified date/time
7thFile/directory name

6. mkdir – Make Directory

mkdir creates new directories.

Terminal window
mkdir newFolder # Create in current directory
mkdir /path/newFolder # Create at a specific path
mkdir {dir1,dir2,dir3} # Create multiple directories at once (no spaces around commas)
mkdir -m a=rwx dirName # Create with specific permissions (rwx for all users)
mkdir -p parent/child # Create nested directories (creates parent if it doesn't exist)

The -p flag (“parents”) is very useful — without it, trying to create parent/child when parent doesn’t exist would throw an error.

7. rmdir – Remove Directory

rmdir removes empty directories only.

Terminal window
rmdir dirName # Remove an empty directory
rmdir -p dirName # Remove nested empty directories
rmdir --ignore-fail-on-non-empty # Suppress error if directory isn't empty (but won't delete it)

⚠️ Note: To delete a directory that contains files, use rm -r dirName. Use this with extreme caution — deleted files are not recoverable through the Recycle Bin.

8. man – Manual Pages

man is your built-in documentation system. It displays comprehensive documentation for any Linux command:

Terminal window
man ls # Shows the full manual for the ls command
KeyAction
SpaceNext page
bPrevious page
qQuit
/wordSearch for a term

Manual Page Sections

  • NAME – Command name and brief description
  • SYNOPSIS – Usage syntax
  • DESCRIPTION – Full explanation
  • OPTIONS – All available flags
  • EXAMPLES – Practical usage examples
  • SEE ALSO – Related commands

man is arguably the most important command to learn — it makes you self-sufficient and removes the need to constantly search the web.

9. cp – Copy Files

cp copies files and directories from one location to another.

Terminal window
cp source.txt destination.txt # Copy file with a new name
cp file.txt /path/to/directory/ # Copy file to another directory

Useful Flags

FlagDescription
-rRecursively copy directories and their contents
-iPrompt before overwriting existing files
-pPreserve file permissions and timestamps
-vVerbose — show what’s being copied

10. grep – Search Inside Files

grep is one of Linux’s most powerful tools. It searches for a pattern (text or regex) within files and prints matching lines.

Terminal window
grep [search_pattern] [file_path]
grep error /var/log/syslog # Find all lines containing "error" in the system log

Useful Flags

FlagDescription
-iCase-insensitive search
-rRecursively search all files in a directory
-nShow line numbers with results
-cCount the number of matching lines
-vInvert — show lines that do not match

grep is frequently combined with other commands using pipes (|). For example: ls -l | grep ".txt" lists only .txt files.

11. cat – View and Combine Files

cat (short for concatenate) is a versatile command used for displaying, creating, copying, and merging files.

Terminal window
cat file.txt # Display file contents
cat file1.txt file2.txt # Display multiple files sequentially
cat > newfile.txt # Create a new file (type content, then Ctrl+D to save)
cat source.txt > dest.txt # Copy content to another file (overwrites)
cat extra.txt >> existing.txt # Append content to the end of a file
cat file1 file2 > merged.txt # Merge multiple files into one

💡 The > operator overwrites a file, while >> appends to it. This distinction is important to avoid accidental data loss.

12. chmod – Change File Permissions

chmod (Change Mode) controls who can read, write, or execute a file. Linux uses a three-tier permission model:

  • u (user/owner) – the file’s owner
  • g (group) – users belonging to the file’s group
  • o (others) – everyone else

Each tier can have three types of permissions:

  • r (read) = 4
  • w (write) = 2
  • x (execute) = 1

Symbolic Method

Terminal window
chmod u=rwx,g=rw,o=r file.txt

Numeric Method

Terminal window
chmod 755 file.txt

Each digit is the sum of the permission values. For example, 755 means:

  • 7 (owner) = 4+2+1 → read + write + execute
  • 5 (group) = 4+1 → read + execute
  • 5 (others) = 4+1 → read + execute

Permission Reference Table

NumberSymbolMeaning
0---No permissions
1--xExecute only
2-w-Write only
3-wxWrite + Execute
4r--Read only
5r-xRead + Execute
6rw-Read + Write
7rwxFull permissions

Final Words

These commands form the foundation of Linux command-line proficiency. They are used daily by millions of users, sysadmins, and developers worldwide. The best way to master them is through hands-on practice — open a terminal and try each one. Use man [command] whenever you want to explore further options or understand a command more deeply.

Linux rewards curiosity — the more you use it, the more powerful it becomes.

🚀 Good luck on your Linux journey!

What is your opinion?

Loading comments...