File and directory management
Use the CLI to manage files and directories.
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.
bash
cd # switch to your home directory
mkdir MyLab
ls # You should see the new MyLab/ directory.
cd MyLab
ls # You will not see anything. The directory is empty.
cd ..
rm -r MyLab
ls # MyLab should now be gone
Creating, Copying, and Deleting Files
touch
- Create an Empty Filecp
- Copy Files and Directoriesrm
- Remove Filesmv
- Move or Rename Files
bash
cd # go to your home directory
ls
touch sample.txt
ls
cp sample.txt sample_copy.txt
ls
mv sample.txt renamed_sample.txt
ls
rm sample_copy.txt
ls
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
Next
Move on to Text files.