按月/年来压缩许多文件组,并在Ubuntu上进行修改/创建

发布于 2025-02-12 15:18:02 字数 910 浏览 1 评论 0原文

现在,我使用Ubuntu服务器的SFTP服务有很多文件,并且占用了太多空间:

-rwxrwxrwx 1 systemd-network systemd-journal    7190 Jul  1  2020 'document_1.xlsx'
-rw-r--r-- 1 systemd-network systemd-journal    1606 Jul  1  2021 'document_1.csv'
-rw-r--r-- 1 systemd-network systemd-journal    7191 Jul  1  2021 'document_2.xlsx'
-rw-r--r-- 1 systemd-network systemd-journal    1606 Jul  1 03:10 'document_2.csv'
-rw-r--r-- 1 systemd-network systemd-journal    7191 Jul  1 03:10 'document_3.xlsx'
-rwxrwxrwx 1 systemd-network systemd-journal    1606 Aug  1  2020 'document_3.csv'
-rwxrwxrwx 1 systemd-network systemd-journal    7190 Aug  1  2020 'document_4.xlsx'
-rw-r--r-- 1 systemd-network systemd-journal    1606 Aug  1  2021 'document_4.csv'

现在我想要服务器的最佳空间,但我无法删除这些空间。 如果可以更好地通过 filetype和/或月/年来压缩,以及/或修改/创建和/或删除

例子:

document_2021.gzip
document_2021_csv.gzip

I've a SFTP service using ubuntu server now it have many files and take too many space like:

-rwxrwxrwx 1 systemd-network systemd-journal    7190 Jul  1  2020 'document_1.xlsx'
-rw-r--r-- 1 systemd-network systemd-journal    1606 Jul  1  2021 'document_1.csv'
-rw-r--r-- 1 systemd-network systemd-journal    7191 Jul  1  2021 'document_2.xlsx'
-rw-r--r-- 1 systemd-network systemd-journal    1606 Jul  1 03:10 'document_2.csv'
-rw-r--r-- 1 systemd-network systemd-journal    7191 Jul  1 03:10 'document_3.xlsx'
-rwxrwxrwx 1 systemd-network systemd-journal    1606 Aug  1  2020 'document_3.csv'
-rwxrwxrwx 1 systemd-network systemd-journal    7190 Aug  1  2020 'document_4.xlsx'
-rw-r--r-- 1 systemd-network systemd-journal    1606 Aug  1  2021 'document_4.csv'

Now I want optimal space of server but I can't delete those.
If better can we compress by filetype and/or month/year and/or modification/creation and/or delete.

Example:

document_2021.gzip
document_2021_csv.gzip

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

作业与我同在 2025-02-19 15:18:03

您提供了多个解决方案的选项,因此,这是第一个选项的简单选择 - 通过FileType压缩文件。
当然,在运行重要的文件之前,请测试示例文件上的任何命令。另外,在执行此类操作之前,请务必备份。但是你已经知道了。
您可以使用要处理的目录中的以下命令来按键入压缩每个文件:

    find ./ -type f -name "*.xlsx" -exec gzip {} ;

如果需要用\ \;或简单
结果将压缩您的文件,例如document_1.xlsx.gz,document_2.xlsx.gz,等等。

You gave multiple options for a solution, so here's a simple one for the first option - To compress files by filetype.
Of course, please test any commands on sample files before running on your important ones. Also, always have a backup before doing anything like this. But you already knew that.
You can compress each file by type using the following command from the directory you want to work on:

    find ./ -type f -name "*.xlsx" -exec gzip {} ;

Depending on how your shell is set up, if you need to end the command with \; or simply ;
The result will compress your files in place, like document_1.xlsx.gz, document_2.xlsx.gz, etc.

绮烟 2025-02-19 15:18:03

是的,您可以通过与分离符分开来在查找之后串起多个-Exec命令。
在此示例中,我首先找到了带有.csv扩展名的所有文件。然后,使用-du(磁盘使用率)获取尺寸,然后使用较长的列表。

    find ./ -type f -name "*.csv" -exec du -sh {}; -exec ls -l {};

您提到可能使用这样的RM,我会在一串-Exec命令中使用RM高度劝阻。
仅仅因为您不希望RM如果以前的命令失败。因此,这将是有风险的。

我很少执行多个-Exec命令。为了将许多命令串在一起,我更有可能在Python中这样做。但是,如果只做几个命令,我只为我想要的每个命令运行一个单独的命令。这可以在运行下一个命令之前检查一个命令的结果。

您要一起运行的特定命令是什么?

Yes, you can string multiple -exec commands after the find by separating with semicolons.
In this example, I first find all files with .csv extension. Then, get their size with -du (disk usage), followed by a long listing.

    find ./ -type f -name "*.csv" -exec du -sh {}; -exec ls -l {};

You mentioned possibly using rm like this, and I would highly discourage using rm in a string of -exec commands.
Only because you wouldn't want the rm to happen if the previous command failed. So that would be risky.

I rarely do multiple -exec commands. For stringing many commands together, I'd more likely do that in Python. But if doing just a few commands, I'd just run a separate command for each one I wanted. That allows a chance to inspect the result of one command before running the next.

What would be the specific commands you are wanting to run together?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文