-1

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?

1 Answers1

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