I just need to know how to search (within Finder vs Terminal, if possible) for all file names within a specific folder, which begin or end with a space or a period.
For example:
" file.jpg" (begins with a space)
"file .jpg" (ends with a space)
"file..jpg" (ends with a period
Additionally, finding a file name with the characters * or " in it. Searching for this in file name using Finder produces thousands of results which don't actually have * or " in it.
Example: "fil*e.jpg" or "fil"e.jpg"
Best Answer
With
Finder
as the active application, chooseFind
from theFile
menu. In theSearching "This Mac"
window that brings up, selectKind
isDocument
, then use+
to add another condition withName
as the first item. If you choosebegins with
as the second item, you can find files whose names begin with a particular character, like space. Theends with
condition won't find files with the names in your examples unless the filename suffix ends with the character of interest, but you can find a particular character, like a space, as the last character before the suffix if you choosecontains
and follow that character with.
. For yourfile..jpg
example you would use..
for the search text. This approach will find literal*
characters in filenames, if you choosecontains
and use*
for the search text.Finding such files with the
find
command (inTerminal
) is straightforward if you quote special characters appropriately. For example,reports all files in my Downloads directory which begin with a space,
reports all files in my Downloads directory with a
*
in its name,reports all files in my Downloads directory with two consecutive
.
characters in its name, andreports all files with a space character immediately before the suffix. Finally,
reports all of those files in my Downloads directory. You can anchor the search elsewhere by replacing
Downloads
on the command line, and you can use other options to restrict the search further (-type f
would ignore directories and symlinks).