Unix ls command question

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions Unix ls command question
# 1  
Old 09-08-2011
Unix ls command question

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.

Any other possible hints?

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

San Jose State University, San Jose, USA, Allen, CS49c
# 2  
Old 09-08-2011
I guess you could have an empty script named "ls" in that directory. However, you would need to have "." in your PATH, which is never recommended, for this very reason.
# 3  
Old 09-08-2011
So then is this problem assuming that there is a './' in the path? Because, as you mentioned, that is the only way it would work. are there any other ways this could work with out having './' in the path?

Thank you for the reply btw
# 4  
Old 01-30-2012
The only other thing I can think of is the "du" command

du (Unix) - Wikipedia, the free encyclopedia
# 5  
Old 01-30-2012
To test the path theory, try specifying the full path to "ls".
Code:
/usr/bin/ls
/usr/bin/ls -a

Also check whether "ls" has been aliased to a clever script which makes "ls" appear faulty sometimes.
Code:
alias | grep "ls"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

UNIX command question

Hi Guys, I am new on the scripting world and would like ask for help if you can. Here are my questions below:- What Unix command(s) would you put in a shell script to read an ASCII comma-delimited input file and validate that field 5 only contains numeric characters? What Unix command(s)... (5 Replies)
Discussion started by: mahiwaga
5 Replies

2. UNIX for Dummies Questions & Answers

New to Unix command line and have a question about the "sort" command

I am going through the Unix Made Easy second edition book by John Muster. So far it's been very informative and I can tell it may be a bit out of date. In one of the exercises it talks about the "sort" command and using it to sort column's of data etc. The "sort" command has changed a bit and... (1 Reply)
Discussion started by: budfoxcat
1 Replies

3. UNIX for Dummies Questions & Answers

Unix command line question

I'm new to Unix and I'm looking for some assistance. We have 20 different accounts we must login to every day. Logging in has become quite the chore and most nights, we have to log out. I'm looking for a way to simply copy and paste the commands into each window to make things easier. I have been... (2 Replies)
Discussion started by: Judo_Bear
2 Replies

4. Shell Programming and Scripting

question about wc command in Unix

Hi all I want to give a command which outputs the number of files have name ending in .pdf(output is just number). Can somebody help me (3 Replies)
Discussion started by: thungmail
3 Replies

5. HP-UX

Question about UNIX ioscan command

Hello there. I have a question regarding the ioscan commnad. When you execute the line ioscan -fnC processor it outputs a list of all processors in the machine. Does this list displays only physical CPUs or does it displays each core? For example, if i have a server with 1 Dual Core... (10 Replies)
Discussion started by: Spilson
10 Replies

6. UNIX for Dummies Questions & Answers

Unix command question

I recently went in for a job interview and the guy asked me what I knew about Unix. I told him not much since I haven't worked with it in a few years. He then asked me the following question: What Unix or Linux shell command will tell you the names of all files in the current directory, along... (2 Replies)
Discussion started by: BMWBigD
2 Replies

7. UNIX for Dummies Questions & Answers

Unix History Question: Why are filenames/dirnames case sentsitive in Unix?

I tried looking for the answer online and came up with only a few semi-answers as to why file and directory names are case sensitive in Unix. Right off the bat, I'll say this doesn't bother me. But I run into tons of Windows and OpenVMS admins in my day job who go batty when they have to deal... (3 Replies)
Discussion started by: deckard
3 Replies

8. UNIX for Dummies Questions & Answers

Question about DOS versus Unix Command?

Okay here is a DOS comparison. When I search for a file in DOS and I was not sure what directory it was in then I would put dir /s/o/p filename the s would tell it to look in every directory including subs, the o would sort it alphabetically and the p would limit the display to one page at a... (1 Reply)
Discussion started by: wmosley2
1 Replies

9. Shell Programming and Scripting

Question about a unix command...

hi all, got a question about grep, ive written a script (Bourne) and i'm using grep -i to search for a file and return the records that i'm looking for. This all works fine, but, i was wondering how i can get an error message if that word isn't in the file. E.G. the user enters: tree and if... (2 Replies)
Discussion started by: wazzag
2 Replies

10. IP Networking

unix to unix serial connection question

hi there i'm a new bie just got few simple questions to ask. I got expert in windows configuration but totally new to unix environment . I want to make sure a com port (com1) is working, so I connect a 9-pin cable (CB9) for both PC using Unix environment (unix to unix). The question are (1)... (1 Reply)
Discussion started by: typsam
1 Replies
Login or Register to Ask a Question