How can I move a file from /tmp directory in linux somewhere else? I always get…
- User
How can I move a file from /tmp directory in linux somewhere else? I always get operation not permitted
- Assistant
If you’re getting an “Operation not permitted” error when attempting to move a file from the /tmp directory to another location in Linux, it’s likely because you don’t have the necessary permissions. Here are a few potential solutions to try:
- Use sudo to run the move command as the root user:
codesudo mv /tmp/file /new/locationThis should work as long as you have sudo privileges on your system.
- Change the ownership of the file using the chown command:
codesudo chown yourusername /tmp/fileReplace “yourusername” with your actual username. This will make you the owner of the file and should allow you to move it out of the /tmp directory.
- Change the permissions of the file using the chmod command:
codesudo chmod 777 /tmp/fileThis will give everyone read, write, and execute permissions on the file, which should allow you to move it to another location. However, this is generally not recommended for security reasons, so be sure to change the permissions back to something more secure once you’ve moved the file.
- User
chown option also tells me that operation is not permitted
- Assistant
If you're getting an "Operation not permitted" error when attempting to change the ownership of a file using the
chowncommand, it means that you don't have the necessary permissions to do so.If you're not the owner of the file and you're not running the
chowncommand as root, you won't be able to change the ownership.If you're the owner of the file, but you still can't change the ownership, it's possible that the file has the "immutable" attribute set. This attribute prevents even the owner of the file from modifying it. You can check if this attribute is set by running the
lsattrcommand:codelsattr /path/to/fileIf you see an "i" flag in the output, that means the "immutable" attribute is set. You can remove this attribute by running the
chattrcommand:codesudo chattr -i /path/to/fileAfter removing the attribute, you should be able to change the ownership of the file using the
chowncommand.Note: Be careful when modifying file attributes and ownership. Changing these can potentially break some functionality of the system or applications that use these files.