Monday, July 10, 2023
HomeNetworkingMaking a listing tree with a single command

Making a listing tree with a single command


The mkdir command can do greater than create a single listing. It will probably create a number of directories directly and may even create a whole listing construction with a single command. The required command can be a tad advanced, however not notably difficult.

NOTE: In case you attempt to arrange a multi-level listing construction with a command just like the one proven under, it will not work if the preliminary directories (“this” and “that”) do not exist already.

$ mkdir this/that/the_other
mkdir: can not create listing ‘this/that/the_other’: No such file or listing

Add a -p (for “mother and father”) and the lacking directories can be created and your this/that/the_other listing construction can be arrange in your present listing as supposed.

$ mkdir -p this/that/the_other
$ ls -l this/that
complete 4 drwxrwxr-x 2 shs shs 4096 Jul 7 10:01 the_other <== all executed!

Making a extra advanced listing construction

You can even arrange a listing construction that has a number of subdirectories at some degree. Within the following instance, 4 separate directories can be arrange throughout the Paperwork/private listing. And, once more, given the usage of -p, the Paperwork and Paperwork/private directories will first be arrange if they do not exist already.

$ mkdir -p ~/Paperwork/private/{residence,household,funds,tales}
$ ls -l Paperwork/private
complete 16
drwxrwxr-x 2 shs shs 4096 Jul 7 09:52 household
drwxrwxr-x 2 shs shs 4096 Jul 7 09:52 funds
drwxrwxr-x 2 shs shs 4096 Jul 7 09:52 residence
drwxrwxr-x 2 shs shs 4096 Jul 7 09:52 tales

As well as, you may specify a collection of subdirectories at a number of ranges within the listing tree that you simply’re organising. This is a quite simple instance:

$ mkdir -p testing/{1,2,3}/{a,b,c}

This can arrange three subdirectories inside a “testing” listing and three subdirectories inside every of these subdirectories. If in case you have the tree command put in, you may view the brand new construction with a command like this one:

$ tree testing
testing
├── 1
│   ├── a
│   ├── b
│   └── c
├── 2
│   ├── a
│   ├── b
│   └── c
└── 3
    ├── a
    ├── b
    └── c

As well as, you may add further subdirectory ranges if you have to.

An alternative choice is to make use of syntax like that proven under to create subdirectories in solely one of many new directories. You are able to do that by including curly brackets round a portion of the command as proven under in order that solely the articles listing can be arrange with subdirectories.

$ mkdir -p tech/{articles/{new,outdated},photographs,notes,feedback}

Once more, the tree command will provide you with a helpful view of the listing construction you may have simply created.

$ tree tech
tech
├── articles
│   ├── new
│   └── outdated
├── feedback
├── photographs
└── notes

Wrap-up

The mkdir command can create advanced listing constructions and the tree command is ideal for confirming the listing construction you’ve got simply arrange. Understand that you may take away a listing construction with a command like “rm -rf this” in case your command did not just do what you wanted it to do and check out once more.

Copyright © 2023 IDG Communications, Inc.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments