Announcement

Collapse
No announcement yet.

[solved] Creating a file as root

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    [solved] Creating a file as root

    I give up. How do I get this to work:

    sudo echo "Line of text" > /etc/directory-where-I-dont-have-write-permission/filename

    The idea is to have a shell script run as sudo create the file filename with the contents Line of text in a directory that requires root permission to write. By itself, this line does not work, as the sudo doesn't span the redirect.
    We only have to look at ourselves to see how intelligent life might develop into something we wouldn't want to meet. -- Stephen Hawking

    #2
    Re: Creating a file as root

    to create you need to use touch
    Once your problem is solved please mark the topic of the first post as SOLVED so others know and can benefit from your experience! / FAQ

    Comment


      #3
      Re: Creating a file as root

      Yeah, I thought it was something simple.

      ....
      sudo touch /etc/dir/filename
      sudo echo "This works" > /etc/dir/filename
      ....

      Thanks.
      We only have to look at ourselves to see how intelligent life might develop into something we wouldn't want to meet. -- Stephen Hawking

      Comment


        #4
        Re: Creating a file as root

        Code:
        $ sudo su -c echo "This is a test"/etc/thisisatest.txt
        [sudo] password for jerry: 
        Unknown id: This is a test/etc/thisisatest.txt
        $ sudo su -c echo "This is a test" > /etc/thisisatest.txt
        bash: /etc/thisisatest.txt: Permission denied
        $ sudo su -
        # echo "this is a test" > /etc/thisisatest.txt
        # cat /etc/thisisatest.txt
        this is a test
        #
        "A nation that is afraid to let its people judge the truth and falsehood in an open market is a nation that is afraid of its people.”
        – John F. Kennedy, February 26, 1962.

        Comment

        Working...
        X