LINUX FUNDAMENTALS

Linux Basic Commands for Beginners

Learn essential Linux commands with simple explanations, practical examples, and terminal outputs. Understand how to manage files, directories, and software.

Beginner Friendly Linux CLI Commands & Outputs Practice Labs

01. Introduction to Linux Commands

Linux commands allow us to interact with the operating system using a terminal. We can create files, remove directories, move data, install software, and manage the system without using a graphical interface.

The terminal accepts commands and displays their results. This is especially useful for Linux administration, networking, and cybersecurity.

What Does a Terminal Prompt Look Like?

Linux Terminal
student@linux:~$ pwd
/home/student

In this example, student is the username, linux is the computer name, and ~ represents the user's home directory.

Note: The commands and outputs below are examples. Your username, directory names, and software versions may be different.

02. rmdir — Remove an Empty Directory

rmdir

The rmdir command removes an empty directory. It cannot remove a directory that still contains files or other directories.

Syntax

rmdir directory_name

Example and Output

rmdir example
student@linux:~$ mkdir demo

student@linux:~$ ls -d demo
demo

student@linux:~$ rmdir demo

student@linux:~$ ls -d demo
ls: cannot access 'demo': No such file or directory

First, we created an empty directory named demo. The rmdir command removed it. The final ls command confirms that the directory no longer exists.

Remember: A successful rmdir command normally displays no output.

03. rm — Remove Files

rm

The rm command removes files from the filesystem. It is commonly used to delete files that are no longer needed.

Syntax

rm filename

Example and Output

rm example
student@linux:~$ touch notes.txt

student@linux:~$ ls notes.txt
notes.txt

student@linux:~$ rm notes.txt

student@linux:~$ ls notes.txt
ls: cannot access 'notes.txt': No such file or directory

The touch command created an empty file named notes.txt. The rm command removed that file.

Warning: Files deleted using rm do not normally go to the desktop Trash or Recycle Bin. Always check the filename before deleting anything.

04. rm -r — Remove a Directory and Its Contents

rm -r

The rm -r command removes a directory recursively. This means it removes the directory along with the files and subdirectories inside it.

The -r option means recursive.

Syntax

rm -r directory_name

Example and Output

rm -r example
student@linux:~$ mkdir project

student@linux:~$ touch project/file.txt

student@linux:~$ ls project
file.txt

student@linux:~$ rm -r project

student@linux:~$ ls -d project
ls: cannot access 'project': No such file or directory

We created a directory called project and added a file inside it. The rm -r command removed both the file and its parent directory.

05. rm -rf — Force Recursive Removal

rm -rf

The rm -rf command recursively removes files and directories while ignoring missing files and suppressing many confirmation prompts.

Here, -r means recursive and -f means force.

Important: This command can cause serious data loss if used with the wrong path. Never copy an unfamiliar rm -rf command without understanding exactly what it will remove.

Safe Practice Example

rm -rf practice
student@linux:~$ mkdir practice-folder

student@linux:~$ touch practice-folder/test.txt

student@linux:~$ ls practice-folder
test.txt

student@linux:~$ rm -rf practice-folder

student@linux:~$ ls -d practice-folder
ls: cannot access 'practice-folder': No such file or directory

This example removes only the temporary practice-folder that we created. It should not be used on important directories.

06. cp — Copy Files

cp

The cp command copies files from one location to another. It can also create another copy of a file with a different name.

Syntax

cp source destination

Example and Output

cp example
student@linux:~$ echo "Hello Linux" > notes.txt

student@linux:~$ cp notes.txt backup.txt

student@linux:~$ ls
backup.txt  notes.txt

student@linux:~$ cat backup.txt
Hello Linux

The command copied the contents of notes.txt into backup.txt. The original file still exists.

Remember: Copying a file creates another file. It does not remove the original.

07. cp -r — Copy Directories

cp -r

The cp -r command copies a directory together with the files and subdirectories inside it.

The -r option means recursive.

Syntax

cp -r source_directory destination_directory

Example and Output

cp -r example
student@linux:~$ mkdir documents

student@linux:~$ touch documents/file1.txt

student@linux:~$ cp -r documents documents-backup

student@linux:~$ ls documents-backup
file1.txt

The documents directory was copied into a new directory called documents-backup. Both directories now exist.

08. mv — Move or Rename Files and Directories

mv

The mv command is used to move files and directories to another location. It can also rename them.

Example 1: Rename a File

mv rename example
student@linux:~$ touch oldname.txt

student@linux:~$ mv oldname.txt newname.txt

student@linux:~$ ls newname.txt
newname.txt

The file was renamed from oldname.txt to newname.txt.

Example 2: Move a File

mv move example
student@linux:~$ mkdir backup

student@linux:~$ mv newname.txt backup/

student@linux:~$ ls backup
newname.txt

The file newname.txt was moved into the backup directory.

Important: Unlike cp, the mv command does not normally leave a second copy at the original location. It may also overwrite an existing destination file.

09. sudo apt update — Refresh Package Information

sudo apt update

The sudo apt update command downloads the latest package information from configured software repositories.

It helps the system discover available software versions and updates. It does not install those updates by itself.

What Does Each Part Mean?

Example and Output

apt update example
student@linux:~$ sudo apt update
[sudo] password for student:

Hit:1 http://deb.debian.org/debian stable InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
All packages are up to date.

This example shows that the package lists were refreshed successfully. The repository addresses and messages may differ on your Linux system.

Remember: apt update updates the package information, not the installed software packages.

10. sudo apt upgrade — Upgrade Installed Packages

sudo apt upgrade

The sudo apt upgrade command upgrades installed software packages when newer compatible versions are available in the configured repositories.

It is commonly used after sudo apt update.

Example and Output

apt upgrade example
student@linux:~$ sudo apt upgrade

Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
Calculating upgrade... Done

0 upgraded, 0 newly installed,
0 to remove and 0 not upgraded.

In this example, no upgrades were available. If updates are available, APT may show a list of packages and ask for confirmation.

Difference Between Update and Upgrade

Command Purpose
sudo apt update Refreshes the available package information.
sudo apt upgrade Upgrades installed packages when suitable updates are available.
Important: These APT commands apply to Debian-based distributions such as Ubuntu, Debian, and Kali Linux. Other Linux distributions may use different package managers. Review proposed upgrades before confirming them.

11. Hands-On Linux Practice Lab

Now practice the commands you have learned. Use a test directory so you do not accidentally modify important files.

Lab 1 — Create and Copy a File

Goal: Create a file and make a backup copy.

Practice Lab 1
student@linux:~$ mkdir linux-practice

student@linux:~$ cd linux-practice

student@linux:~/linux-practice$ echo "Linux Practice" > file.txt

student@linux:~/linux-practice$ cp file.txt backup.txt

student@linux:~/linux-practice$ ls
backup.txt  file.txt

You created a practice directory, added a file, and copied it using cp.

Lab 2 — Rename and Remove a File

Goal: Practice mv and rm.

Practice Lab 2
student@linux:~/linux-practice$ mv backup.txt saved.txt

student@linux:~/linux-practice$ ls
file.txt  saved.txt

student@linux:~/linux-practice$ rm saved.txt

student@linux:~/linux-practice$ ls
file.txt

You renamed backup.txt to saved.txt, then removed it.

Lab 3 — Remove an Empty Directory

Goal: Understand how rmdir works.

Practice Lab 3
student@linux:~/linux-practice$ mkdir empty-folder

student@linux:~/linux-practice$ rmdir empty-folder

student@linux:~/linux-practice$ ls
file.txt

The empty directory was removed successfully.

Practice tip: Run pwd and ls before deleting files. These commands help you confirm your current directory and its contents.

12. Quick Revision

Command What It Does
rmdir Removes an empty directory.
rm Removes files.
rm -r Removes a directory and its contents recursively.
rm -rf Forces recursive removal; use carefully.
cp Copies files.
cp -r Copies directories and their contents.
mv Moves or renames files and directories.
sudo apt update Refreshes package information.
sudo apt upgrade Upgrades installed packages.

13. Additional Learning Resources

Use these references to learn more about Linux commands and practice safely.