Podcast
Questions and Answers
In Linux, what is the primary function of a directory?
In Linux, what is the primary function of a directory?
- To store file names and related information. (correct)
- To manage the kernel processes.
- To execute system commands.
- To compile source code.
What distinguishes an absolute pathname from a relative pathname in Linux?
What distinguishes an absolute pathname from a relative pathname in Linux?
- Absolute pathnames are shorter.
- Absolute pathnames begin at the root directory, while relative pathnames are in relation to the current directory. (correct)
- Relative pathnames are used for system files only.
- Relative pathnames always start with the user directory.
Which command is used to create a new directory in Linux?
Which command is used to create a new directory in Linux?
- `rmdir`
- `ls`
- `cd`
- `mkdir` (correct)
What condition must be met before using the rmdir
command to remove a directory?
What condition must be met before using the rmdir
command to remove a directory?
Which command would recursively remove a directory and all its content, including subdirectories and files?
Which command would recursively remove a directory and all its content, including subdirectories and files?
What is the purpose of the mv
command when used on directories?
What is the purpose of the mv
command when used on directories?
Which command is used to copy a directory, including its contents, to a new location?
Which command is used to copy a directory, including its contents, to a new location?
How can you navigate to a home directory in Linux?
How can you navigate to a home directory in Linux?
What does pwd
command display?
What does pwd
command display?
After creating a directory named 'reports' inside your home directory, how would you navigate into it using a relative path from your home directory?
After creating a directory named 'reports' inside your home directory, how would you navigate into it using a relative path from your home directory?
Flashcards
Linux Directory
Linux Directory
A file that primarily stores file names and related information in Linux.
Linux Home Directory
Linux Home Directory
The directory for a specific user, also known as the login directory, automatically created as /home for each user.
Absolute Pathname
Absolute Pathname
Begins at the root directory (/) and provides the full path to a file or directory.
Relative Pathname
Relative Pathname
Signup and view all the flashcards
mkdir command
mkdir command
Signup and view all the flashcards
rmdir command
rmdir command
Signup and view all the flashcards
rm -rf command
rm -rf command
Signup and view all the flashcards
mv command (for renaming)
mv command (for renaming)
Signup and view all the flashcards
cp Command
cp Command
Signup and view all the flashcards
cd command
cd command
Signup and view all the flashcards
Study Notes
- The lab provides an intro to file management in Linux
- Students learn to use commands for creating, removing, and changing directories.
- Hands-on exercises using terminal commands will help students manage files, and enhance their proficiency in Linux.
Lab Learning Outcomes
- Understand the difference between absolute and relative pathnames in Linux.
- Navigate the Linux file system using command-line tools.
- Create, move, and delete directories using appropriate commands.
Lab Instructions
- The lab instructor will provide guidance on navigating and managing directories using relative and absolute pathnames.
- Students will learn how to create, remove, and change directories, focusing on understanding the differences between relative and absolute paths.
Linux Directory
- Linux Directory stores file names and related information.
- All files, whether ordinary, special, or directories, reside in directories.
- Directories function as containers for files and other directories.
- A Linux home directory is a directory for a specific user, containing individual files known as the login directory.
- After logging in, a Linux system automatically creates this directory as "/home" for each user
- It is a standard subdirectory of the root directory, denoted by a forward slash (/).
- The root directory contains all other directories, subdirectories, and system files.
Absolute/Relative Pathnames
- Directories form a hierarchy with the root (/) at the top.
- A file's position is described by its pathname, with elements separated by a /.
- Absolute pathnames start from the root (/). Example: /etc/passwd
- Relative pathnames relate to the current working directory and never begin with a /. Example: personal/res.
Working with Directories
-
Creating directories: The command
$mkdir <dirname>
creates directories -
mkdir
stands for 'make directory'. -
Example:
$mkdir mydir
creates a directory named mydir in the current directory. -
The command
mkdir
creates multiple directories when given multiple directory names. For example:$mkdir d1 d2 d3
-
Removing Directories: The command
rmdir
deletes directories. -
Syntax:
$rmdir <dirname>
-
Example:
$rmdir d1
-
You can only remove empty directories that don't contain files or sub-directories.
-
Removing Directories: The command
rm -rf directory
recursively removes the directory and all files and directories in that directory structure. Use with caution. -
There is no "trash" container to restore deleted files.
-
Renaming Directories: The
mv (move)
command also renames directories. -
Syntax:
$mv <olddir> <newdir>
-
Example :
$mv mydir yourdir
renamesmydir
toyourdir
-
cp Command: The command
cp
copies a file or directory. -
Syntax:
cp <existing directory name> <new directory name>
-
mv Command: The command
mv
moves a file or directory from one location to another. -
Syntax:
mv <old directory location path> <new directory location path>
Changing Directories
- The
cd
command can change the current directory using an absolute or relative path. - Syntax:
$cd dirname
Create Tree Directories: Example 1
- Create a “university” directory:
mkdir university
- Open university directory:
cd university
- Print the current path(pwd):
pwd
- Create “eng,medic and computer” directories:
mkdir eng medic computer
- Open computer directory:
cd computer
- Print the current path(pwd):
pwd
- Create “ICT and IT” directories:
mkdir ICT IT
Create Tree Directories: Example 2
- Create a “traffic” directory:
mkdir traffic
- Open traffic directory:
cd traffic
- Print the current path(pwd):
pwd
- Create "red,yellow and green" directories:
mkdir red yellow green
- Open red directory:
cd red
- Print the current path(pwd):
pwd
- Create “stop” directory:
mkdir stop
- Go back one step:
cd ..
- Print the current path(pwd):
pwd
- Open yellow directory:
cd yellow
- Create “ready” directory:
mkdir ready
- Go back one step:
cd ..
- Open green directory:
cd green
- Create “go” directory:
mkdir go
- Go back two steps:
cd ../..
- Display traffic tree:
ls
Example 3:
- Move the go directory inside red directory
mv traffic/green/go traffic/red
cd traffic
Cd red
ls
- Copy the ready directory to green
cd ..
cp –r yellow/ready green
cd green
ls
- Rename red directory to error directory
cd ..
mv red error
ls
- Delete ready directory
rmdir yellow/ready
cd yellow
ls
Homework
- Create example tree
- Copy the file1.txt directory to file2.1tx
- Rename image1.png to pic.png
Studying That Suits You
Use AI to generate personalized quizzes and flashcards to suit your learning preferences.