Linux directory creation and deletion commands basics

  

[Computer Shop News]

Function: Create a directory (similar to the md command under MSDOS).

Syntax: mkdir [options] dir-name

Description: This command creates a directory named by dir-name. The user who requested the directory creation has write permission in the current directory (in the parent directory of dir-name), and dirname cannot be the directory or file name already in the current directory.

The meaning of each option in the command is:

- m Set access permissions for the new directory. It can also be set with the chmod command.

- p can be a path name. At this point, if some directories in the path do not exist yet, with this option, the system will automatically create those directories that do not exist yet, that is, you can create multiple directories at a time.

rmdir Command

Function: Delete an empty directory.

Syntax: rmdir [options] dir-name

Description: dir-name indicates the directory name. This command removes one or more subdirectory entries from a directory. It is important to note that a directory must be empty before it is deleted. The rm -r dir command can be used instead of rmdir, but it is dangerous. You must also have write access to the parent directory when you delete a directory.

The meaning of each option in the command is:

- p Recursively deletes the directory dirname, and when the parent directory is empty after the subdirectory is deleted, it is also deleted. If the entire path is deleted or part of the path is reserved for some reason, the system displays the corresponding information on the standard output.

cd command

Function: Change the working directory.

Syntax: cd [directory]

Description: This command changes the current directory to the directory specified by the directory. If no directory is specified, it will be returned to the user's home directory. In order to change to the specified directory, the user must have execute and read permissions to the specified directory.

This command can use wildcards (see Chapter 10 for the meaning of wildcards).

pwd Command

In the Linux hierarchical directory structure, users can create new directories using the mkdir command in any directory that is authorized. You can also use the cd command to convert from one directory to another. . However, there is no prompt to tell the user which directory it is currently in. To know which directory is currently in use, you can use the pwd command, which displays the entire pathname.

Syntax: pwd

Description: This command displays the absolute path of the current working directory.

ls Command

ls is short for English word list, its function is to list the contents of the directory. This is one of the most common commands for users because users need to view the contents of a directory from time to time. This command is similar to the dir command under DOS.

Syntax: ls [options] [directory or file]

For each directory, this command will list all subdirectories and files in it. For each file, ls will output its file name and other information requested. By default, output entries are sorted alphabetically. When the directory name or file name is not given, the information of the current directory is displayed.

The meanings of the options in the command are as follows:

- a Displays all subdirectories and files in the specified directory, including hidden files.

- A Displays all subdirectories and files in the specified directory, including hidden files. But not listed “.” and “..”.

- b Displays undisplayable characters in file names in octal escape characters.

- c Sort by the modification time of the file.

- C Divides into multiple columns to display items.

- d If the parameter is a directory, only its name is displayed instead of the files under it. It is often used with the l option to get the details of the catalog.

- f Do not sort. This option will invalidate the lts option and make the aU option valid.

- F Mark “/” after the directory name, “*” after the executable file, mark the "@” after the symbolic link, mark the pipe (or FIFO) “

Copyright © Windows knowledge All Rights Reserved