0% found this document useful (0 votes)
6 views

Practical 2 MonikaSethi

The document provides an overview of essential Linux commands related to directory management, including pwd, cd, mkdir, and rmdir. It explains how to navigate directories, create new ones, and remove empty directories, along with examples and key features of each command. Additionally, it highlights the differences between rmdir and rm commands for directory deletion.

Uploaded by

rainbro187
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Practical 2 MonikaSethi

The document provides an overview of essential Linux commands related to directory management, including pwd, cd, mkdir, and rmdir. It explains how to navigate directories, create new ones, and remove empty directories, along with examples and key features of each command. Additionally, it highlights the differences between rmdir and rm commands for directory deletion.

Uploaded by

rainbro187
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Linux Commands

Prepared By

Dr, Monika Sethi

Chitkara University Institute of Engineering and


Technology,
Chitkara University, Punjab
Content Experiment 2

Implement Directory oriented commands:


pwd, cd, mkdir, rmdir

2
pwd Command

The pwd (Print Working Directory) command is used to display


the current directory you are in. It helps you know your exact
location in the file system.

3
cd (Change Directory) Command
1. Basic Usage
cd directory_name

🔹 Moves into the specified directory.

Example:
cd Documents

Moves into the Documents folder.

2. Move to Home Directory


cd

🔹 Moves to your home directory (/home/username).

3. Move to the Root Directory (/)


cd / (cd space /)

🔹 Moves to the root directory (the top-level of the filesystem).


4
1. Root Directory (/)
🔹 Definition:

● The top-most directory in the Linux filesystem.


● All other directories and files are inside it.

🔹 Path:

cd /

🔹 Key Features:

● It contains all system files and directories (like /bin, /etc, /var).
● Accessible only by the root user for critical tasks.
● Modifying system files here without care can break the system.
5
2. Home Directory (/home/username)
🔹 Definition:
● A personal space for each user to store files and settings.
● Every user gets a separate home directory.

🔹 Path:
cd ~
# OR
cd /home/yourusername
# OR
cd
🔹 Key Features:
● Normal users have full control over their home directory.
● Stores personal files, downloads, and configuration files (like .bashrc).
● Safer for regular work compared to /. 6
4. Move Up One Level (..)
cd ..

🔹 Moves one level up to the parent directory.

Example:

cd ..

If you are in /home/user/Documents, running cd .. will take you to /home/user.

5. Move Up Multiple Levels


cd ../..

🔹 Moves two levels up in the directory structure.

Example: If you are in /home/user/Documents/Work, running cd ../.. will take you


to /home/user.
7
6. Move to the Previous Directory (-)
cd -

🔹 Switches to the last directory you were in.

Example:

cd /var/log

cd /home/user

cd -

🔹 This takes you back to /var/log.

7. Move to an Absolute Path


cd /etc/network

🔹 Moves directly to /etc/network (absolute path).

8
8. Move to a Relative Path
cd Documents/Work

🔹 Moves to the Work folder inside Documents.

9. Using cd with Spaces in Folder Names


If a folder name has spaces, use quotes or a backslash (\):
cd "My Folder"
cd My\ Folder

9
10
mkdir Command
1. mkdir Command (Make Directory)

The mkdir command is used to create a new directory.

Basic Usage
mkdir myfolder

🔹 This creates a new folder named myfolder in the current directory.

Common Options

1. Create Multiple Directories

mkdir folder1 folder2 folder3


🔹 This creates three directories: folder1, folder2, and folder3.

2. Create Parent Directories (-p option)


mkdir -p parent/child/grandchild

🔹 If parent does not exist, it will create all missing directories.


11
Check Help/Manual

mkdir --help # Quick guide


man mkdir # Full manual

12
rmdir Command (Remove Directory)

The rmdir command removes empty directories.

Basic Usage
rmdir myfolder
🔹 This deletes the folder myfolder only if it is empty.

Removing Multiple Empty Folders


rmdir folder1 folder2 folder3
🔹 Deletes multiple empty directories.
Important Notes:

🚨 rmdir cannot remove non-empty directories. If a folder has files inside, use:

rm -r myfolder

🔹 This forcefully removes myfolder and all its contents.

13
1. rm (Remove)
✅ Used to delete files and directories
✅ Can remove both empty and non-empty directories
✅ Supports forceful deletion (-f) and recursive deletion (-r)

2. rmdir (Remove Directory)


✅ Used to delete empty directories only
✅ Cannot delete non-empty directories
✅ Safer than rm because it won’t remove directories with files
inside

14
15

You might also like