删除Linux NAS上的所有mac`._`文件?


0

我正在尝试从旧的NAS盒(qnap ts209)中删除所有隐藏的mac垃圾邮件文件。我尝试按照以下步骤用bash删除所有Mac生成的文件“ ._”,但NAS上的find命令不包含该-exec选项。

# [/share/Qweb] # find -name "._*" -exec rm -rf {} \;

Usage: find [PATH...] [EXPRESSION]

Search for files in a directory hierarchy.  The default PATH is
the current directory; default EXPRESSION is '-print'

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

[/share/Qweb] #

这是关于我的盒子的一些信息:

[/share/Qweb] # man find
-sh: man: command not found
[/share/Qweb] # cat /etc/*-release
cat: /etc/*-release: No such file or directory
[/share/Qweb] # lsb_release
-sh: lsb_release: command not found
[/share/Qweb] # cat /proc/version
Linux version 2.6.12.6-arm1 (root@NasARM4) (gcc version 3.4.4 (release) (CodeSourcery ARM 2005q3-2)) #2 Sun Sep 18 02:09:29 CST 2011
[/share/Qweb] # uname -a
Linux QNAP 2.6.12.6-arm1 #2 Sun Sep 18 02:09:29 CST 2011 armv5tejl unknown
[/share/Qweb] # uname -mrs
Linux 2.6.12.6-arm1 armv5tejl

我不知道如何从查找到rm,也许这是可能的,我在SU中寻找不涉及的答案时感到非常困惑-exec。(编辑:https : -delete//stackoverflow.com/a/11191868/1238884 建议配管到RM并不是一种选择;该死的,我也没有这种选择.0

Answers:


1

似乎您缺少消息所要求的PATH参数,即类似

find . -name "._*" -exec rm -rf {} \;

注意.这里。如果不是从当前目录开始,则替换为起始路径。

如果您拥有xargs(1),则可以使用该rm(1)文件,以便每个调用一次处理多个文件:

find . -name "._*" | xargs rm

小心,进行空试,例如echo(1),确保没有任何不良反应发生。


xargs工作,谢谢一群!(也附和,但后来find . -name "._*" -print确实也。
frumbert

0

创建一个名为“ del_apple_files.py”(或类似名称)的文件,在其中粘贴以下内容:

#!/bin/env python

import os
import fnmatch 

def purge(dir, pattern):
   for root, dirnames, filenames in os.walk(dir):     
       for filename in fnmatch.filter(filenames, pattern):
           match = os.path.join(root, filename)        
           print(str(match))     
           os.remove(match)                  

dir = '/PATH/TO/SHARED/FOLDERS/ROOT'
pattern = '._*'

purge(dir, pattern)

将文件复制到您的NAS盒中,通过SSH进入其中,并以管理员用户身份运行该文件,并在整个共享文件夹中具有访问权限:

python /PATH/TO/del_apple_file.py

您还可以为其计划一个cronjob,它将仅删除文件,并将文件夹留在后面...

请享用!;)

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.