If you are just starting with Linux, the command line interface (CLI) might seem confusing, or you might have no idea what to do with it. The Linux terminal is not like Windows or macOS, where you can do your tasks through graphical interfaces. Making a new folder, new file, or navigating is easy in Windows - with the help of a few clicks, we can do most things. But Linux users rely on commands. Don't worry - you don't need to memorise hundreds of commands to get started with Linux.
In this guide, you'll learn the 10 most essential Linux commands that will help you:
- Navigate through directories confidently
- Manage files and folders effectively
- Handle basic system operations
Whether you have little knowledge or no knowledge of Linux, or you are just curious about it, these most-used commands will form a great foundation for your Linux expertise.
Let's dive in and learn the Linux command line!
1. pwd (Print Working Directory)
-
Command:
pwd
- What it does: Shows your current location in the file system
-
Common options:
-
pwd -L
: Show logical path (follows symbolic links) -
pwd -P
: Show physical path (shows actual path in filesystem)
-
- Example:
$ pwd
/home/username
-
Use cases:
- When you're lost in the directory structure
- Before executing file operations to confirm location
- In shell scripts to verify working directory
2. ls (List Directory Contents)
-
Command:
ls
- What it does: Lists files and directories in the current location
-
Common options:
-
ls -l
: Long format with details -
ls -a
: Show hidden files -
ls -h
: Human-readable file sizes -
ls -R
: Recursive listing -
ls -t
: Sort by modification time
-
- Example:
$ ls -lh
total 24K
drwxr-xr-x 2 user user 4.0K Oct 30 10:00 Documents
-rw-r--r-- 1 user user 2.5K Oct 30 09:45 file.txt
-
Use cases:
- View directory contents
- Check file permissions and sizes
- Find recently modified files
3. cd (Change Directory)
-
Command:
cd
- What it does: Changes your current working directory
-
Common options:
-
cd ..
: Move up one directory -
cd ~
: Go to home directory -
cd -
: Go to previous directory -
cd /
: Go to root directory
-
- Example:
$ cd Documents
$ cd ../Downloads
$ cd ~/Projects
-
Use cases:
- Navigate through directory structure
- Quick access to home directory
- Return to previous location
4. mkdir (Make Directory)
-
Command:
mkdir
- What it does: Creates new directories
-
Common options:
-
mkdir -p
: Create parent directories if needed -
mkdir -m
: Set directory permissions -
mkdir -v
: Verbose mode, print message for each directory
-
- Example:
$ mkdir NewFolder
$ mkdir -p Projects/Website/src
$ mkdir -m 755 SecureFolder
-
Use cases:
- Create project directories
- Set up directory structures
- Make directories with specific permissions
5. rm (Remove)
-
Command:
rm
- What it does: Removes files and directories
-
Common options:
-
rm -r
: Remove directories and contents -
rm -f
: Force removal without confirmation -
rm -i
: Interactive mode (ask before removal) -
rm -v
: Verbose mode
-
- Example:
$ rm file.txt
$ rm -r OldProject
$ rm -i important.doc
- Warning: Use with caution - deleted files cannot be recovered!
-
Use cases:
- Delete unwanted files
- Clean up temporary files
- Remove empty/unwanted directories
6. cp (Copy)
-
Command:
cp
- What it does: Copies files and directories
-
Common options:
-
cp -r
: Copy directories recursively -
cp -i
: Interactive mode -
cp -v
: Verbose mode -
cp -p
: Preserve permissions
-
- Example:
$ cp file.txt backup.txt
$ cp -r Project ProjectBackup
$ cp -p script.sh /usr/local/bin/
-
Use cases:
- Create file backups
- Copy project directories
- Deploy scripts/programs
7. mv (Move/Rename)
-
Command:
mv
- What it does: Moves or renames files and directories
-
Common options:
-
mv -i
: Interactive mode -
mv -n
: No overwrite -
mv -v
: Verbose mode -
mv -u
: Update (move only newer files)
-
- Example:
$ mv oldname.txt newname.txt
$ mv file.txt ~/Documents/
$ mv -i important.doc backup/
-
Use cases:
- Rename files/directories
- Organize files into folders
- Move completed work to new locations
8. grep (Global Regular Expression Print)
-
Command:
grep
- What it does: Searches text patterns in files
-
Common options:
-
grep -i
: Case insensitive -
grep -r
: Recursive search -
grep -l
: Show only filenames -
grep -n
: Show line numbers -
grep -v
: Invert match
-
- Example:
$ grep "error" log.txt
$ grep -r "TODO" ./project
$ grep -i "warning" *.log
-
Use cases:
- Search logs for errors
- Find specific code patterns
- Filter command output
9. chmod (Change Mode)
-
Command:
chmod
- What it does: Changes file/directory permissions
-
Common options:
- Numeric mode:
chmod 755 file
- Symbolic mode:
chmod u+x file
-
chmod -R
: Recursive change -
chmod -v
: Verbose mode
- Numeric mode:
- Example:
$ chmod +x script.sh
$ chmod 644 file.txt
$ chmod -R 755 directory
-
Use cases:
- Make scripts executable
- Set secure file permissions
- Modify directory access rights
10. cat (Concatenate)
-
Command:
cat
- What it does: Display, combine, and create text files
-
Common options:
-
cat -n
: Number lines -
cat -b
: Number non-blank lines -
cat -s
: Squeeze blank lines
-
- Example:
$ cat file.txt
$ cat file1 file2 > combined.txt
$ cat > newfile.txt
-
Use cases:
- View file contents
- Combine multiple files
- Create small text files
Conclusion
These 10 commands form the foundation of your Linux command-line journey. Practice them regularly, and soon they'll become second nature. Remember to use the man
command (e.g., man ls
) to learn more about any command's options and usage.
Pro Tips
- Use Tab for auto-completion of commands and file names
- Access command history with up/down arrow keys
- Use
history
command to see previously used commands
Top comments (0)