Welcome to Team5 Unix Live

File Basics

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.

mkdir [options] <Directory>

mkdir

rmdir- remove an empty directory.

rmdir [options] <Directory>

rmdir

touch- create a file. This command modifies the timestamp of the file, but if the file does not exist, it creates it.

touch <filename>

touch

Notice how the directories are blue and regular files are white?

rm- remove files and non-empty directories.

rm <filename>

rm

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.

rm-r

mv- move file.

mv <source> <destination>

mv

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.

cp [options] <source> <destination>

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.

cp < Last Lesson Chapter Quiz >