One command to create a directory and file inside it linux command

前端 未结 9 1246
無奈伤痛
無奈伤痛 2020-12-24 12:39

Suppose my current directory is A. I want to create a directory B and a file \"myfile.txt\" inside B.

How to do th

9条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-24 13:09

    You could create a function that parses argument with sed;

    atouch() {
      mkdir -p $(sed 's/\(.*\)\/.*/\1/' <<< $1) && touch $1
    }
    

    and then, execute it with one argument:

    atouch B/C/D/myfile.txt
    

提交回复
热议问题