Single command to create a file and set its permission

后端 未结 8 1273
北恋
北恋 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:29

    For bash, simply use chmod with file redirection and history expansion:

    chmod 777 filename.txt>>!#:2
    

    For ksh and zsh you have to drop the history expansion (as shown above, there may be other ways) and use:

    chmod 644 filename>>filename
    

    For scripts of any shell you don't have (and really don't need) history expansion so use the above there as well.

提交回复
热议问题