Intro to Linux File Management

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson

Questions and Answers

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?

  • 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?

  • `rmdir`
  • `ls`
  • `cd`
  • `mkdir` (correct)

What condition must be met before using the rmdir command to remove a directory?

<p>The directory must be empty. (C)</p> Signup and view all the answers

Which command would recursively remove a directory and all its content, including subdirectories and files?

<p><code>rm -rf</code> (D)</p> Signup and view all the answers

What is the purpose of the mv command when used on directories?

<p>To rename or move the directory. (A)</p> Signup and view all the answers

Which command is used to copy a directory, including its contents, to a new location?

<p><code>cp</code> (A)</p> Signup and view all the answers

How can you navigate to a home directory in Linux?

<p>Using the command <code>$ cd ~</code> (A)</p> Signup and view all the answers

What does pwd command display?

<p>Present working directory. (B)</p> Signup and view all the answers

After creating a directory named 'reports' inside your home directory, how would you navigate into it using a relative path from your home directory?

<p>cd reports (D)</p> Signup and view all the answers

Flashcards

Linux Directory

A file that primarily stores file names and related information in Linux.

Linux Home Directory

The directory for a specific user, also known as the login directory, automatically created as /home for each user.

Absolute Pathname

Begins at the root directory (/) and provides the full path to a file or directory.

Relative Pathname

Defines the location of a file or directory relative to the current working directory. Never starts with a /.

Signup and view all the flashcards

mkdir command

Creates directories. Syntax: $mkdir

Signup and view all the flashcards

rmdir command

Deletes directories. Syntax: $rmdir . Directory must be empty.

Signup and view all the flashcards

rm -rf command

Recursively removes a directory and its contents (files and subdirectories). Use with caution.

Signup and view all the flashcards

mv command (for renaming)

Renames a directory. Syntax: $mv

Signup and view all the flashcards

cp Command

Copies a directory. Syntax: $cp

Signup and view all the flashcards

cd command

Changes the current directory. Syntax: $cd dirname

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 renames mydir to yourdir

  • 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
    1. mv traffic/green/go traffic/red
    2. cd traffic
    3. Cd red
    4. ls
  • Copy the ready directory to green
    1. cd ..
    2. cp –r yellow/ready green
    3. cd green
    4. ls
  • Rename red directory to error directory
    1. cd ..
    2. mv red error
    3. ls
  • Delete ready directory
    1. rmdir yellow/ready
    2. cd yellow
    3. 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.

Quiz Team

Related Documents

More Like This

Use Quizgecko on...
Browser
Browser