AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / server / 问题

问题[find](server)

Martin Hope
Alex Douglas
Asked: 2021-04-01 08:48:47 +0800 CST

cron 查找多种文件类型并自动删除它们

  • 0

我正在尝试组合一个命令来查找多种文件类型并自动删除它们。我想在我的服务器上每 10 分钟在 cron 中运行一次。

我想查找以下类型的文件:.swp、.save、.swo、.maintenance 和 .bak

这是我的命令:

 find . -type f -name '*.swp' -o -type f -name '*.save' -o -type f -name '*.bak' -o -type f -name '*.swo' -o -type f -name '*.maintenance'

我会在这个命令中添加什么来自动删除这些文件?

我尝试在最后添加 -delete ,但这并没有摆脱它们:

 find . -type f -name '*.swp' -o -type f -name '*.save' -o -type f -name '*.bak' -o -type f -name '*.swo' -o -type f -name '*.maintenance' -delete
cron files find ubuntu-18.04
  • 1 个回答
  • 102 Views
Martin Hope
Spot
Asked: 2020-11-07 12:44:52 +0800 CST

rsync远程查找前缀主目录?

  • 2

我正在尝试从十分钟前的远程目录中提取所有内容,然后删除源文件。

我的远程查找似乎正在工作(在远程盒子上独立测试),但是当 rsync 使用它时,我的用户的主路径将作为查找输出的前缀,如下所示:

rsync -avz --dry-run --remove-source-files --files-from=<(ssh spot@host "find /mnt/volume_2/partners/test/uploads/ -amin +10 -type f,d -print0") spot@host:. .

receiving incremental file list
rsync: [sender] link_stat "/home/spot/mnt/volume_2/partners/test/uploads" failed: No such file or directory (2)
rsync: [sender] link_stat "/home/spot/mnt/volume_2/partners/test/uploads/file-1054" failed: No such file or directory (2)
rsync: [sender] link_stat "/home/spot/mnt/volume_2/partners/test/uploads/file-1105" failed: No such file or directory (2)
rsync: [sender] link_stat "/home/spot/mnt/volume_2/partners/test/uploads/file-1105/subfile-1105" failed: No such file or directory (2)
rsync: [sender] link_stat "/home/spot/mnt/volume_2/partners/test/uploads/file-1101" failed: No such file or directory (2)
rsync: [sender] link_stat "/home/spot/mnt/volume_2/partners/test/uploads/file-1056" failed: No such file or directory (2)
rsync: [sender] link_stat "/home/spot/mnt/volume_2/partners/test/uploads/file-1058" failed: No such file or directory (2)

我花费的时间比我想承认的尝试解决这个问题的时间要多,但没有成功。我希望这里有人能很好地为我指明正确的方向。

谢谢!

rsync find
  • 1 个回答
  • 527 Views
Martin Hope
Alex Douglas
Asked: 2020-10-29 09:57:49 +0800 CST

我想在某个目录的 crontab 中每 10 分钟运行一次命令 [重复]

  • 0
这个问题在这里已经有了答案:
为什么我的 crontab 不工作,我该如何排除故障? (7 个回答)
1 年前关闭。

使用 Ubuntu 18.04 运行服务器

我试图在 /var/www/html 目录上的 crontab 中每 10 分钟运行一次此命令:

  find . -type f -name "*.maintenance" -delete

这是完成此操作的正确语法吗?

  */10 * * * * /var/www/html find . -type f -name "*.maintenance" -delete
linux cron find ubuntu-18.04
  • 1 个回答
  • 102 Views
Martin Hope
n4rzul
Asked: 2020-08-15 06:45:53 +0800 CST

递归地制作所有 .acignore->.gitignore 的副本

  • 0

我以以下文件结构为例

    c
    -Git
     -GitBranchTest
         .acignore
         [lots more files]
      -subfolder
         .acignore
         [lots more files]

我正在尝试复制所有 .acignore 文件并重命名为 .gitignore,所以当我完成后它应该看起来像这样

    c
    -Git
     -GitBranchTest
         .acignore
         .gitignore
         [lots more files]
      -subfolder
         .acignore  
         .gitignore  
         [lots more files]

我尝试过的和我得到的错误:

我试过的

我希望这足够清楚。请帮忙。

linux bash cp find
  • 2 个回答
  • 42 Views
Martin Hope
James B. Byrne
Asked: 2020-05-28 11:34:40 +0800 CST

我需要在使用 -newermt 和 -exec ls {} 时解释 bash 查找行为

  • 0

我有这个命令:

find /var/cache/pkg  -newermt 2020-01-30 | grep 'kdeaccessibility-4.14.3_1'

什么都不返回。我把它改成这样:

find /var/cache/pkg  -newermt 2020-01-30 -exec ls -D '%F' -l -t -r {} \; | grep 'kdeaccessibility-4.14.3_1'

并返回:

-rw-r--r--  1 root  wheel        556 2017-07-14 kdeaccessibility-4.14.3_1-6dc124e39c.txz
lrwxr-xr-x  1 root  wheel         40 2017-07-21 kdeaccessibility-4.14.3_1.txz -> kdeaccessibility-4.14.3_1-6dc124e39c.txz

因此,该-newermt选项似乎被该-exec选项禁用。但我不明白为什么。

但是,如果我添加该-type f选项,则查找按预期工作。

find /var/cache/pkg  -type f -newermt 2020-01-30 -exec ls -D '%F' -l -t -r {} \; | grep 'kdeaccessibility-4.14.3_1'

什么都没有返回。我由此推断符号链接的存在导致了这种行为,但我不明白为什么。

bash find
  • 1 个回答
  • 47 Views
Martin Hope
Ginger
Asked: 2020-02-12 14:56:52 +0800 CST

crontab 无法从日志文件夹中删除旧文件

  • 0

我在我的 crontab 中有这一行来删除旧文件:

1 * * * * find /var/log/abc/ -mtime +7 -type f -delete

不幸的是,它不起作用。

我试图授予所有用户使用清除该文件夹的权限

chmod +777 /var/log/abc

但是 chmod 没有用。我还能尝试什么?


按照记录输出的建议,我发现这是在日志中:

/bin/sh: 1: find: not found

所以我想我需要正确设置我的路径......

cron chmod find
  • 1 个回答
  • 251 Views
Martin Hope
John
Asked: 2020-01-17 12:13:16 +0800 CST

使用 find、exec 和 cp 复制特定文件,同时保留目录路径

  • 0

我使用空文本文件设置了以下文件夹:

1/a.txt
2/b.txt

我只想将 txt 文件复制到另一个目录,同时保持它们的目录结构。所以我尝试了以下命令:

mkdir -p temp/s;
find ./ -name '*txt' -exec cp --parents '{}' ./temp/s \;

现在我从当前目录中看到以下文件:

1/a.txt
2/b.txt
temp/s/1/a.txt
temp/s/2/b.txt
temp/s/temp/s/2/b.txt

我不明白为什么最后一行会temp/s/temp/s/2/b.txt出现。有人可以向我解释为什么会发生这种情况以及如何修复我的命令以使其temp不嵌套在另一个命令中temp吗?

这是我期待的最终结果:

1/a.txt
2/b.txt
temp/s/1/a.txt
temp/s/2/b.txt
find
  • 1 个回答
  • 1039 Views
Martin Hope
user3200534
Asked: 2019-08-04 02:46:18 +0800 CST

如何将文件名作为前缀添加到文本文件的每一行?(批处理;子目录)

  • 3

我有许多 .txt 文件,它们的文件名是不同的日期:

01.01.2010.txt
02.01.2010.txt
...

目前每个文件(例如:01.01.2010.txt)看起来像这样:

  0.351  XXX  XXX  XXX  XXX
  0.292  XXX  XXX  XXX  XXX  

如何将文件名添加到文件的每一行并保持格式?

...所以它看起来像这样,对于文件 01.01.2010.txt:

  01.01.2010  0.341  XXX  XXX  XXX  XXX
  01.01.2010  0.122  XXX  XXX  XXX  XXX  

.. 对于文件 02.01.2010.txt,看起来像这样:

  02.01.2010  0.391  XXX  XXX  XXX  XXX
  02.01.2010  1.342  XXX  XXX  XXX  XXX  

这些文件存储在子目录中。如果有一个可以处理所有这些以及子目录的单行器,那就太棒了。

- /patch/to/file
 -/path/to/file/sub1/
 -/path/to/file/sub2/
 -/path/to/file/sub3/
find
  • 2 个回答
  • 1557 Views
Martin Hope
gogasca
Asked: 2018-11-13 23:13:52 +0800 CST

通过 Linux 命令更新所有 Python 文件

  • 0

在我的原始 Python 文件中,我有以下内容:

from official.utils.flags import _base

我需要将其更改为:

from utils.flags import _base

我的文件结构如下所示:

.
├── README.md
├── requirements.txt
├── setup.py
└── trainer
    ├── __init__.py
    ├── task.py
    ├── task_eager.py
    ├── dataset.py
    └── utils

我所有的 Python 文件都位于 utils 文件夹下。我试过了:

find . -type f -exec sed -i -e "s/from official./from /g" {} +

但我看到创建了一堆新文件:

test.py             test.py.py          test.py.py.py           test.py.py.py.py        test.py.py.py.py.py     test.py.py.py.py.py.py
test.py-e           test.py.py-e            test.py.py.py-e         test.py.py.py.py-e      test.py.py.py.py.py-e       test.py.py.py.py.py.py-e
find
  • 1 个回答
  • 38 Views
Martin Hope
David Eyk
Asked: 2018-03-29 07:32:59 +0800 CST

如果 -exec 命令失败,如何使 find 返回非 0?

  • 1

当我使用失败find的子命令运行命令时,返回退出代码:-execfind0

$ find . -iname '*.txt' -exec ls foo \;
ls: foo: No such file or directory
ls: foo: No such file or directory
ls: foo: No such file or directory
ls: foo: No such file or directory
ls: foo: No such file or directory
ls: foo: No such file or directory
ls: foo: No such file or directory
$ echo $?
0

如果它的任何子命令失败,有什么方法可以find失败吗?

find
  • 1 个回答
  • 384 Views

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    新安装后 postgres 的默认超级用户用户名/密码是什么?

    • 5 个回答
  • Marko Smith

    SFTP 使用什么端口?

    • 6 个回答
  • Marko Smith

    命令行列出 Windows Active Directory 组中的用户?

    • 9 个回答
  • Marko Smith

    什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同?

    • 3 个回答
  • Marko Smith

    如何确定bash变量是否为空?

    • 15 个回答
  • Martin Hope
    Tom Feiner 如何按大小对 du -h 输出进行排序 2009-02-26 05:42:42 +0800 CST
  • Martin Hope
    Noah Goodrich 什么是 Pem 文件,它与其他 OpenSSL 生成的密钥文件格式有何不同? 2009-05-19 18:24:42 +0800 CST
  • Martin Hope
    Brent 如何确定bash变量是否为空? 2009-05-13 09:54:48 +0800 CST
  • Martin Hope
    cletus 您如何找到在 Windows 中打开文件的进程? 2009-05-01 16:47:16 +0800 CST

热门标签

linux nginx windows networking ubuntu domain-name-system amazon-web-services active-directory apache-2.4 ssh

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve