ls unexpectedly listing subdirectory contents at /usr/bin
1. ave a number of i586-mingw32msvc-* files in my /usr/bin directory.
2. I moved them to a subdirectory named i586-mingw32msvc.
3. Now if I do ls i5* under /usr/bin, I get the contents of the
i586-mingw32msvc subdirectory -- how is this?
If I move only some of the i5* files to the subdirectory, I get:
On 2/26/06, Shriramana Sharma
1. ave a number of i586-mingw32msvc-* files in my /usr/bin directory. 2. I moved them to a subdirectory named i586-mingw32msvc. 3. Now if I do ls i5* under /usr/bin, I get the contents of the i586-mingw32msvc subdirectory -- how is this?
If I move only some of the i5* files to the subdirectory, I get:
i586-mingw32msvc: . .. I have not seen ls commands in other directories automatically listing subdirectory contents unless specifically told to do so. Why does /usr/bin alone behave this way?
Shriramana, this is normal. ls expands wildcards for files and subdirectories. Look at this: kenji:/opt # ls . gnome kde3 mtest.c snavigator .. insight mono-1.1.8.3 netbeans-4.1 MozillaFirefox jdk1.5.0_04 mozilla novell kenji:/opt # ls m* mtest.c mono-1.1.8.3: . MonoDoc.desktop bin lib .. Release Notes.desktop etc share Mono Project WebSite.desktop Start Here.desktop html uninstall MonoDevelop.desktop Uninstall.desktop include mozilla: . .. bin include installed-chrome.d lib share My /opt directory contains two subdirectories and a file starting with m. "ls m*" causes both to be listed: the contents of the subdirs and the file. \Steve
Shriramana, On Saturday 25 February 2006 23:54, Shriramana Sharma wrote:
...
I have not seen ls commands in other directories automatically listing subdirectory contents unless specifically told to do so. Why does /usr/bin alone behave this way?
Surely you don't believe there's some kind of special case in ls or some other code for /usr/bin? In fact, there is not. You have to understand how things work (shocking, isn't it?) in order to predict their behavior. When unquoted and unescaped wild-cards (*, ? and [...]) are present in a command submitted to the shell, the first thing that happens is that those wild cards are expanded. (Options determine whether or not it's an error for nothing to match one or more of the patterns given.) Once this expansion has produced the final argument list, the command is invoked, passing those arguments to it. Now in the case of ls (and when the "-d" option is not given), any argument that names a directory is taken as a request to list that directories _contents_, not the directory itself. The -d option tells ls to list any directories given as arguments instead of their contents. There. Now you have enough information to explain what you're seeing. No magic, no special cases for /usr/bin and something that's explained in countless Web pages and books... Randall Schulz
participants (3)
-
Randall R Schulz
-
Shriramana Sharma
-
Steve Graegert