0

I need to draw the tree structure of the following code.

cd /; mkdir a b c a/a b/a; cd a; mkdir ../e ../a/f ../b/a/g; cd../b/./; mkdir /a/k a/b ../a/./b /c

I know that: cd /; (goes to root) , mkdir creates directories a b c but I can't understand the rest of the line.

Any thoughts would be really helpful.

2

2 Answers 2

1

This is written in a confusing manner and I'm assuming comes from a basic linux/unix test. I can explain. It will seem clearer if it is on multiple lines. The ; char means end of a command. The mkdir command can do multiple things with one execution.

cd /

You will be in / as your current working directory.

mkdir a b c a/a b/a

Creates directories relative to your cwd: /a, /b, /c, /a/a, /b/a

cd a

Your cwd becomes /a

mkdir ../e ../a/f ../b/a/g

Creates directories relative to current location. The .. means to go up one. Above your cwd of /a is / so you create /e, then /a/f, then /b/a/g dirs.

cd ../b/./

While .. means parent directory, . means this directory. So, from /a you would go up one (..) then into /b, then stay where you are (.).

A trailing / after a directory name means only that it is a directory and is optional.

mkdir /a/k a/b ../a/./b /c

Again this needs to be broken up since it is obviously written to be confusing. Creates /a/k, since the leading / means an absolute path, then /b/a/b since you are already in /b and it is relative (does not start with /). Next is /a/b since you are already in /b and the . does nothing. Then it will try to create /c but this already exists.

I would suggest working through this yourself on a command line and see if it makes sense.

1

tree can visualize what you want, though your command will error as terdon pointed out. You'll need it to say cd ../b/./;

If you install tree, run your command, and run tree on your directories under / you'll see the full directory tree you've created.

[root@host /]# tree -a a
a
|-- a
|-- b
|-- f
`-- k

4 directories, 0 files
[root@host /]# tree -a b 
b
`-- a
    |-- b
    `-- g

3 directories, 0 files
[root@host /]# tree -a c
c

0 directories, 0 files
[root@host /]# tree -a e
e

0 directories, 0 files

Not the answer you're looking for? Browse other questions tagged .