How to enter a directory with the 'cd' command if it has 700 permission and is not owned by me?
Solution 1:
sudo cd
won't work because the cd
command is built into the shell. So you are saying become root and then run this command. You become root and then the command after sudo is searched for but there is no cd
command to find.
The method to use is to switch to the user that owns the directory. Permission 700
is meant as "owner can read, write and execute".
So if root owns the directory sudo -i
, password and then cd {dir}
is the only correct method. If someone else owns the directory you can still use the 1st method but can also change to that user with su {username}
and then use cd
as that user.
Solution 2:
sudo -i
to open "root console" and then
cd /path/to/directory
(cd
is a shell builtin command, so it can't be the sudo target)
Solution 3:
To open a root directory we may run a root shell, e.g.:
sudo su
# cd /root
Solution 4:
As others pointed out -- it's shell built-in:
~ % which cd
cd: shell built-in command
So, why don't you sudo the shell itself?
~ % sudo $SHELL -c "cd name_of_dir"