Linux Directory Commands:mkdir, rmdir, tree dirname,basename

Source: Internet
Author: User
Tags create directory

Directory management class commands for Linux commands: mkdir, rmdir, tree, DirName, basename



mkdir command: Create directory/new directory

Syntax: mkdir [OPTION]/path/to/somewhere

Common parameter options:

-P: Create parent directory//Recursive creation

-V: Display creation information


Example:

How to create a directory under/tmp/: X_m, X_n, Y_m, Y_n

# mkdir/tmp/{x_,y_}{m,n}

rmdir command: Delete directory

Syntax: Rmdir/path/to/somewhere

Common parameter options:

-P: Delete along with empty directory on upper level (use cautiously)


-p:will also create all directories leading up to the given directory that does not exist already. If the given directory already exists, ignore the error.

-v:display each directory, that mkdir creates. Most often used with-p.

-m:specify the octal permissions of directories created by mkdir.


-P is the most often used when using mkdir to build up complex directory hierarchies, in case a necessary directory is missing or already there. -M is commonly used to lock down temporary directories used by shell scripts.


Examples[edit]


An example of-p on action is:


Mkdir-p/tmp/a/b/c


IF/TMP/A exists but/tmp/a/b does not, mkdir would create/tmp/a/b before creating/tmp/a/b/c.

And an even more powerful command, creating a full tree at once (this however was a Shell extension, nothing mkdir does its ELF):

Mkdir-p Tmpdir/{trunk/sources/{includes,docs},branches,tags}


If one is using the variables with mkdir in a bash script, the POSIX ' special ' built-in command ' eval ' would serve its purpose.


Domain_name=includes,docs

Eval "Mkdir-p Tmpdir/{trunk/sources/{${domain_name}},branches,tags}"



This would create:


Tmpdir

________|______

|      | |

Branches Tags Trunk

|

Sources

____|_____

| |

Includes docs


Tree command: List contents of a table

Syntax: Tree [OPTION] ... [DIR]

-D: File of only hierarchical directory type;

-L Level: shows only a few levels;

dirname command: Removes the file name (part of the non-directory) from the given file name that contains the absolute path, and then returns the remaining


Path (part of the directory)

Syntax: DirName FILENAME

Example:

# Dirname/etc/sysconfig/network-scripts/ifcfg-eth0

/etc/sysconfig/network-scripts

basename command: Removes the left part of the directory from a given file name that contains an absolute path, or simultaneously removes a suffix within


(Part of the directory), and then return to the remainder (part of the non-directory)

Syntax: basename FILENAME [SUFFIX]

Example:

#basename/etc/sysconfig/network-scripts/ifcfg-eth0

Ifcfg-eth0


This article is from the "it_working" blog, make sure to keep this source http://weine100.blog.51cto.com/2152945/1691296

Linux Directory Commands:mkdir, rmdir, tree dirname,basename

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.