OrenIshShalom
OrenIshShalom

Reputation: 7112

list files in directories that contain a given name

How to list all java files whose absolute paths contain the word opt? this works:

$ find . -name *.java | grep "opt"

But I need the sizes of those files as well (similar to ls)? I've tried the following but failed:

$ ls -l *opt*/*.java
$ find *opt* -name *.java

Upvotes: 0

Views: 58

Answers (1)

Raman Sailopal
Raman Sailopal

Reputation: 12877

find -type f -path "*/opt/*.java" -printf "%f %s\n"

Search for a specific directory/file path using -path and then use printf to print the file name (%f) and the file size (%s)

Upvotes: 1

Related Questions