From man find
-empty File is empty and is either a regular file or a directory.
So to find both empty files and directories it is sufficient to do
find ~/lists -empty
To indicate the type, you could use the %y
output format specifier
%y File's type (like in ls -l), U=unknown type (shouldn't happen)
e.g.
find ~/lists -empty -printf '%y %p\n'
or make use of an external program like ls
, which includes a --classify
option
-F, --classify
append indicator (one of */=>@|) to entries
i.e.
find ~/lists -empty -exec ls -Fd {} \;
If your definition of 'empty' is expanded to include files containing only whitespace characters, then it becomes more complicated - and more computationally intensive, since now you need to actually open at least any non-empty files and examine their contents. The most efficient way I can think of off the top of my head would be something like
find ~/list \( -empty -o \( -type f -a ! -exec grep -qm1 '[^[:blank:]]' {} \; \) \) -exec ls -Fd {} \;
(either empty, OR a file AND grep does not detect at least one non-blank character). Likely there is a better way though.
TL;DR
Add -iname "*.log"
after /
to your find
command. Refer to man page for more info
A more detailed answer
The task at hand is the following:
- List files that match pattern
*.log
- Execute
grep
per each file to find whether or not it contains a specific string.
- List the filename that has a match on the
stdout
The example of how that can be accomplished can be seen bellow:
$ find /var/log -iname "*.log" -exec grep -l 'wlan' {} \+
Essentially there's 3 things at play:
find
does the job of finding files AND calling grep
per list of filenames in the -exec ...{} \+
structure, where {}
will be substituted with all the filenames found.
-iname "*.log"
can provide case-insensetive matching of the filenames
-exec . . .{} \+
calls the low-level execve
function that will spawn grep -l
with the list of all the files found in front of it ( in the place of {}
).
- The
\+
is the option that specifies for execve
to pack as any files as possible in front of grep
(the limit is set by ARG_MAX
variable, is specific to exec
, and for Ubuntu is at 2097152
as can be shown by getconf ARG_MAX
command ). Once the limit is reached, exec
will repeat the call to grep
with more files packed as arguments. The \
is necessary to ensure +
is interpreted as argument to find
and not as another shell command.
- the
-l
option or grep shows files with matched string. -L
would match files without the string.
Best Answer
Or...
For example
Or
(where ~ equates to /home/your_username/), or...
and so forth.