Search code examples
linuxls

List files but exclude certain directories in Unix


I am attempting to list files in a folder with sub folders recursively, but trying to avoid going into one folder as they are duplicates.

This is the command I run but it doesn't do anything.

ls -lR /opt/elk/data/syslogs | grep -v .log. | grep --exclude-dir="cam" * > /tmp/logs.log

If there any changes I can make to this?

Thanks.


Solution

  • Options to different versions of find vary greatly, but you may try:

    find /opt/elk/data/syslogs -name cam -prune -o -print
    

    On RHEL, you probably have gnu find, and if you want file size and modification time, you might try:

    find /opt/elk/data/syslogs -name cam -prune -o -printf "%p %s %t\n"