Training Missions

Missions: Using command line shell

Creating and removing

mkdir: Make directory

The mkdir command will allow you to create directories. For example,

$ mkdir penguin

will create a directory called "penguin".

Any number of directories can be created simultaneously. Thus, for example, the following command would create three directories within the current directory (i.e., the directory in which the user is currently working) with the names dir1, dir2 and dir3:

$ mkdir dir1 dir2 dir3

If a directory with that name already exists in the current directory, mkdir will return a warning message such as mkdir: cannot create directory 'dir1': File exists and will not create a file with that name. However, it will then continue to create directories for any other names provided as arguments.

rm: Remove files or directories:

The command name "rm" is derived from "remove." You can use this command to remove or delete a file in your directory. For example, to remove a file named test.txt present in your current directory, you can type

$ rm test.txt

Removing directories:

By default, rm does not remove directories. If the -r (--recursive) option is specified, however, it will. For example,

rm -r penguin

will remove the directory penguin and its contents recursively. What does "recursively" mean? Think of it this way: this command will remove the directory and all its files and subdirectories, and all the subdirectories' files and subdirectories, and on and on ("recursively") until the original directory penguin is completely empty.

Challenge:

What is the output of the ls command in the sequence given below?

$ ls
test.txt music
$ mkdir videos
$ rm -r music
$ ls
test.txt
videos
test.txt videos
music videos