Paul.L.Snyder on 7 May 2004 19:57:02 -0000 |
"Douglas Lentz" <dlentz@dca.net> wrote on 05/07/2004 02:15:07 PM: > Aaron Mulder wrote: > > When you do ls /etc/ssh* you're getting the contents in > >/etc/ssh/, so the file you're looking for is /etc/ssh/ssh_host_key. If > >you ran "ls -d /etc/ssh*" you'd see that it's a directory you're hitting. > > Thanks. This is my fault, for not running "info ls" and assuming that ls > is just like the old MS-DOS dir. There are actually a couple of differences going on, here. One is in the way 'ls' behaves, the other is in the way the shell (that is, bash) deals with wildcards like '*' - in UNIX circles these are often called "globs", and the process of matching files with a glob is called "globbing". Here's some relatively detailed information for anyone not so familiar with the way that Linux does business when you type a command, and who is interested in digging a little deeper. In DOS & in the Windows command interpreter, what you type after the 'dir' (such as the *.txt in "dir *.txt") is passed directly to the 'dir' command, which then deals with the process of figuring out what files are matched. It also prints out a lot of standard verbiage - the "Directory" line at the top and the summary lines at the bottom. In UNIXy shells, there is a bit more division of labor. The shell handles any globs, performing "filename generation", and effectively rewriting the command line before it tries to execute it. To get a feel for how bash deals with globs, play with the echo command a bit. It will show you what a command will look after all expansions are performed: echo ls /etc/ssh* echo ls /etc/ssh/* echo ls /etc/rc.* 'ls' itself is a classic ball-of-mud application. (There are two types of applications: diamonds, and balls of mud. A rough diamond can be improved through proper cutting and polishing, and can eventually be deemed relatively perfect. The only way to improve a ball of mud is by adding more mud.) All sorts of options and "features" have been added to it over the decades - of the lower-case letters alone, only -e -y and -z are not valid options in the GNU version, and then there are When 'ls' is given a directory as an argument, its default behavior is to display the contents of that directory. If 'ls' is given the '-d' switch, it will print the names of directories instead of their contents. You didn't get any feedback that directory _contents_ were being displayed with 'ls /etc/ssh*' because there was only one argument given to 'ls'. That is, bash took the command line ls /etc/ssh* and turned it into ls /etc/ssh When given just one directory, 'ls' will not print any identifying information. Compare this to the behavior with what you get when you type ls /etc/rc* In this case, the contents of each directory are preceded by a line with the name of the directory. 'ls' can change what it is doing based on context, as well. See what happens when you type ls /etc/rc* | cat ('cat' is a command that will output either the contents of files supplied as arguments or input that is "piped" to it from another command. The '|' character is referred to as a "pipe" in this context.) Here, 'ls' detects that its output is being sent to another command, not to the terminal, so it doesn't do anything fancy, like printing out the filenames in columns, or inserting the names of the directories. Some other commands to try: find /etc -name 'ssh*' locate ssh (if you have slocate installed) echo $(ls -d /etc/rc.*) echo $(ls /etc/rc.*) echo /etc/trc.* Have fun! As you play around, you will discover that you can do things at the Linux command prompt that command.com and cmd.exe can't even dream of! For details on how bash does expansion, take a look at 'info bash', under "Basic Shell Features", "Shell Expansions". My personal favorite shell is 'zsh', the Z-Shell. It's similar to bash in many ways, but has all sorts additional features that make it really cool for interactive use. Balls of mud can be a lot of fun! Cheers, pls ___________________________________________________________________________ Philadelphia Linux Users Group -- http://www.phillylinux.org Announcements - http://lists.phillylinux.org/mailman/listinfo/plug-announce General Discussion -- http://lists.phillylinux.org/mailman/listinfo/plug
|
|