Linux Ask!

Linux Ask! is a Q & A web site specific for Linux related questions. Questions are collected, answered and audited by experienced Linux users.

Permission denied when redirection with sudo

Answer:

When you are doing redirection with sudo, such as the following command

# sudo echo 1 > /proc/sys/vm/drop_caches

-bash: /proc/sys/vm/drop_caches: Permission denied

You will get permission denied as the redirection will be performed as the user calling sudo, not as the superuser. So if you don't have permission to write to the target file, you will get permission denied.

To solve the problem, use the following method

sudo sh -c 'echo 1 > /proc/sys/vm/drop_caches'

  1. How to simulate login as root using sudo command
  2. How to clear cache from memory in Linux?
  3. Reduce the chance of using swap if you have enough memory
  4. How to combine the output of multiple commands into a single file?
  5. How to redirect output to a file

Leave a Reply

(required)

(required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>