What's the best way to delete certain files?

Questions about SNMP, Power, System, Logs, disk, & RAID.
Post Reply
johncatral
New here
Posts: 8
Joined: Sun Aug 16, 2015 6:26 am

What's the best way to delete certain files?

Post by johncatral »

Hello, guys!

I'm hoping you could guide me on what's the best and possibly quickest way to delete all files in a folder, EXCEPT certain extensions?

To give you a better understanding what I'm trying to do is to remove all unnecessary files, but leave movie files like mp4, mkv, avi, etc. alone. I've been using sabnzbd on my qnap for years now and I want to clean the folder up.

Any apps I can use on Qnap that you could recommend. Terminal commands would possibly be the best, but I'm not sure.

Thanks in advance!

- JOhn
User avatar
MrVideo
Experience counts
Posts: 4742
Joined: Fri May 03, 2013 2:26 pm

Re: What's the best way to delete certain files?

Post by MrVideo »

Be sure and back up the folder before doing any of this.

This is a very simple way of doing this. Log in as admin via ssh and do the following:

Code: Select all

cd [to the directory containing the files]
mkdir ../temp_dir
mv *.{mkv,mp4,avi,(and whatever extensions)} ../temp_dir
rm *
mv ../temp_dir/* .
rm -r ../temp_dir
The idea is to move all the files you want to keep out of the way when you remove whatever is left in the directory. Then you move the files back and remove the temporary directory.

Keep in mind that files are not actually moved, taking time. Because the files are in the same directory file system, only directory links are changed, which is really fast.

There might be other ideas.
QTS MANUALS
Submit QNAP Support Ticket - QNAP Tutorials, FAQs, Downloads, Wiki - Product Support Status - Moogle's QNAP FAQ help V2
Asking a question, include the following
(Thanks to Toxic17)
QNAP md_checker nasreport (release 20210309)
===============================
Model: TS-869L -- RAM: 3G -- FW: QTS 4.1.4 Build 20150522 (used for data storage)
WD60EFRX-68L0BN1(x1)/68MYMN1(x7) Red HDDs -- RAID6: 8x6TB -- Cold spare: 1x6TB
Entware
===============================
Model: TS-451A -- RAM: 2G -- FW: QTS 4.5.2 Build 20210202 (used as a video server)
WL3000GSA6472(x3) White label NAS HDDs -- RAID5: 3x3TB
Entware -- MyKodi 17.3 (default is Kodi 16)
===============================
My 2017 Total Solar Eclipse Photos | My 2019 N. Ireland Game of Thrones tour
johncatral
New here
Posts: 8
Joined: Sun Aug 16, 2015 6:26 am

Re: What's the best way to delete certain files?

Post by johncatral »

@MrVideo, thank you for that! I'm assuming that will only the files that are in the current directory and not in any sub-folders, right? I forgot to add that in my original post that I will be dealing with a lot of subfolders. I'll try this out! :) Thanks!
User avatar
MrVideo
Experience counts
Posts: 4742
Joined: Fri May 03, 2013 2:26 pm

Re: What's the best way to delete certain files?

Post by MrVideo »

True, it will not traverse sub-directories. That complicates the issue. I'm not saying that it can't be done with a script. How many sub-directories are involved?

BTW, the script that I provided will complain about not being able to delete those sub-directories, which is good.
QTS MANUALS
Submit QNAP Support Ticket - QNAP Tutorials, FAQs, Downloads, Wiki - Product Support Status - Moogle's QNAP FAQ help V2
Asking a question, include the following
(Thanks to Toxic17)
QNAP md_checker nasreport (release 20210309)
===============================
Model: TS-869L -- RAM: 3G -- FW: QTS 4.1.4 Build 20150522 (used for data storage)
WD60EFRX-68L0BN1(x1)/68MYMN1(x7) Red HDDs -- RAID6: 8x6TB -- Cold spare: 1x6TB
Entware
===============================
Model: TS-451A -- RAM: 2G -- FW: QTS 4.5.2 Build 20210202 (used as a video server)
WL3000GSA6472(x3) White label NAS HDDs -- RAID5: 3x3TB
Entware -- MyKodi 17.3 (default is Kodi 16)
===============================
My 2017 Total Solar Eclipse Photos | My 2019 N. Ireland Game of Thrones tour
johncatral
New here
Posts: 8
Joined: Sun Aug 16, 2015 6:26 am

Re: What's the best way to delete certain files?

Post by johncatral »

Oh, there are a lot of sub-folders, so it looks like my issue may be even more complicated. :(
User avatar
OneCD
Guru
Posts: 12139
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: What's the best way to delete certain files?

Post by OneCD »

@MrVideo, this might be a job for a recursive `find` with an extension white-list?

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
User avatar
MrVideo
Experience counts
Posts: 4742
Joined: Fri May 03, 2013 2:26 pm

Re: What's the best way to delete certain files?

Post by MrVideo »

OneCD wrote:@MrVideo, this might be a job for a recursive `find` with an extension white-list?
Yep, but the "find" that is included with QNAP is very weak in a lot of things. I'm not sure what it can, or cannot, do.

The builtin find can only do:

Code: Select all

EXPRESSION may consist of:
	-follow		Dereference symbolic links.
	-name PATTERN	File name (leading directories removed) matches PATTERN.
	-print		Print (default and assumed).

	-type X		Filetype matches X (where X is one of: f,d,l,b,c,...)
	-perm PERMS	Permissions match any of (+NNN); all of (-NNN);
			or exactly (NNN)
	-mtime TIME	Modified time is greater than (+N); less than (-N);
			or exactly (N) days
The entware find can do:

Code: Select all

Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

default path is the current directory; default expression is -print
expression may consist of: operators, options, tests, and actions:

operators (decreasing precedence; -and is implicit where no others are given):
      ( EXPR )   ! EXPR   -not EXPR   EXPR1 -a EXPR2   EXPR1 -and EXPR2
      EXPR1 -o EXPR2   EXPR1 -or EXPR2   EXPR1 , EXPR2

positional options (always true): -daystart -follow -regextype

normal options (always true, specified before other expressions):
      -depth --help -maxdepth LEVELS -mindepth LEVELS -mount -noleaf
      --version -xdev -ignore_readdir_race -noignore_readdir_race

tests (N can be +N or -N or N): -amin N -anewer FILE -atime N -cmin N
      -cnewer FILE -ctime N -empty -false -fstype TYPE -gid N -group NAME
      -ilname PATTERN -iname PATTERN -inum N -iwholename PATTERN -iregex PATTERN
      -links N -lname PATTERN -mmin N -mtime N -name PATTERN -newer FILE
      -nouser -nogroup -path PATTERN -perm [-/]MODE -regex PATTERN
      -readable -writable -executable
      -wholename PATTERN -size N[bcwkMG] -true -type [bcdpflsD] -uid N
      -used N -user NAME -xtype [bcdpfls]
      -context CONTEXT


actions: -delete -print0 -printf FORMAT -fprintf FILE FORMAT -print 
      -fprint0 FILE -fprint FILE -ls -fls FILE -prune -quit
      -exec COMMAND ; -exec COMMAND {} + -ok COMMAND ;
      -execdir COMMAND ; -execdir COMMAND {} + -okdir COMMAND ;
QTS MANUALS
Submit QNAP Support Ticket - QNAP Tutorials, FAQs, Downloads, Wiki - Product Support Status - Moogle's QNAP FAQ help V2
Asking a question, include the following
(Thanks to Toxic17)
QNAP md_checker nasreport (release 20210309)
===============================
Model: TS-869L -- RAM: 3G -- FW: QTS 4.1.4 Build 20150522 (used for data storage)
WD60EFRX-68L0BN1(x1)/68MYMN1(x7) Red HDDs -- RAID6: 8x6TB -- Cold spare: 1x6TB
Entware
===============================
Model: TS-451A -- RAM: 2G -- FW: QTS 4.5.2 Build 20210202 (used as a video server)
WL3000GSA6472(x3) White label NAS HDDs -- RAID5: 3x3TB
Entware -- MyKodi 17.3 (default is Kodi 16)
===============================
My 2017 Total Solar Eclipse Photos | My 2019 N. Ireland Game of Thrones tour
User avatar
OneCD
Guru
Posts: 12139
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: What's the best way to delete certain files?

Post by OneCD »

Agree. Might be worth installing GNU find if it makes the job easier. ;)

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
johncatral
New here
Posts: 8
Joined: Sun Aug 16, 2015 6:26 am

Re: What's the best way to delete certain files?

Post by johncatral »

Is this the right way of installing Entware via manual install in the Appcenter?

https://github.com/Entware-ng/Entware-n ... n-QNAP-NAS

Thanks!
User avatar
OneCD
Guru
Posts: 12139
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: What's the best way to delete certain files?

Post by OneCD »

Hi John. :)

If possible, try the standard installer QPKG for Entware-3x instead. It can be found here.

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
johncatral
New here
Posts: 8
Joined: Sun Aug 16, 2015 6:26 am

Re: What's the best way to delete certain files?

Post by johncatral »

Awesome! I’ll try that out.

Thank you!
User avatar
OneCD
Guru
Posts: 12139
Joined: Sun Aug 21, 2016 10:48 am
Location: "... there, behind that sofa!"

Re: What's the best way to delete certain files?

Post by OneCD »

Oh, and to install GNU find:

Code: Select all

opkg install findutils

ImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImageImage
Post Reply

Return to “System & Disk Volume Management”