Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Ubuntu terminal removing multiple partial files using wildcard

This maybe easy on linux users, but I am having a hard time figuring out how to delete multiple files (partial files) using wildcard.

sudo rm logs/archived/remove_me.2022.* or sudo rm logs/archived/remove_me.2022.? seems not to work.

I am getting the error rm: cannot remove 'logs/archived/remove_me.*': No such file or directory

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I am currently on /var/lib/tomcat8/ trying to remove these logs inside logs/archived.

I am remove them one by one but there are a lot of files to remove .. (example. from 2020 and there are daily and in partial files).

Example I am inside /var/lib/tomcat8/logs/archived/ and I want to remove all log files starting with remove_me.2021.*

Below are the sample list of files that I want to remove.There are also other files in this directory that should not be removed.

remove_me.2022-03-02.1.log.gz
remove_me.2022-03-02.2.log.gz
remove_me.2022-03-02.3.log.gz
remove_me.2022-03-02.4.log.gz
remove_me.2022-03-02.5.log.gz
remove_me.2022-03-03.1.log
remove_me.2022-03-03.2.log
remove_me.2022-03-03.3.log
remove_me.2022-03-03.4.log
remove_me.2022-03-03.5.log
remove_me.2022-03-03.6.log
remove_me.2022-03-03.7.log
remove_me.2022-03-03.8.log
remove_me.2022-03-03.9.log
remove_me.2022-03-03.10.log

>Solution :

I believe the issue here is that the asterisk (*) is resolved by the current user, i.e., before becoming the superuser. Hence, it resolves to nothing, because the current user is not able to even read that directory.

Solve this by becoming superuser first, and then doing everything normally:

sudo -i
cd /var/lib/tomcat8/logs/archived/
rm remove_me.2022.*
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading