How can I create a file with executable permission itself? I want to create a new file with a single command with executable permissions how can I do it?
Asked
Active
Viewed 1,790 times
-1
1 Answers
0
The best practice to create a new file with executable permissions is touch newfile
then chmod +x myfile
.
If your works require a lot of doing this task, I suggest using alias to work more efficiently. Because Bash alias doesn't directly accept parameters, so you need to do a simple trick like that:
_xnew() { touch "$1" && chmod +x "$1"; }
alias xnew='_xnew'
To use it, you just need to type xnew myfile
in your terminal:
$ user@host: xnew myfile
$ user@host: ls
-rw-r--r-- 1 user user 400 Nov 10 08:00 myfile

ne3suszr
- 13
touch
thenchmod
– glenn jackman Nov 10 '19 at 14:02