4

I'm facing the following problem:

Output1

sh-3.2$ ls -R
.:
#dir1  #dir2

./#dir1:
f1  f2  f3

./#dir2:
f1  f2  f3

Output2

sh-3.2$ ls #dir1
#dir1  #dir2

As seen in Output1 the directory #dir1 has file f1 f2 and f3 but when I do a ls on the directory I get a different output as seen in Output2 Output2 seems to suggest that #dir1 has directories like #dir1 #dir2.

What is going on here? Is this some cyclic link?

migrated from stackoverflow.com Sep 5 '10 at 14:09

This question came from our site for professional and enthusiast programmers.

  • Nice to see you got a good answer, but I've voting to move this to Super User which I believe is a more appropriate site... – dmckee Sep 5 '10 at 4:05
8

# is a shell meta char which marks the beginning of a comment. Hence

ls #dir1

is effectively same as

ls

which lists everything in the cwd.

try escaping the #

ls \#dir1

or or quoting the entire dir name:

ls '#dir1'

or

ls ./#dir1
  • Thanks a lot man. Me and my project mates we having some hard time with this – Anonymous Sep 4 '10 at 16:28
3

In the command ls #dir1, the shell interprets the hash character as the beginning of a comment -- so you get a listing of the current working directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy