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 whether there is any single command in unix (korn shell) that will do the two things together that is to say create a 0B fil with desired permission?
To change file and directory permissions, use the command chmod (change mode). The owner of a file can change the permissions for user ( u ), group ( g ), or others ( o ) by adding ( + ) or subtracting ( - ) the read, write, and execute permissions.
Setting 777 permissions to a file or directory means that it will be readable, writable and executable by all users and may pose a huge security risk.
install -m 777 /dev/null filename.txt
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With