Unix - create path of folders and file

后端 未结 11 2074
面向向阳花
面向向阳花 2020-12-22 18:20

I know you can do mkdir to create a directory and touch to create a file, but is there no way to do both operations in one go?

i.e. if I wa

11条回答
  •  臣服心动
    2020-12-22 19:12

    if you want simple with only 1 param snippet :

    rm -rf /abs/path/to/file;  #prevent cases when old file was a folder
    mkdir -p /abs/path/to/file; #make it fist as a dir
    rm -rf /abs/path/to/file; #remove the leaf of the dir preserving parents 
    touch /abs/path/to/file; #create the actual file
    

提交回复
热议问题