Remove files from directory based on partial name in Linux
Wanted to know what is the best way to remove any files from directory no matter what their extension is based on a partial name. You have multiple files in directory but wanted to delete specifices file which files name are started from or end from or having some characters.
Cron_foo_something.jpg Cron_foo_today.jpg Text_something.png Logs_foo_site.html logo.php
The simple way go to directory path:
cd /path/to/directory
run command rm. The following example used for file name having _foo_
rm *_foo_*
or
you can directly run rm commant by passing file path
rm /path/to/directory/*_foo_*
Delete the file which name started from Cron_foo_
rm Cron_foo_*
or
rm /path/to/directory/*Cron_foo_*
Delete the file which name started from _something
rm *_something
or
rm /path/to/directory/*_something