Single command to create a file and set its permission

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

    Because of Docker and Alpine, I imagine there are a lot of people interested in creating executable one-liners without the help of bash-isms. It's pretty simple with install

    $ docker build -t temp - < d6e46aa2470d
    Step 2/3 : RUN echo "date" | install -m 775 /dev/stdin /bin/now
     ---> Running in 95919b575638
    Removing intermediate container 95919b575638
     ---> cd1fafd96ef3
    Step 3/3 : CMD /bin/now
     ---> Running in 03b5c3ac7265
    Removing intermediate container 03b5c3ac7265
     ---> 8f30b527dd29
    Successfully built 8f30b527dd29
    Successfully tagged temp:latest
    
    $ docker run --rm temp
    Thu Nov 12 07:44:24 UTC 2020
    
    $ docker run --rm temp ls -la /bin/now
    -rwxrwxr-x    1 root     root             5 Nov 12 07:44 /bin/now
    
    $ docker rmi temp
    Untagged: temp:latest
    Deleted: sha256:8f30b527dd29203b67c86290b34b0a29d3c98a48134609d0b1e2b89087a7d6e7
    Deleted: sha256:cd1fafd96ef3084226c5f98f472e3e08bc9a9f0448cc3e68b6f1c192d12d778a
    Deleted: sha256:e58c75acbf953a64d35089cf50e1c5b762601e1cb9d9d1d668e135f23ce1fe86
    

提交回复
热议问题