Ignore .txt in find script

Hi
i am really new to linux scripting and i need a little bit help.

i have the following script:

find "/usr/share/nextcloud/data/__groupfolders" -type f -mtime +14 -exec rm {} \;

but i don't want to delete everything. I want to ignore .txt files. How can i do this?

First of all, you should never run a script like this with -exec rm {} until you have tested it without the -exec rm {} ;

So first, think about:

find "/usr/share/nextcloud/data/__groupfolders" -type f -mtime +14 

and add the necessary arguments to find to ignore all .txt files

Try a few things, and test first and post back what you think is a good way to do it :wink:

Hint: Maybe try to add:

! -name "*.txt"

Yeah the script is running on a productiv Nextcloud in the testing phase i first tryed it with ls and after that i specified a folder in __groupfolders whitch could be deleted without worry of loosing something. The Script works fine like it is. Im going to try everything again with the ls. thx for your help

------ Post updated at 07:16 AM ------

thx man it is working you are top! You safed my day ;D

find "/usr/share/nextcloud/data/__groupfolders/28" -type f -mtime +14 ! -name "*.txt" -ls

Thanks but you could have easily discovered the ! -name flags for find looking at the man page examples:

       cd /source-dir
       find . -name .snapshot -prune -o \( \! -name *~ -print0 \)|
       cpio -pmd0 /dest-dir

See also:

 The following operands are supported:

       path	       A path name of a starting point in the directory hierarchy.

       expression      The first argument that starts with a -, or is a ! or a (, and all  subsequent  arguments  are
		       interpreted as an expression made up of the following primaries and operators. In the descrip-
		       tions, wherever n is used as a primary argument,  it  is  interpreted  as  a  decimal  integer
		       optionally preceded by a plus (+) or minus (-) sign, as follows:

		       +n	more than n

		       n	exactly n

		       -n	less than n
  -name pattern   True if pattern matches the current file name. Normal shell file  name  generation  characters
		       (see  sh(1))  can  be used. A backslash (\) is used as an escape character within the pattern.
		       The pattern should be escaped or quoted when find is invoked from the shell.

		       Unless the character '.' is explicitly specified in the beginning     of  pattern,  a  current
		       file   name   beginning	 with	'.'   does   not  match  pattern  when	using  /usr/bin/find.
		       /usr/xpg4/bin/find does not make this distinction; wildcard file  name  generation  characters
		       can match file names beginning with '.'.