Master the Basics - The 10 Most Important Linux Commands and How to Use Them
Master These 10 Linux Commands to Level Up Your Skills

If you’ve just installed Linux on your new server to host your locally stored media, you’re probably staring at a command prompt like this:
john@mediaserver:~$
A blinking cursor and no idea where to start—if you’re new to Linux, the terminal can feel like an intimidating black box. With cryptic commands, strange symbols, and endless possibilities, it’s easy to feel overwhelmed. But here’s the good news: mastering Linux isn’t about memorizing hundreds of commands. It’s about learning the essentials that give you the confidence to understand and control your system.
Think of it like learning a new language. You don’t need to know every word in the dictionary to start speaking; you just need the most useful words and phrases. In the same way, a few key Linux commands will unlock the power to navigate, manage, and troubleshoot your system like a pro.
In this post, we’ll break down 10 of the most important Linux commands—what they do, why they matter, and how to use them. By the end, you’ll have a solid foundation to tackle whatever the terminal throws at you. Let’s dive in.
1. ls
– List Directory Contents
The ls
command is one of the first Linux commands every user should learn. It allows you to see the contents of a directory—essentially, it’s the Linux version of peeking inside a folder in a graphical file manager. Whether you’re looking for a specific file, checking for hidden files, or trying to understand the structure of your directories, ls
is your go-to tool.
Here’s why it’s important:
Basic Usage:
Typing ls
in the terminal will list the files and folders in your current working directory.
Useful Options:
ls -l
: Shows detailed information, such as file permissions, ownership, size, and last modification date.ls -a
: Includes hidden files and directories (those starting with a dot, like.config
).ls -h
: Outputs file sizes in a human-readable format (e.g., KB, MB, GB).
Practical Examples:
View a directory’s structure:
If you’re organizing your media, you’ll often need to see what’s in a directory. For example, running ls media/Movies
shows all the files in your Movies folder.
Identify hidden files:
Hidden files often contain configuration settings. Use ls -a
to reveal them when troubleshooting or customizing software.
Check file details:
When permissions or sizes matter (e.g., checking if a script is executable or whether a file is too large), ls -lh
provides all the details in one readable output.
Why It Matters:
Knowing what’s in your directories is the first step to managing your Linux system effectively. The ls
command helps you understand your environment, locate files, and stay organized.
2. cd
– Change Directory
The cd
command is your key to navigating the Linux file system. It stands for “change directory,” as the name suggests, and it allows you to move between folders in your system. Think of it like double-clicking a folder in a graphical interface but using the power and speed of the command line.
Basic Usage:
cd <directory>
: Moves you into the specified directory.
For example, if you want to move to the “Movies” folder in your media directory, you’d type:
cd /media/Movies
Useful Shortcuts:
Home Directory: cd
by itself takes you back to your home directory, no matter where you are.
Parent Directory: cd ..
moves you one level up in the file hierarchy.
Root Directory: cd /
takes you to the root directory (the base of your file system).
Practical Examples:
Move into a specific directory:
To access your media
folder from any directory:
cd /media
Navigate multiple levels at once:
To jump directly to a subdirectory without going step by step:
cd /media/Shows
To move up one level in the hierarchy:
If you’re in /media/Shows
and want to go back to the /media
folder:
cd ..
Why It Matters:
Efficient navigation is crucial when working in the Linux terminal. The cd
command enables you to quickly reach the directory you need, whether you’re accessing files, running scripts, or modifying system configurations. Knowing how to use both relative and absolute paths ensures you can move around your system seamlessly.
Troubleshooting Tips:
If cd
doesn’t work, double-check the directory name. Linux file systems are case-sensitive, so “media” and “Media” are treated as different folders.
Use the ls
command before cd
to ensure the directory exists and to see available options.
3. pwd
– Print Working Directory
The pwd
command is one of the most essential Linux commands. It stands for “print working directory” and does exactly that: it tells you the full path of the directory you are currently in. This command is a constant companion when navigating the Linux file system, especially in environments with complex directory structures. Think of it as a map with a “You are here” arrow.
Basic Usage:
Type pwd
in the terminal, and it will output the absolute path of your current working directory.
For example, if you’re in your Movies
folder, running pwd
might return:
/media/Movies
Practical Use Cases:
Know Where You Are:
When working in nested directories or switching between multiple terminals, it’s easy to lose track of your location. pwd
gives you clarity, ensuring you know exactly where you are in the file system.
Script Writing:
When writing scripts, you often need to confirm the current directory to set relative paths for your files. pwd
ensures you’re working in the correct location.
Debugging Navigation Issues:
If a file or command isn’t working as expected, pwd
can help verify whether you’re in the right directory to execute the task.
Why It’s Important:
While pwd
might seem like a small tool, its simplicity is its strength. Knowing your current working directory is fundamental to navigating and managing your Linux system effectively. It’s particularly useful when combined with other commands like ls
and cd
.
Example Workflow:
Here’s a quick scenario where pwd
proves its worth:
-
You log into a remote server via SSH and are unsure of your starting directory. Run
pwd
to confirm your location. -
After changing directories several times using
cd
, runpwd
again to ensure you’re where you need to be before performing actions like copying or deleting files.
Tips for Using pwd
:
Combine it with other commands in scripts to dynamically record or confirm the directory path. For example:
echo "You are currently in $(pwd)"
Use it to verify paths when creating symbolic links or setting environment variables.
In Linux, knowing your current location in the file system is half the battle, and pwd
is the trusty compass that keeps you oriented. Whether you’re a beginner or an experienced user, this simple command is one you’ll use constantly.
4. mkdir
– Make Directory
The mkdir
command is your go-to tool for creating new directories (folders) in Linux. Whether you’re organizing media files or creating new locations for backups, mkdir
is simple, efficient, and essential for maintaining a tidy file system.
Basic Usage:
The simplest form of the command:
mkdir <directory-name>
This creates a directory in your current location.
For example, running:
mkdir media
creates a new folder named ‘media’ in the directory you’re currently in.
Practical Use Cases:
Organizing Media:
When starting a new media storage structure, you can quickly create folders for Movies, Shows, and Music:
mkdir -p /media/{Movies,Shows,Music}
This creates the media
folder (if it does not already exist), and the Movies, Shows, and Music subfolders inside it.
Setting Up Temporary Locations:
When testing or running scripts, you might need a dedicated folder for temporary files:
mkdir temp_files
Useful Options:
-p
(Parent): Creates parent directories as needed, avoiding errors if parts of the path don’t already exist.
-v
(Verbose): Outputs confirmation messages as directories are created, useful for understanding what’s happening in complex operations.
For example:
mkdir -pv /media/{Movies,Shows,Music}
Outputs:
mkdir: created directory 'media'
mkdir: created directory 'media/Movies'
mkdir: created directory 'media/Shows'
mkdir: created directory 'media/Music'
Troubleshooting Tips:
-
If
mkdir
gives you a “Permission denied” error, it means you don’t have the rights to create a folder in that location. Usesudo mkdir
to create directories in restricted areas, like system folders. -
Double-check the directory name for typos—Linux file systems are case-sensitive, so “media” and “Media” are not the same.
Why It’s Important:
Creating directories is one of the most fundamental tasks in organizing and managing your Linux environment. Whether setting up a personal media server, deploying software, or scripting automated tasks, mkdir
is a tool you will rely on constantly. Its flexibility with options like -p
makes it invaluable for creating complex folder structures in seconds.
The mkdir
command isn’t just about creating folders—it’s about bringing structure and order to your Linux system. With a bit of creativity and practice, it becomes a cornerstone of efficient file management.
5. rm
– Remove Files or Directories
The rm
command is a powerful tool for deleting files and directories in Linux. It stands for “remove” and is essential for keeping your system clean by getting rid of unwanted files, temporary data, or old backups. However, with great power comes great responsibility—rm
can permanently delete data without confirmation, so it’s crucial to use it carefully.
Basic Usage:
- To remove a file:
rm <file-name>
For example:
rm old_document.txt
This deletes the old_document.txt
file from your current directory.
Deleting Multiple Files:
You can remove several files in one command:
rm file1.txt file2.txt file3.txt
Removing Directories:
By default, rm
only removes files. To delete directories, you’ll need to use specific options:
rm -r
(Recursive): Removes a directory and all its contents (files and subdirectories).
rm -r folder_name
rm -rf
(Recursive + Force): Deletes everything in a directory without asking for confirmation.
rm -rf /path/to/directory
Be very careful with this command—it’s often referred to as the “nuclear option” because it can wipe out data irreversibly.
Practical Use Cases:
Delete Temporary Files:
Clean up temporary or cache files after troubleshooting or testing:
rm -r /tmp/my_temp_files
Delete Media You No Longer Want/Need:
Remove unneeded files to free up disk space:
rm -r /media/Movie/Movie_I_No_Longer_Need
Useful Options:
-i (Interactive): Asks for confirmation before deleting each file, reducing the risk of accidental deletion:
rm -i important_file.txt
-v
(Verbose): Shows details of what’s being deleted:
rm -rv /path/to/directory
-f
(Force): Ignores warnings and deletes files or directories without asking for confirmation. Use with caution.
Safety Tips for Using rm
:
-
Double-Check Paths: Before running
rm
, confirm the path to avoid unintended deletions. If you are not careful, you can sometimes delete more than you intended. -
Avoid
sudo
Unless Necessary: Runningrm
as a superuser (sudo
) can delete system-critical files. Use it sparingly. -
Simulate with
ls
: Usels
to preview the files you’re about to delete:
ls /path/to/directory
Why It’s Important:
The rm
command is a cornerstone of Linux file management. It ensures that your system doesn’t get cluttered with unnecessary files, helping you maintain an organized and efficient environment. However, because deletions are irreversible by default, understanding and respecting its power is crucial.
Example Workflow:
- Delete a Single File:
rm Movie_I_Hate.mkv
- Remove a Directory with Files:
rm -r ~/Downloads/temp_folder
- Clean All
.tmp
Files in a Directory:
rm *.tmp
6. cp
– Copy Files and Directories
The cp
command in Linux is used to copy files and directories from one location to another. It’s one of the most versatile and commonly used commands, whether you’re creating backups, duplicating files for edits, or moving content between directories. With a range of options to enhance its functionality, cp
is a powerful tool for efficient file management.
Basic Usage:
Copy a File:
cp <source-file> <destination>
For example:
cp config.conf backup_config.conf
This copies config.conf
to a new file named backup_config.conf
in the current directory.
Copying Multiple Files:
To copy multiple files into a directory:
cp file1.txt file2.txt /path/to/destination/
Copying Directories:
By default, cp
doesn’t copy directories unless you include the recursive -r
option:
Copy an Entire Directory:
cp -r /source/directory /destination/directory
This creates a duplicate of the directory and all its contents, including subdirectories and files.
Practical Use Cases:
Backup Files:
Before editing a critical file, create a backup:
cp config.yaml config_backup.yaml
Move Files to External Drives:
Copy files to another folder :
cp /home/user/downloads/movie.mkv /media/Movies/Movie_Name/
Useful Options:
-i
(Interactive): Prompts for confirmation before overwriting existing files:
cp -i file1.txt /destination/
-v
(Verbose): Displays details of each file being copied, helpful for tracking large operations:
cp -v file1.txt file2.txt /destination/
-u
(Update): Copies files only if the source file is newer or doesn’t exist in the destination:
cp -u file1.txt /destination/
-p
(Preserve): Retains the original file’s metadata (timestamps, permissions, etc.):
cp -p file1.txt /destination/
Tips for Using cp
:
Preview Before Copying: Use the ls
command to check your source and destination paths before running cp
.
Avoid Overwriting: Use the -i
option to prevent accidental overwriting of files. Alternatively, use -n
(no-clobber) to skip overwriting entirely.
Why It’s Important:
The cp
command is indispensable for anyone managing files in Linux. Its versatility allows you to copy everything from individual files to entire directory structures. Whether backing up critical data, reorganizing your file system, or preparing project templates, cp
ensures you can duplicate your work without error.
Mastering the cp
command will add a vital tool to your Linux arsenal. One that keeps your files safe, organized, and easy to manage.
7. mv
– Move or Rename Files and Directories
The mv
command in Linux is a dual-purpose powerhouse. It’s used to move files and directories from one location to another, but it also functions as a tool to rename them. This versatility makes mv
an essential command for file management, whether reorganizing directories, renaming files, or moving data to another location.
Basic Usage:
Move a File:
mv <source-file> <destination>
For example:
mv movie.mkv /media/Movies/Movie_Name/
This moves the file movie.mkv
to the Movie_Name
directory.
Rename a File:
mv <old-name> <new-name>
For example:
mv Movie_Name.mkv Movie_Name_2022.mkv
This renames the file Movie_Name.mkv
to Movie_Name_2022.mkv
in the current directory.
Moving Multiple Files:
To move several files to a new directory:
mv file1.txt file2.txt file3.txt /destination/directory/
Moving Directories:
Move an Entire Directory:
mv /source/directory /destination/
This moves the directory and its contents to the new location.
Useful Options:
-i
(Interactive): Prompts for confirmation before overwriting a file in the destination:
mv -i file.txt /destination/
-v
(Verbose): Displays the details of the files being moved or renamed:
mv -v file.txt /destination/
-n
(No-Clobber): Prevents overwriting existing files in the destination:
mv -n file.txt /destination/
Tips for Using mv
:
Preview Before Moving: Use ls
or find
to preview files before moving them to avoid mistakes.
Avoid Overwriting: Use the -i
or -n
option to prevent accidental overwrites.
Be Careful with sudo
: When moving system-critical files, running mv
with sudo
can have significant consequences if done incorrectly. Double-check your paths.
Why It’s Important:
The mv
command is indispensable for organizing your Linux system. Its ability to move and rename files in one step makes it a versatile and efficient tool. Whether you’re tidying up your home directory, reorganizing project files, or preparing data for a backup, mv
helps you manage your files quickly and effectively.
By mastering mv
, you’ll gain the flexibility to manipulate files and directories seamlessly, making your Linux workflow smoother and more organized.
8. chmod
– Change File Permissions
The chmod
command is an essential tool for managing file and directory permissions in Linux. It allows you to control who can read, write, and execute files, ensuring your system is secure. And that users only have the access they need. By mastering chmod
, you safeguard sensitive files and enable proper collaboration across users.
Understanding File Permissions:
Before diving into chmod
, it’s important to understand the structure of Linux file permissions, which can be viewed using ls -l
:
-rwxr-xr-- 1 user group 4096 Jan 23 10:00 script.sh
Here’s what the fields mean:
r
(read): Allows viewing the file’s contents.w
(write): Allows modifying the file.x
(execute): Allows running the file as a program or script.
Permissions are grouped into three categories. In the above exaple this is how it breaks down:
- Owner (
rwx
) - Full access to the file - Group (
r-x
) - Read and Execute for the members of the group - Others (
r--
) - Everyone else can read the file
Basic Usage:
Change Permissions Using Symbolic Notation:
chmod <permissions> <file>
For example, to give the owner execute permissions for a file:
chmod u+x script.sh
Here’s a breakdown of symbolic permissions:
u
(user): The file’s owner.g
(group): Users in the file’s group.o
(others): All other users.a
(all): Applies tou
,g
, ando
.
Modifiers:
+
(add): Adds a permission.-
(remove): Removes a permission.=
(set): Sets a permission exactly.
Example:
Add read and write permissions for the group:
chmod g+rw file.txt
Remove execute permission for others:
chmod o-x script.sh
Change Permissions Using Octal Notation:
Octal values provide a shorthand for setting permissions:
4
(read):r--
2
(write):-w-
1
(execute):--x
Combine these to set multiple permissions (e.g., 7 = rwx
, 6 = rw-
).
To set permissions directly:
chmod 755 script.sh
This sets:
- Owner: Read, write, execute (
7 = rwx
). - Group: Read, execute (
5 = r-x
). - Others: Read, execute (
5 = r-x
).
Practical Use Cases:
Make a Script Executable:
When creating a new script, you need to make it executable:
chmod +x my_script.sh
Secure Sensitive Files:
Restrict access to a private file so only the owner can read or write it:
chmod 600 private_file.txt
Allow Group Collaboration:
Grant a group read and write permissions to a shared file:
chmod g+rw shared_file.txt
Useful Options:
-R
(Recursive): Apply permissions to a directory and all its contents:
chmod -R 755 /path/to/directory
--reference
: Copy permissions from one file to another:
chmod --reference=source_file target_file
Example Workflow:
- Check Current Permissions:
Usels -l
to see the current permissions:
ls -l file.txt
- Modify Permissions:
Grant read and write permissions to the owner and group, but deny all permissions to others:
chmod 660 file.txt
- Make a Directory and Its Contents Accessible:
Ensure a web project directory is accessible to everyone:
chmod -R 755 /media/Movies
Tips for Using chmod
:
Test Before Automating: Avoid running chmod
commands recursively without testing on a single file or directory.
Avoid Over-Permissive Settings: Always follow the principle of least privilege. Grant only necessary permissions. While setting permissions to 777
might seem convenient, it can create serious security risks by giving everyone full access to your files. Instead, take the time to set appropriate permissions based on your needs. For example, I use 770
permissions. This setup allows the owner and group full access to the files. While completely restricting access to others. With 770
, not only is the content protected from unauthorized access, but it’s also hidden from users outside the group, enhancing both security and privacy.
Check Permissions Regularly: Use ls -l
to ensure files have the correct permissions.
Why It’s Important:
File and directory permissions are at the heart of Linux security and system management. The chmod
command gives you precise control over access, allowing you to protect sensitive files, enable collaboration, and maintain proper functionality for applications and scripts.
By mastering chmod
, you’ll be equipped to secure your system, manage user access, and ensure the smooth operation of your Linux environment. It’s not just a command—it’s a key to effective and secure system management.
9. chown
– Change File Ownership
The chown
command in Linux allows you to change the ownership of files and directories. Ownership defines who can access, modify, or manage a file. Every file in Linux has two primary ownership attributes: the user (owner) and the group. By using chown
, you can assign files to the appropriate owner and group, which is especially critical for managing multi-user systems and ensuring security.
Basic Usage:
Change the Owner of a File:
chown <new-owner> <file>
For example:
chown kryptikwurm movie.mkv
This sets the owner of movie.mkv
to the user kryptikwurm
.
Change Both Owner and Group:
chown <new-owner>:<new-group> <file>
Example:
chown kryptikwurm:media movie.mkv
This changes the owner to kryptikwurm
and assigns the file to the media
group.
Changing Ownership of Directories:
To change the ownership of a directory and all its contents, use the -R
(recursive) option:
chown -R kryptikwurm:media /media
This changes the ownership of /media
and everything inside it to user kryptikwurm
and group media
.
Useful Options:
-R
(Recursive): Apply ownership changes to directories and all their contents:
chown -R kryptikwurm:media /media
-v
(Verbose): Displays information about what chown
is changing:
chown -v kryptikwurm:media movie.mkv
Checking File Ownership:
Use ls -l
to check ownership details of files and directories:
ls -l file.txt
The output shows the owner and group:
-rw-r--r-- 1 user group 4096 Jan 23 12:00 file.txt
Here, user
is the owner, and group
is the group.
Safety Tips for Using chown
:
Be Careful with sudo
: Always double-check the file or directory path when using sudo
with chown
, as incorrect paths can cause system-wide permission issues.
Don’t Use Wildcards Recklessly: Avoid commands like chown -R user:group /*
as they could affect critical system files.
Preview Changes: Use ls -l
to inspect file ownership before making changes.
Why It’s Important:
Proper ownership management is vital for system security and functionality. With chown
, you can:
- Ensure only authorized users can access or modify files.
- Enable collaboration by assigning files to specific groups.
- Maintain system integrity by assigning correct ownership to configuration and system files.
By mastering chown
, you’ll have the power to manage access and keep your Linux system secure and efficient. It’s an indispensable command for anyone managing multi-user environments or working on shared systems.
10. df
– Display Disk Space Usage
The df
command in Linux is used to display information about the available and used disk space on file systems. Short for “disk free,” df
provides a quick overview of your system’s storage capacity, helping you monitor and manage disk usage effectively. It’s an essential tool for system administrators and users who need to ensure there’s enough space for files, logs, and applications.
Basic Usage:
To display disk usage for all mounted file systems, simply type:
df
Example output:
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/sda1 500000000 250000000 250000000 50% /
tmpfs 4000000 0 4000000 0% /dev/shm
Key Fields in the Output:
Filesystem: The name of the disk or storage device (e.g., /dev/sda1
).
1K-blocks: Total storage space on the filesystem in 1KB blocks (default).
Used: Disk space currently in use.
Available: Disk space available for use.
Use%: The percentage of disk space in use.
Mounted on: The directory where the filesystem is mounted.
Useful Options:
-h
(Human-Readable): Display sizes in a more readable format (e.g., MB, GB):
df -h
Example output:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 500G 250G 250G 50% /
-T
(Show Filesystem Type): Include the type of filesystem (e.g., ext4, xfs):
df -T
Example output:
Filesystem Type 1K-blocks Used Available Use% Mounted on
/dev/sda1 ext4 500000000 250000000 250000000 50% /
Practical Use Cases:
Monitor Disk Space on Servers:
Regularly check disk space usage to ensure critical services don’t fail due to lack of storage:
df -h
Identify Full or Nearly Full Filesystems:
Use the Use%
column to quickly spot filesystems nearing capacity, such as:
Filesystem Size Used Avail Use% Mounted on
/dev/sda1 500G 490G 10G 98% /
Check Mounted External Devices:
Verify the available space on USB drives, external hard drives, or network shares:
df -h /media/usb
Tips for Using df
:
Use -h
for Human-Readable Output: The default df
output can be hard to interpret; always use -h
unless you need raw block sizes.
Monitor Regularly: Run df
periodically on servers or systems with limited storage to prevent unexpected failures.
Check Mounted Points: Use df
to verify that external devices or network shares are mounted correctly.
Why It’s Important:
The df
command provides critical insights into your system’s disk space usage. With it, you can:
-
Proactively manage storage to avoid full filesystems that could disrupt services.
-
Diagnose performance issues caused by lack of space.
-
Monitor external devices and ensure sufficient capacity for backups or large data transfers.
By mastering df
, you’ll be equipped to monitor and manage your system’s storage effectively, ensuring optimal performance and stability. It’s a simple yet powerful tool that every Linux user should have in their arsenal.
In Conclusion:
Mastering Linux commands gives you the keys to fully control your system. From using ls
to navigate directories to chmod
for managing security, these commands empower you to interact with your Linux environment confidently and efficiently. By getting comfortable with these 10 essential commands, you’ll be able to manage files, troubleshoot issues, optimize performance, and keep your system secure—all from the terminal.
Linux can seem intimidating at first, but with practice, these commands will become second nature. They’re more than just tools, they’re your gateway to unlocking the full potential of Linux and taking control of your system like a pro.
Don’t just read about these commands—practice them! Open your terminal, try creating files, managing permissions, and searching for data. The best way to learn is by getting your hands dirty. And if you’re ready to push your skills even further, start experimenting with combining these commands to write scripts or automate tasks.
Mastering Linux starts with the basics. So take that first step today. Your journey to becoming a Linux power user is just beginning.