LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   single command for creating file and setting permission to it. (https://www.linuxquestions.org/questions/linux-newbie-8/single-command-for-creating-file-and-setting-permission-to-it-4175608629/)

Ankit yadav 06-26-2017 06:03 AM

single command for creating file and setting permission to it.
 
Hi All,

I want to know is there is any command which let me create file and set to some permission(other than default).

Like we can do with directories with command
mkdir -m 777 testdir

Some where I found "install" command. But again i successfully able to create directory from it, not file.

Is there is any way to do it. Or we should follow touch file;chmod 777 file command itself.

Thanks in Advance. :)

Jjanel 06-26-2017 06:44 AM

No 'single command'. EDIT: corrected to Yes, in post#5 below; see man install
Have a study of: man creat
There's always umask: https://unix.stackexchange.com/quest...-touch-command
Oh, maybe visit my favorite command: strace ;) Enjoy your Linux!

Shadow_7 06-26-2017 06:50 AM

It depends on how you define "single command". You can string several commands into one "script", and run the script as a single command. But caveats, as when you lose the script you might not remember the commands. And if you're on someone else's system, they wont have your script.

BW-userx 06-26-2017 07:04 AM

correct it is more done in steps, first create, then change permissions two commands one line

Code:

$⚡ ~ ⚡> touch changePermissionsOnMe ; chmod 777 changePermissionsOnMe

Jjanel 06-26-2017 07:59 AM

A *single* command!
 
Oh: ooops: I found this (/dev/null 'trick' to make install 'work'):
https://unix.stackexchange.com/quest...e-command-line

Code:

install -m 7666 /dev/null MYrwSrwSrwT
ls -l !$ ; echo hi > !$ ; ls -l !$ #echo stole my Suid;Idk WHY?

is devilishly BWeatiful:D Thanks OP, for getting me to learn install;)

p.s. Got milkstdin?: echo hi | install -m 7666 /dev/stdin MYrwSrwSrwT

Ankit yadav 06-27-2017 02:09 AM

Thanks Jjanel

Its worked $install -m 755 /dev/null newfile


All times are GMT -5. The time now is 03:50 PM.