No, find
by default traverses all available levels:
sudo find / -mount -name 'myfilename'
If you have a separate home partition, or a encrypted home, or a secondary hard drive, you may want to list their mount points too, next to /
, for example
sudo find / /home/enzotib /media/data -mount -name 'myfilename'
The -mount
option is needed to avoid to traverse mounted filesystems. Among these there are /proc
, /dev
and /sys
, that is convenient to skip.
An alternative to traverse all files, avoiding only these last three paths is
sudo find /!(proc|sys|dev) -name 'myfilename'
Finding Files with bat
Anywhere
To find all files anywhere inside /path/to/folder
whose names contain bat
, you can use:
find /path/to/folder -name '*bat*'
I have quoted the search pattern *bat*
because, if the quotes were omitted and files match *bat*
in the current directory, the shell will expand *bat*
into a list of them and pass that to find
. Then find
wouldn't work right. (\*bat\*
and "*bat*"
also work.)
To search in the folder you're currently in (e.g., that you've cd
ed to), use .
, as usual:
find . -name '*bat*'
To search your whole computer, use /
. To search your home directory, use ~
, or the full name of your home directory. (The shell expands ~
to your home directory's fully qualified path.)
Broadening or Narrowing Your Search, Based on Name
If you want to search case-insensitively, so files containing BAT
, bAt
, and so forth are matched, use the -iname
test instead of the -name
test:
find /path/to/folder -iname '*bat*'
I've noticed all your files end in .c
. If you only want to find files like that, use:
find /path/to/folder -name '*bat*.c'
I noticed all your filenames have bat
either at the very beginning or the very end of the part preceding the .c
suffix. If you want to avoid matching files like embattled.c
, you could use:
find /path/to/folder -name '*bat.c' -o -name 'bat*.c'
-o
is the or operator.
Matching Only Files
To find only regular files--and not folders, symbolic links, and special device nodes--you can use -type f
. This is frequently recommended and sometimes quite appropriate... but often not what you really want, especially if you're running find
for the purpose of examining the output yourself. If you had a symbolic link that matched your search, wouldn't you want to know about it?
If you want to find both regular files and symbolic links, you can use:
find /path/to/folder -name '*bat*' \( -type f -o -type l \)
That uses the -o
operator and also parentheses for grouping (which must be quoted so the shell does not treat them specially; otherwise you'll get a syntax error).
But suppose you only want to see symbolic links that ultimately point to a regular file (and not symbolic links to directories, device nodes, etc.). That's actually even simpler: use -xtype
instead of -type
. Provided you're not running find
with -L
flag, -xtype
on a symbolic link tests the type of the file the link points to.
find /path/to/folder -name '*bat*' -xtype f
If you have a symlink to another symlink to a file, -xtype f
will match it even though its direct target is another symlink rather than a regular file. This is almost always what you want.
Often people think they want -type f
, but really they want -xtype f
.
Getting Detailed Output
find
's default action if you don't specify one is -print
. All the commands given above are equivalent to themselves with -print
tacked on at the end.
find
is often used to run commands based on the files found--often, commands that make changes. But there are also other actions whose purpose is to display results, besides -print
. Of particular interest is -ls
:
find /path/to/folder -name '*bat*' -ls
This gives detailed information on each file, in a multi-column format, similar to (though not quite the same as) what you would see by running ls file
.
Further Reading
For more information on find
and other ways to find files, see:
Best Answer
Via bash's recursive glob and ImageMagick's
identify
command:Saving such output to file , is just a matter of adding
> mylog.txt
to previous command, that isFrom there, you could use
awk
orperl
to comparemylog.txt
columnsawk
here uses,
as separator for columns, and the usual structure forawk
is/PATTERN/{COMMANDS}
, which defaults to just printing if{COMMANDS}
omitted ; in the particular example above, if the pattern$2 > 800 && $3 > 600
is true, that is it's the image above desired resolution, you'll get it printed to the screen.And probably skipping the log step in between, it would be a little better to just pipe everything:
In case you encounter
arguments list too long
error, typicallyfind
command is better approach for recursively walking the directory tree. Theidentify
can be called throughfind
's-exec
flag, and filtering still can be handled byawk
:As usual, don't forget to add
> log2.txt
to save everything to file.Full path of to the file could be handled in either one of two ways. One, by specifying
%d/%f
inidentify
command's format string, or usefind
's-printf
option. That is eitherOr