-7

I have been given an homework assignment for Linux that reads:

Create a tree of files as shown in the image in the user home directory(用户主目录), listing all the commands that complete the process.

enter image description here

My issue is that I don't know what command(s) I should be using to do this. Any help would be appreciated.

  • 2
    Hint: mkdir -p /path/to/directory creates all the intermediate directories, so you only need to issue a command for the "leaf" directories. – xenoid Dec 15 '19 at 9:39
1

A single directory can be created using the mkdir command on the command line. For example:

mkdir private

This would create the directory private in the current directory.

Your exercise asks for a series of commands that creates the show directory structure, so this would be a series of mkdir commands.

There are basically two ways you could solve this assignment:

  1. Move to your home directory (with cd), and then create each directory that is needed there. Then cd into one of them and create each directory that is needed there etc., or

  2. Move to you home directory, then use mkdir -p with the paths of the bottom-most directories only. The -p option to the mkdir command would create the directory at the end of the specified path, but would also create any intermediate directories if they are missing. For example:

    mkdir -p private/homework private/lab
    

    would create both the private directory and the homework and lab subdirectories beneath it.

See also the output of man mkdir on you system.

1

A tree of files should be a directory structure.

Then there is one detail: to use parens to not get lost.

mkdir private public temp
(cd private; mkdir lab ...)
(cd public; mkdir music book ...)

(cd public/book; mkdir java c++ Pascal)

This imitates the way you would do it interactively, with cd .. maybe to return to the higher level.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.