Chapter 4 directory operations
4.3.1 column directory
$ Ls directory
-D option, force to display only the directory name, not the content
4.4 operation directory
4.4.1 create a directory
Mkdir directory
Example: $ mkdir hw1
Create the hw1 directory in the current directory
$ Mkdir/tmp/test-Dir
Create the test-Dir directory under the/tmp directory
1. Create parent directory
$ Mkdir/tmp/ch04/test1
If the parent directory of the specified directory does not exist, the system will prompt an error.
Mkdir: failed to make directory "/tmp/ch04/test1"; no such file or directory
In this case, you can declare-P for the mkdir command. The required directory is created for the parent directory that does not exist.
$ Mkdir-P/tmp/ch04/test1
The execution process is as follows:
1) run the mkdir command to check whether the directory/tmp exists. If it does not exist, create it.
2) run the mkdir command to check whether/tmp/ch04 exists. If not, create it.
3) run the mkdir command to check whether/tmp/ch04/test1 exists. If not, create it.
2. Common Errors
1) try to create an existing Directory.
4.4.2 copy files and directories
CP can also be used to copy directories.
For example:
$ CP-r docs/book docs/School Work/src/mnt/zip
Copy the school and book directories under the docs directory and the src directory under the Work directory to/mnt/zip.
$ LS-AF/mnt/zip
Result: ../book/school/src/
Common Errors:
1) The target address is not a directory.
2) The target address already exists.
4.4.3 move files and directories
Music videos can be used to rename files, but they are designed to move files and directories between directories.
$ MV source destination
Here, source is the name of the file or directory to be moved, and destination is the directory to which the file or directory is moved.
$ MV/home/Ranga/names/tmp
$ MV docs/work/
Move the directory docs to the directory work.
Move multiple files
$ MV work/docs/. Profile pub/
Move the directory docs, work, and file. profile to the pub directory.
Common Errors:
1) Move multiple files and directories to a non-existent directory
2) Move the file and directory to a file
3) Try to move directories across the File System
4.4.4 delete a directory
You can use:
1. $ rmdir
2. $ Rm-R
Use the first line to delete an empty directory.
The second command is considered unsafe because it cannot be recovered.
1. rmdir
To delete an empty directory, run the rmdir command.
Rmdir Directories
2. Common Errors
Try to delete a non-empty directory
Try to use rmdir to delete the file
3. rm-R
You can use RM with the-r option to delete a directory and its content.
$ Rm-r ch01/
Delete the ch01 directory and its contents. This command does not generate output or interact with each other.
-I: Interactive delete operations
Exercise:
1. What command is used to copy/usr/local to/opt/PGMS?
CP/usr/local/opt/PGMS