Re: Basic ls/rm help
- From: Chris Davies <chris-usenet@xxxxxxxxxxxx>
- Date: Wed, 16 May 2007 10:30:23 +0100
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
.
- Prev by Date: Re: Southern Electric e-billing site "enhanced" to no longer work on linux
- Next by Date: Re: Southern Electric e-billing site "enhanced" to no longer work on linux
- Previous by thread: Re: Basic ls/rm help
- Next by thread: Re: Basic ls/rm help
- Index(es):
Relevant Pages
|