2 Replies - 1764 Views - Last Post: 08 September 2011 - 10:26 AM Rate Topic: -----

#1 TheRaiderNation  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 81
  • Joined: 11-January 10

UNIX ls command help

Posted 07 September 2011 - 10:29 PM

There was a question that I have been asked, I won't lie it is from homework, regrading the ls, list, command and I am hopelessly lost and just can't seem to figure it out. Here is question:

Summarized Question
There is something about the naming of the files in a directory that cause ls, including ls . and ls -a, not to work when in the directory, however if you do an ls of the directory from somewhere else the files show up.

Example, the current directory is /usr/local/etc/fred/
If I ls, ls ., ls -a nothing shows up
However if I cd to, say for example, /usr/local/ (Or any other directory for that matter
and do an ls /usr/local/etc/fred/ the files are listed.

Full Question

Quote

One day, as you’re pondering an assignment for CS49C, your housemate notices the following remarkable thing and asks you about it: there’s a directory whose files he can list with the ls command, but only from outside the directory. You investigate, and you discover that the ls command – when run without arguments – seems to work fine when the default directory is anything other than the directory your housemate pointed out (which happens to be /usr/local/etc/fred). But your housemate is correct: executing ls when the default directory is /usr/local/etc/fred just gives you back the command prompt. You’re almost ready to believe the directory is simply empty, but your housemate insists this isn’t some lame joke.

For completeness, you try ls –a, but that seems to have no effect. In fact, even the default . and .. files are not visible. Finally, you do what your housemate has been asking you to do all along, and you cd to a different directory and then do an ls of /usr/local/etc/fred. To your amazement, you discover there are files in the directory. It is indeed as though the files had been made truly invisible, but only from within that single directory. And when you look over the names of the files more closely, you suddenly understand what your housemate has done to produce this bizarre behavior. What has happened?

Hint: it’s not a permissions issue, and it’s classic Unix.


As was stated at the end of the original question, it is not a permissions issue, so that rules that out. Also the fact that ls -a didn't work even while in the directory rules out that the files are hidden by starting with a dot. I feel as if it has something to do with the way files are named, but can't figure out just how they are named.

Note: This question is meant to be present in csh, if that makes a difference from what would happen in bash

This post has been edited by TheRaiderNation: 07 September 2011 - 10:33 PM


Is This A Good Question/Topic? 0
  • +

Replies To: UNIX ls command help

#2 sepp2k  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2013
  • View blog
  • Posts: 3,039
  • Joined: 21-June 11

Re: UNIX ls command help

Posted 08 September 2011 - 01:16 AM

The first explanation I could come up with is that the $PATH contains the current directory (i.e. .) before /bin (or wherever the real ls resides), and fred (or someone evil hacker who got into fred's account) created an ls executable in /usr/local/etc/fred.
Was This Post Helpful? 1
  • +
  • -

#3 TheRaiderNation  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 81
  • Joined: 11-January 10

Re: UNIX ls command help

Posted 08 September 2011 - 10:26 AM

View Postsepp2k, on 08 September 2011 - 02:16 AM, said:

The first explanation I could come up with is that the $PATH contains the current directory (i.e. .) before /bin (or wherever the real ls resides), and fred (or someone evil hacker who got into fred's account) created an ls executable in /usr/local/etc/fred.


Thank you for the reply, someone from another forum mentioned the same thing, and I think it is the most probable scenario.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1