Really basic question... I'm not too embarrased to ask
I gave up on Windows search years ago (kept missing out files I knew were there, GUI changes from one Windows version to the next), so I open a command window, cd\ if necessary, and
dir whatever.* /s
This scans the whole disk ( /s being to specify subdirectories) and finds what I'm looking for.
I tried to use ls in Linux, but although ls -R does list the whole disk, ls -R *.mp3 doesn't do what I expect - because if there's no file matching the search criteria in the initial folder, it errors (No such file or directory) and doesn't try anywhere else.
Doesn't look like any other switches would help, either.
What's the secret to such a simple search?
Search with ls, like MS-DOS dir /s ...?
Forum rules
Topics in this forum are automatically closed 6 months after creation.
Topics in this forum are automatically closed 6 months after creation.
Search with ls, like MS-DOS dir /s ...?
Last edited by LockBot on Wed Dec 28, 2022 7:16 am, edited 2 times in total.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Reason: Topic automatically closed 6 months after creation. New replies are no longer allowed.
Re: Search with ls, like MS-DOS dir -s ...?
Instead of ls, use find. As in: find path-to-search what-to-search-for
To find all mp3 files in the current folder and all subfolders:
The \* makes the wildcard (*) not expanded to match files in the current folder (else you would only find those mp3 files ). The \ is an escape character, ensuring the next character is kept as a literal and not expanded by the shell to do filename matching (aka globbing).
You can also search case-insensitive:
Find has lots more nice features.
To find all mp3 files in the current folder and all subfolders:
Code: Select all
find . -name \*.mp3
You can also search case-insensitive:
Code: Select all
find . -iname \*.mp3
Re: Search with ls, like MS-DOS dir /s ...?
Thanks, that did the trick... more or less
- the wanted stuff is buried in the midst of tons of other lines of Permission denied
I still prefer the dir /s I'm used to with DOS though... you get a summary per folder with count of files and total filesize, and each line shows date/time and size too.
Sounds like the basis for a script....
- the wanted stuff is buried in the midst of tons of other lines of Permission denied
I still prefer the dir /s I'm used to with DOS though... you get a summary per folder with count of files and total filesize, and each line shows date/time and size too.
Sounds like the basis for a script....
Re: Search with ls, like MS-DOS dir /s ...?
You can disregard any warnings, by either running it as root, as in:
Or, preferably, just disregarding the warnings:
(This redirects file descriptor 2, known as stderr, or where the errors are written, to the bit bucket.)
If you want to scan the whole disk, just replace . as path with /, as in:
With the -printf "format" argument added you can also tell it how to output its results. See "man find" for details, you'll need that anyway to write a script If you know perl, you can automatically generate the perl code for any find command with find2perl. Try it:
Just edit the created code to tune it to what you need
Code: Select all
sudo find . -name \*.mp3
Code: Select all
find . -name \*.mp3 2>/dev/null
If you want to scan the whole disk, just replace . as path with /, as in:
Code: Select all
find / -name \*.mp3 2>/dev/null
Code: Select all
find2perl . -name \*.mp3
Re: Search with ls, like MS-DOS dir /s ...?
Many thanks for the help, all works well.. shame it's so much more verbose than dir /s
- but if I'm going to use it more often then I'll get used to it or script something up!
Thanks!
- but if I'm going to use it more often then I'll get used to it or script something up!
Thanks!