Search code examples
linuxshellglob

Linux globbing - exclude files that contain a hyphen/dash in filename


I want to ignore all files that contain a dash/hyphen in filename.

$ ls /home/user/logs/*.log
access.log
error.log
access-2020-05-27.log
access-2020-05-26.log
error-2020-05-27.log
error-2020-05-26.log

I only want it to list access.log and error.log

I tried this but it does the exact opposite of what I want. Lists all files with a dash/hyphen

ls /home/user/logs/*[-]*.log

Solution

  • These two work OK with bash:

    ls *[A-Za-z].log
    
    ls *[^0-9].log
    

    Also:

    ls | grep -v -e -