Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm running Ubuntu 10.04 and am having issues getting to the log files in /var/log/apache2

I can cd to most other places (I haven't tried every single file, obviously) but when I try to get to the above directory, I get the error message sudo: cd: command not found

... I've just tried something else and I can't cd when used in conjunction with sudo. I can use sudo when doing things like apt-get but it seems I can't change directory when using sudo.

I haven't been on this server for a while but I know I used to be able to do this.

share|improve this question
up vote 6 down vote accepted

On most systems, cd isn't a program, it's a shell command, so you can't use sudo to run it. Try sudo -i to get an interactive shell then cd into that directory.

share|improve this answer
That's not 100% true - on some systems there is a cd in /usr/bin as well as the shell built-in, and that's what sudo will invoke. However, even when that's true, it won't do you any good because once the sudo command finishes and exits you're back at the directory you started at. – Paul Tomblin Dec 31 '10 at 14:34
That would explain it. Thanks. – Piers Karsenbarg Dec 31 '10 at 14:37
How would a /usr/bin/cd command function? Doesn't the "it won't do you any good" part apply even without sudo? – mattdm Dec 31 '10 at 15:17
Hah! Learn something new every day. @mattdm: Apparently systems with a cd program have it so that scripts can test if you can change into a directory or not (by checking its return value for errors)… – DerfK Dec 31 '10 at 17:05

Supplemental to DerfK's answer;

Before I discovered sudo -i, I'd use sudo ls /var/log/abcd to identify the files in such a directory, and then read the files more directly.

Not the cleanest way,... but there's always more than one way to skin a cat..

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.