Posts Tagged ‘cd’

cd into, or make a directory beginning with a leading “-”

Saturday, April 12th, 2008

Having ZFS and SAMBA on the home machine is great. It was simple to set up a share and offer it out to my house mates for them to backup their dissertation work on. With ZFS compressing the files, some of my file systems are getting a 1.6x ratio (60% disk space for free compared with a non-compressing file system)

The interesting bit comes with file permissions and Windows file attributes which aren’t quite the same, in fact, not at all. The attributes get mapped onto the unix file permissions in an interesting way, and you’ll need to keep that in mind when ls -l ing around a shared directory.

Meanwhile, there was a directory named “—-FILES—-” on the share. Trying to use

cd "----FILES----"

doesn’t quite work! Despite quoting the directory name, cd still tries to take some of those dashes as a switch. I’m not sure if theres a way around this using the relative path, but there is a different workaround: simply use the absolute path, instead of a relative one to get you there, eg:

cd /mydir/----FILES..../

To make a directory with leading dashes, you’ll need to specify the full pathname, or use something like this to make the process less painful:

mkdir `pwd`/--mydir--

cd needs execute permissions to work?!

Sunday, March 9th, 2008

You need execute permission on a directory to cd to it! Is read not enough? In practice, no. The chdir system call requires execute permission to make that directory the starting point for path searches. According to the chdir (system call, section 2) man page:

For a directory to become the current directory, a process
must have execute (search) access to the directory.

So when trussing the output of a failed cd to a directory with no execute permissions we see:

chdir("lala") Err#13 EACCES [file_dac_search]
chdir(”lala”) Err#13 EACCES [file_dac_search]

and as the man page goes on to say:

EACCES Search permission is denied for any com-
ponent of the path name.

Reading this article explains, that of course you can’t execute a directory but rather, that the execute permission bit is reused for different purposes. Without execute permission on the directory, you can’t stat() any files within the directory. Opening, deleting and other operations on a file first require you to stat() it first, as stat() gives you the files inode. Without the files inode, theres very little you can do with it!

Armed with this knowledge you might feel inspired to check out the source code of this call for yourself!