Single command to create a file and set its permission

后端 未结 8 1168
北恋
北恋 2021-01-31 08:23

I am using the following 2 commands to create a 0B file and set its extn to 644

touch filename.ext
chmod 777 filename.txt

My question is that w

8条回答
  •  梦谈多话
    2021-01-31 08:49

    If you want to create the file not just empty but with content and mode at the same time you can use process substitution with install in bash:

    install -m 755 <(echo commands go here) newscript
    

    <() places the output into a temporary file (Process-Substitution)

提交回复
热议问题