File and directory management
Use the CLI to manage files and directories.
You are getting the first edition of all these pages. Please let me know if you find an error!
By the end of the lab, you should be able to navigate the Linux file system, manage files and directories, manipulate text files, understand basic file permissions, and utilize process management commands.
Part 2: File and Directory Management
Reminder: All file system names a case-sensitive.
Now, let’s practice adding and removing files and directories using the CLI.
Creating and Removing Directories
mkdir
- Make Directoryrmdir
- Remove Directoryrm -r
- Remove Directory and its contents recursively. WARNING: This is going to delete the directory and everything below it recursively. Linux does not have ‘undelete’, so be very careful with this command!
The commands below have a #
character, which indicated the beginning of a comment. # comments
are there for clarification and you do not type them.
Type ls
after each command below to see the changes:
bash
cd # switch to your home directory
mkdir MyLab
cd MyLab
rmdir MyLab # This should fail because the directory is not empty
cd ..
rm -r MyLab
Creating, Copying, and Deleting Files
touch
- Create an Empty Filecp
- Copy Files and Directoriesrm
- Remove Filesmv
- Move or Rename Files
Type ls
after each command below to see the changes:
bash
cd # go to your home directory
touch sample.txt
cp sample.txt sample_copy.txt
mv sample.txt renamed_sample.txt
rm sample_copy.txt
Exercise
- Create a new directory named
LabDirectory
- Navigate into this directory using the
cd
command - Create a new file named
LabFile.txt
inside this directory. Usetouch
- Copy this file to a new file named
LabFileCopy.txt
. Usecp
- Delete
LabFileCopy.txt
. Userm