File Manipulation
How to manipulate files and directories
In Chapter 2, you learned about navigating files and directories. In Chapter 3, you will be creating, moving, copying, and deleting them.
mkdir- creates a directory.
rmdir- remove an empty directory.
touch- create a file. This command modifies the timestamp of the file, but if the file does not exist, it creates it.
Notice how the directories are blue and regular files are white?
rm- remove files and non-empty directories.
If you are trying to remove a directory, but it is not empty, it will give you an error. To get pass this error, use rm with the -r option.
mv- move file.
Quick Exercise:
In this series of commands, two directories named “FirstDir” and “SecondDir” are created. Going into the FirstDir directory, file called testfile is created. Using the mv command, testfile gets moved into the SecondDir directory. Because we are currently in FirstDir, we would have to go up a directory(“../”) or back to the home directory which SecondDir is in. To see if the mv command has been properly used, use the ls command to see that FirstDir is empty and the testfile file has been moved into SecondDir.
cp- copy a file.
Now let’s copy the testfile from SecondDir into FirstDir so both directories have a testfile file. In SecondDir, run the cp command (pictured below), and check that both directories contain a copy of testfile.
< Last Lesson Chapter Quiz >