LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 07-27-2020, 01:47 PM   #1
cesarsj
Member
 
Registered: Mar 2019
Location: Patos de Minas, MG, Brazil
Distribution: Slackware
Posts: 159

Rep: Reputation: Disabled
Question 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?
 
Old 07-27-2020, 02:08 PM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
There is no specific exclude option.

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.
 
Old 07-27-2020, 02:17 PM   #3
cesarsj
Member
 
Registered: Mar 2019
Location: Patos de Minas, MG, Brazil
Distribution: Slackware
Posts: 159

Original Poster
Rep: Reputation: Disabled
Lightbulb

Quote:
Originally Posted by rtmistler View Post
There is no specific exclude option.

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.
I got what I wanted like this:

rm -f syslog.?; rm -f syslog.??
 
Old 07-27-2020, 02:47 PM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,310
Blog Entries: 3

Rep: Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722Reputation: 3722
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.
 
2 members found this post helpful.
Old 07-27-2020, 07:34 PM   #5
igadoter
Senior Member
 
Registered: Sep 2006
Location: wroclaw, poland
Distribution: many, primary Slackware
Posts: 2,717
Blog Entries: 1

Rep: Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625Reputation: 625
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.

Last edited by igadoter; 07-27-2020 at 07:44 PM.
 
Old 07-27-2020, 07:49 PM   #6
frankbell
LQ Guru
 
Registered: Jan 2006
Location: Virginia, USA
Distribution: Slackware, Ubuntu MATE, Mageia, and whatever VMs I happen to be playing with
Posts: 19,326
Blog Entries: 28

Rep: Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142Reputation: 6142
As an aside, I'm a bit puzzled.

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.
 
3 members found this post helpful.
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Why is syslog-ng not recording any log events in /var/log/syslog.log ToffeeYogurtPots Linux - Software 3 05-31-2018 02:15 PM
Euro MPs back end-to-end encryption for all citizens Jeebizz Linux - News 3 10-31-2017 11:50 AM
no syslog after delete syslog file zerop Ubuntu 4 04-26-2016 01:31 PM
How to extract all files on a directory and delete all files? moisespedro Slackware 9 01-21-2014 11:55 AM
Can I delete files in /mnt/tmp? and Files in the trash can will not delete? M$ISBS Slackware 15 10-02-2009 11:56 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 10:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration