Linux directory creation and deletion commands

Source: Internet
Author: User
Tags file size mkdir parent directory

  Linux directory creation and deletion command basics:

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. Requires the user who created the directory to have write permissions in the current directory (in the Dir-name parent directory), and dirname cannot be the existing directory or file name in the current directory.

The meanings of the options in the command are:

-M sets access permissions on the new directory. You can also set it with the chmod command.

-P can be a path name. In this case, if some directories in the path do not already exist, plus this option, the system will automatically establish those directories that do not yet exist, that is, you can build multiple directories at once.

  rmdir command

Function: Deletes an empty directory.

Syntax: rmdir [Options] Dir-name

Description: Dir-name represents the directory name. This command deletes one or more child directory entries from one directory. It is important to note that a directory must be empty before it is deleted. The Rm-r dir command can replace RmDir, but it is dangerous. You must also have write permissions to the parent directory when you delete a directory.

The meanings of the options in the command are:

-p recursively deletes the directory dirname, which is also deleted when the subdirectory is deleted and its parent directory is empty. If the entire path is deleted or some of the paths are retained for some reason, the system displays the appropriate information on the standard output.

  CD command

Function: Change working directory.

Syntax: CD [directory]

Description: This command changes the current directory to the directory specified by directory. If directory is not specified, it is returned to the user's home directory. In order to change to a specified directory, the user must have execute and Read permissions on the specified directory.

The command can use wildcard characters (see chapter tenth for wildcard meanings).

  PWD command

In the Linux hierarchy, users can create a new directory using the mkdir command in any given directory, or use the CD command to convert from one directory to another. However, there is no prompt to tell the user which directory is currently in. To know the current directory, you can use the PWD command, which displays the entire path name.

Syntax: pwd

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

  ls command

LS is a shorthand for the English word list, and its function is to list the contents of the catalog. This is one of the most commonly used commands for users, because users need to view the contents of a directory from time to times. This command is similar to the dir command under DOS.

Syntax: LS [options] [directory or file]

For each directory, the command lists all subdirectories and files in it. For each file, LS outputs its filename and other information required. By default, output entries are sorted in alphabetical order. When no directory name or filename is given, the information for the current directory is displayed.

The options in the command have the following meanings:

-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 do not list "." and ".."

-B Displays the octal escape character for the non displayed characters in the filename.

-C is sorted by file modification time.

-C is divided into multiple columns to display items.

-D If the parameter is a directory, display only its name without displaying the files below it. Often used with the L option to get detailed information about the directory.

-F not sorted. This option will invalidate the LTS option and make the AU option valid.

-F Mark "/" After the directory name, "*" After the executable file, Mark "@" after the symbol link, mark "|" after the pipe (or FIFO), and Mark "=" after the socket file.

-I displays the I node number of the file in the first column of output.

-L Displays the details of the file in long format. This option is most commonly used.

The information listed in each row is: File type and permission link number file is the main file of the group file size established or recently modified time name

For a symbolic link file, the file name that appears is followed by a "-〉" and a reference file path name.

For device files, the File Size field displays the primary, secondary, and not the file size.

The total number of blocks in the table of contents is displayed at the beginning of the long format list, which contains the indirect blocks.

-L Displays the file that the link points to if the specified name is a symbolic link file.

-M output is in character stream format, file spread, separated by commas.

-The N output format is the same as the L option, except that in the output Chinese part and the group are represented by the corresponding UID number and the GID number, rather than the actual name.

-O is the same as the L option, except that the owner information is not displayed.

-P adds a "/" to the back of the directory.

-Q Use the "?" for the characters that are not displayed in the file name. Replace.

-R Displays the output in alphabetical order or in the earliest priority.

-R recursively displays the files in each subdirectory of the specified directory.

-S gives the number of blocks to use for each directory entry, including the indirect block.

-The t is sorted by modified time (most recently first) instead of by name. If the file is modified in the same time, in dictionary order. The modification time depends on whether the C or U selection is used. The default time stamp is the last modification time.

-U when displayed by file last accessed time (most recent priority) instead of by name. The time tag for-T is modified to the last access time.

-X displays information about each sorted item by row.

The information displayed with the LS-L command begins with a 10-character string with the first character representing the file type, which can be one of the following types:

-Common documents

D Directory

L Symbolic Link

B Block Device file

C Character device file

The following 9 characters represent the access rights of the file, divided into 3 groups, 3 bits per group.

The first group represents the permissions of the file owner, the second group represents the permissions of the same group of users, and the third group represents the permissions of other users. The three characters for each group represent read, write, and execute permissions on the file respectively.

The permissions are as follows:

R Read

W Write

X execution. For the directory, the entry permission is represented.

s when the file is executed, the UID or GID of the file is given the UID (user ID) or GID (group ID) of the execution process.

T sets the flag bit (left in memory, not swapped out). If the file is a directory, the files in that directory can only be deleted by Superuser, directory owner, or file owner. If it is an executable file, the pointer to its body section remains in memory after the file is executed. This allows the system to load the file more quickly when it is executed again.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.