How to touch a file and mkdir if needed in one line

前端 未结 8 996
抹茶落季
抹茶落季 2021-02-18 14:38

I need to touch a file with an absolute file name such as: /opt/test/test.txt, but I\'m not sure if there is /opt/test existed on the system. So the code should similar with thi

8条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-02-18 14:59

    Bring Python to command line.

    i.e. Use pyp

     cat filepaths.txt | pyp "'mkdir -p '+s[0:-1]|s+'; touch '+o" | sh
    

    The Pyed Piper", or pyp, is a linux command line text manipulation tool similar to awk or sed, but which uses standard python string and list methods as well as custom functions evolved to generate fast results in an intense production environment.

提交回复
热议问题