Developing and getting rid of directory structures on Linux

Uncategorized

Handling directory sites on Linux is easy, however the process gets more complex when you require to develop, empty or remove big, complex directory site structures. This post will take you from the most standard commands to some relatively complicated ones that can assist make the process easier.mkdir The mkdir

command can develop a single directory site like this:

$ mkdir newdir

It can also produce a complicated directory and subdirectory structure with a command like the one listed below. The -p argument informs the command to produce the base directory if it does not currently exist.Each group of directory names that appears in the command revealed– like 1,2,3 and docs, script– will result in a series of subdirectories being created at that level. $mkdir -p newdir/ /

You can include as lots of levels to the directory site structure as you need simply by adding additional/ dir1, dir2 type specs to the mkdir command. If you include the -v (verbose) choice, the command will show each directory as it is created.

$ mkdir -pv newdir/ 1,2,3/ mkdir: produced directory ‘newdir’ mkdir: created directory ‘newdir/1’ mkdir: developed directory ‘newdir/1/docs’ mkdir: developed directory site ‘newdir/1/scripts’ mkdir: developed directory ‘newdir/2’ mkdir: developed directory site ‘newdir/2/docs’ mkdir: developed directory site ‘newdir/2/scripts’ mkdir: produced directory ‘newdir/3’ mkdir: produced directory site ‘newdir/3/docs’ mkdir: produced directory ‘newdir/3/scripts’

You can view the directory structure after it is set up using a recursive ls command like this that shows the directory sites at each level:

$ ls -lR newdir newdir: total 12 drwxr-xr-x. 4 shs 4096 Dec 29 11:12 1 drwxr-xr-x. 4 shs 4096 Dec 29 11:12 2 drwxr-xr-x. 4 shs 4096 Dec 29 11:12 3 newdir/1: overall 8 drwxr-xr-x. 2 shs 4096 Dec 29 11:12 docs drwxr-xr-x. 2 shs 4096 Dec 29 11:12 scripts newdir/1/docs: total 0 newdir/1/scripts: overall 0 newdir/2: total 8 drwxr-xr-x. 2 shs 4096 Dec 29 11:12 docs drwxr-xr-x. 2 shs 4096 Dec 29 11:12 scripts newdir/2/docs: total 0 newdir/2/scripts: total 0 newdir/3: overall 8 drwxr-xr-x. 2 shs 4096 Dec 29 11:12 docs drwxr-xr-x. 2 shs 4096 Dec 29 11:12 scripts newdir/3/docs: overall 0 newdir/3/scripts: overall 0

tree

Another and possibly more gratifying way to see a recently produced directory structure is to use the tree command that shows the structure of a complex directory in an extremely easy to comprehend way like this:

$ tree newdir ├ ─ ─ 1 │ ├ ─ ─ docs │ └ ─ ─ scripts ├ ─ ─ 2 │ ├ ─ ─ docs │ └ ─ ─ scripts └ ─ ─ 3 ├ ─ ─ docs └ ─ ─ scripts 9 directories, 0 files

Once you add files to your new directory sites, the tree command will show those too.

$ tree newdir/1 newdir/1 ├ ─ ─ docs │ └ ─ ─ notes newdir/1/docs/ notes$ls-l newdir/1/docs/ notes-rw-r– r–. 1

shs shs 0 Dec

29 11:43 newdir/1/docs/ notes … Source

Leave a Reply

Your email address will not be published. Required fields are marked *