Whenever I try cd folder_name/ in bash on any directory it gives this error:

-bash: cd: folder_name/: Permission denied

Execution permissions are given to all folders so that doesn't seem to be the problem. E.g. running stat on Desktop/ outputs:

  File: 'Desktop/'
  Size: 4096        Blocks: 8          IO Block: 4096   directory
Device: 807h/2055d  Inode: 13107232    Links: 2
Access: (0755/drwxr-xr-x)  Uid: ( 1000/caffeine)   Gid: ( 1000/caffeine)
Access: 2017-12-07 14:39:42.715820915 +0500
Modify: 2017-12-06 01:16:13.985722935 +0500
Change: 2017-12-06 01:16:13.985722935 +0500
 Birth: -

Some other possibly relevant information:

  1. I can read or write files in any directory without any issue.
  2. mkdir executes normally but I can't cd into the new folder.
  3. rmdir executes normally.
  4. I can open a terminal in a particular folder by navigating to that folder and opening a terminal from it.

So can anyone tell what the problem can be?

Thanks in advance.

EDIT: type -a cd shows the following output:

cd is a function
cd () 
    echo "-bash: cd: $1: Permission denied"
cd is a shell builtin
  • 6
    Add the output of type -a cd to your post, please.
    – muru
    Dec 8, 2017 at 6:50
  • 3
    So, who do you know who would play a practical joke on you like that?
    – John1024
    Dec 8, 2017 at 7:03
  • 2
    hahahahahaha, the friends we keep these days :-) Dec 8, 2017 at 7:05
  • 5
    Run unset cd and things should work. Next, run grep 'Permission denied' ~/.bashrc ~/.bash_profile ~/.profile and report what you find.
    – John1024
    Dec 8, 2017 at 7:06
  • 2
    @AwaisChishti you will need to find where that cd function is set else it will repeat Dec 8, 2017 at 7:36

1 Answer 1


You probably where the victim of a prank, possibly done by your coworkers or someone who had access to your machine.

Bash functions can shadow the original shell built-in commands as you could see as you did type -a cd. It has shown you that it first found a function which is possibly declared somewhere.

cd is a function
cd () 
    echo "-bash: cd: $1: Permission denied"
cd is a shell builtin

From this output you can see that somewhere someone declared a shell function called cd which shadows now the shell built-in command cd. In some cases something like this might be useful to make commands more versatile or implement extra functionality, but in this case it was been done with ill intend (my guess). This could have been done in several places on the system:

  • /etc/bash.bashrc
  • /etc/profile
  • any file in /etc/profile.d/
  • /etc/environment
  • ~/.bashrc
  • ~/.profile
  • ~/.bash_aliases
  • any other file which gets executed or sourced from those files

One possible way to find this maybe is doing a recursive grep search in /etc/ and in /home/:

grep -r 'bash: cd: $1: Permission denied' /home/*
sudo grep -r 'bash: cd: $1: Permission denied' /etc/*

Which might yield an output like that:

$ grep -r 'bash: cd: $1: Permission denied' /home/*
/home/videonauth/.bashrc:    echo "-bash: cd: $1: Permission denied"

In this example the line or function seems to be in ~/.bashrc which you can see by the path leading the grep output. Depending how sufficient the whole thing is hidden this might or might not yield a result. There are other ways to hide such a function declaration which may not be so easy to find.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .