I am newbie on linux os. My target is selecting files which have the specific string values in filenames on console mode

This is my sample filename,

filename : apnic-2016-02-01

condition : The first letter of filename should not start with 'b' and the day value (01) should be odd value

Below is my command using pipe and grep command.

ls -al | grep -v [b]   --> choosing the filenames which dose not start with 'b' and working successfully

but I am stuck with selecting odd value in the filename. I wonder how to choose the odd day value on filename.

Any reply will be welcomed.

  • The format is year, month, and day? As far as I know, I don't think there's a way to say "odd". You might have to grep out even values instead. They would end in 0, 2, 4, 6, 8. So, | grep -v "2$" | grep -v "4$" ... should work.
    – Ray
    Mar 27, 2021 at 5:03

1 Answer 1

 ls -d [!b]*[13579]

This command will select all files whose name doesn't start with 'b' and ends with a odd number.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .