Remove files which not named "today.md"

Use a negative match (requires shopt -s extglob, but possibly already set):

rm !(today).md

(you can first use ls instead of rm to check the result).

Lots of power in extglob, you could also do

rm !(yesterday|today).md

if you wanted to spare two files.


find . -maxdepth 1 -name '*.md' ! -name today.md -type f -print

Should find all the files (-type f) in the current directory (. -- or explicitly put a directory name there) only (-maxdepth 1 prevents following subdirectories) that end in .md (-name '*.md'), excluding (!) the file today.md.

Be sure to include the single quotes around '*.md' so your shell doesn't try to expand that to the list of .md files in the current directory before it executes find.

It will print the list of files to be deleted. Change -print to -delete to delete them instead.


The above are better solutions, but the reason your code isn't working is because of the comparison.

"./today.md" is not equal to "today.md".