Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 231493
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:56:15+00:00 2026-05-11T19:56:15+00:00

I have a script which is running as root, it’s supposed to store it’s

  • 0

I have a script which is running as root, it’s supposed to store it’s cache file (only modified by the script) at /var/lib/varlibfile. However the script does not seem to create the file, and my investigation led me to this:

$ sudo echo "something" >/var/lib/varlibfile
bash: /var/lib/varlibfile: Permission denied
$ sudo echo "something" >varlibfile
$ sudo cp varlibfile /var/lib/

In other words, I am able to create a file called varlibfile at /var/lib, but I’m not allowed to create it using redirection. Only file copy works. It seems very strange to me and I would like to use redirection directly to the intended file instead of creating it somewhere else and then copying it.

Some extra information:

$ ls -ld /var
drwxr-xr-x 14 root root 4096 2009-03-02 14:47 /var
$ ls -ld /var/lib
drwxr-xr-x 51 root root 4096 2009-05-16 19:25 /var/lib
$ ls -la /var/lib/ | head
total 204
drwxr-xr-x  51 root          root          4096 2009-05-16 19:25 .
drwxr-xr-x  14 root          root          4096 2009-03-02 14:47 ..
drwxr-xr-x   2 root          root          4096 2009-03-02 14:22 acpi-support
drwxr-xr-x   2 root          root          4096 2009-03-02 14:39 alsa
drwxr-xr-x   2 root          root          4096 2009-05-14 14:42 apparmor
drwxr-xr-x   6 root          root          4096 2009-05-14 14:42 apt
drwxr-xr-x   2 root          root          4096 2008-04-04 11:56 aptitude
drwxr-xr-x   2 root          root          4096 2008-07-02 12:58 aspell
drwxr-xr-x   2 avahi-autoipd avahi-autoipd 4096 2009-03-05 16:42 avahi-autoipd

Can anyone explain why this is happening? And how to solve the problem, ideally I want to write /var/lib/varfile directly without any previous creation at another location.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T19:56:15+00:00Added an answer on May 11, 2026 at 7:56 pm

    What

    $ sudo echo something >/var/lib/varlibfile
    

    does, is pipe the output of “sudo echo something” to the file. So the file write operation is done as the current user, who doesn’t have permission to write in /var/lib.

    Try something like

    $ sudo sh -c "echo something >/var/lib/varlibfile"  
    

    or

    $ echo something | sudo tee /var/lib/varlibfile
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a script which contacts a few sources and tell them the IP-address
I have a script which logs on to a remote server and tries to
I have a script which will be run interactively by non-technical users. The script
I have a shell script which copies a few files to the current directory,
I have a php script which accesses a MSSQL2005 database, reads some data from
I have a lingo script which runs some data processing for a Flash movie.
I have a simple script which is used to start another program. This other
I have a cgi script which takes form input, I want to facilitate the
I have a PHP script which executes a shell command: $handle = popen('python last',
I have this .bat script which I use to maven package my application. Problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.