Unix - create path of folders and file

后端 未结 11 2013
面向向阳花
面向向阳花 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:03

    as I saw and test in a unix forum this solves the problem

    ptouch() {
        for p in "$@"; do
            _dir="$(dirname -- "$p")"
            [ -d "$_dir" ] || mkdir -p -- "$_dir"
        touch -- "$p"
        done
    }
    

提交回复
热议问题