How do I delete all files that start with syslog BUT do not end with .gz?
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
How do I delete all files that start with syslog BUT do not end with .gz?
I would like to leave only the compressed logs.
I would like to leave only the compressed logs. How could I delete all those that don't end with .gz at once? Does the rm command have any flags for this?
You really should read the manual page for the rm command to see this for yourself.
Depending on the files, you can remove using a wildcard and not affect the .gz files.
For instance if you have a bunch of .log files, and you also have a bunch of .log.gz files, if you remove using a term like "*.log" it will only remove the .log files and not the .log.gz files.
You really should read the manual page for the rm command to see this for yourself.
Depending on the files, you can remove using a wildcard and not affect the .gz files.
For instance if you have a bunch of .log files, and you also have a bunch of .log.gz files, if you remove using a term like "*.log" it will only remove the .log files and not the .log.gz files.
Another way would be to build out a query using the find utility.
Code:
find /some/path/ -type f -name 'syslog.*' -not -name '*.gz' -print
Then when you have found what you want to delete, tack on a -delete on the end of that.
find can also use regular expressions with use of the -regex and -regextype options. See the output from 'find -regextype help' for what styles of regular expressions your version supports.
Well grep with correct pattern those to delete place resulting list into file and you can use while loop on this file with rm command with -i option for safety. Some suggests to full file name for complete safety.
Edit: one more word is about to be carefull char bash is using as word delimiter. Usually it is space but it is something to change. Bash splits name according to word delimiter. I am not quite sure does double quotes grants enough protection.
The log files that do not end in .gz are older logs that have been compressed by logrotate. The others are the live logs being created by current processes.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.