CHAPTER 13. Exercises
As we have already learned above, the creation of a directory is pretty easy. In the same manner, removing or deleting a directory from the Linux system is also very simple. One thing that you have to bear in mind, however, once you remove or delete a directory from the Linux system, there is no way to undo that task. Therefore, the best thing is whenever you are running any command on Linux; the first thing is to be careful with what you do. If it means double checking the command before running it, the better. The command we are going to use to remove or delete a directory is rmdir which stands for remove directory. The things that you have to take note of here is that rmdir command supports the –p and –v options in the same manner as mkdir command. Additionally, the directory has to be empty before t is removed. We will learn how to get around this later.  
  1. rmdir linux_tutorial/beginner/commands  
  2. ls linux_tutorial/beginner  
How to create a blank file 
Many commands that are involved in data manipulation within a file have a superb feature that they will create a file automatically when we refer to it, and we find that it does not exist. As a matter of fact, we can manipulate this feature to create a blank file using the touch command. In other words, you type the command touch followed by the command line option and the file name. 
  1. pwd  
  2. /home/Gary/linux_tutorial  
  3. ls  
  4. beginner  
  5. touch practice_exercise1  
  6. ls practice_exercise1 commands 
Copying a file or a directory   
Let us consider the following example: 
  1. user@bash: ls  
  2. practice_exercise1 commands  
  3. cp practice_exercise1 Exercise1 
  4. ls  
  5. practice_exercise1 Exercise1 commands 
An important thing that we have to note in this case is the source and the destination point at the paths. Some examples that we can consider here include: 
When you use the cp command, the destination of the file can represent a path to a file or a directory. If the destination is to a file such as Exercise1, 2 and 3, then this will create a copy of the files in the destination file, but the original remains in the source file or directory. If we copy the files into a directory, the files will maintain the names in the destination directory. In the default behavior of the cp command, it will only copy a file. The term recursive in this case means that you would wish to copy the directory and all the contents of that very directory which could include files, directories, and subdirectories among others. 
Let us consider the following example: 
  1. user@bash: ls  
  2. Gary Practicals transfers 
  3. user@bash: cp Practicals Practicals_beginner 
  4. cp: omitting directory ‘Practicals.' 
  5. user@bash: cp -r Practicals Practicals_beginner  
  6. user@bash: ls  
  7. Gary Practicals transfers Practicals_beginner 
Bear in mind that any files or directories that are within the Practicals directory will be copied into the Practicals_beginner directory.