Re: Basic ls/rm help



Alan Kirkup <12345@xxxxxxxxxxx> wrote:
I've tried RTFM as they say, but the commands I'm trying (ls -R
filename.ext and rm -R filename.ext) don't work. Obviously my
understanding of the Linux command line is flawed!

How do I do the above in Linux? The shell I'm using is bash.

Someone else has already answered your specific queries, so I'm going
to try and explain why what you've tried didn't work.

The COMMAND.COM doesn't understand wildcards, so it's up to the programs
themselves (DIR, DEL, etc.) to interpret them. This means that when
you do DIR FILENAME.EXT /S it's the DIR command matching FILENAME.EXT
recursively through the directories.

On the other hand, UNIX/Linux shells such as bash are responsible for
expanding wildcards into a list of files. So when you do something like
"ls *.txt" or "ls filename.ext" all that "ls" gets is a list of files
(it never sees the "*" [1]).

When do you something like "ls -R item", it tells "ls" to list the
contents of "item" recusively. (This is rather different to asking
"ls" to list the contents of all directories in the current directory
recursively, looking for matches to "item", which is what the DOS "DIR
/S" command would do.)

As it happens, if you want the latter behaviour then "ls" simply can't
do it; you have to use "find". But you can use the output of "find"
to drive "ls" thereby giving you the equivalent:

"ls" for all files matching "filename.ext" [2]:
find * -name "filename.ext" -print

"ls -l" for all files matching "filename.ext" [3]:
find * -name "filename.ext" -exec ls -ld {} \;

I hope this helps.
Chris

[1] Actually "ls" will see an asterisk if there are no matches to the
pattern. But personally I see that as a flaw rather than a feature. If
you really want a literal asterisk then you should quote it.

[2] Since all "ls" does is list filenames, you don't even need it, here

[3] You need to escape the ";" to stop it being interpreted by the
shell. It then gets passed to "find" and is used to mark the end of the
command passed to -exec
.



Relevant Pages

  • Re: Book for Linux
    ... manipulating files and permissions, file systems and basic administrative ... Beginning the Linux Command Line ...
    (alt.os.linux)
  • Re: how to umount a USB key
    ... Davide Bianchi tried to express: ... >> What is the linux command to light off a USB key before unplug it? ... Actually linux DOES have an command for removable devices. ...
    (comp.os.linux.hardware)
  • Re: Tutorial
    ... >I am looking for a tutorial about the Linux Command line, ... I said to use Control-Alt-F1. ... And if you're looking for a command-line Linux guide and not a general FC3 ...
    (Fedora)
  • Re: Tutorial
    ... Daniel Orzechowski wrote: ... >> I am looking for a tutorial about the Linux Command line, ... The Bash shell is the default command shell used with FC3. ...
    (Fedora)
  • Re: finding your IP address when dynamically assigned by dhcp
    ... > I believe that there is a linux command, ... > 'ipconfig' command in windows that will return the ip addresses and ...
    (comp.os.linux.misc)