gpt4 book ai didi

ftp - 使用ncftp删除文件夹中所有文件和文件夹的命令

转载 作者:行者123 更新时间:2023-12-04 14:38:31 38 4
gpt4 key购买 nike

我在远程服务器上有一个需要清除的文件夹。我需要删除此文件夹中的所有文件和文件夹。我无法删除和重新创建父文件夹,因为我不想弄乱权限。

例如:
远程文件夹是 Development/
该文件夹包含多个文件和多个文件夹。
我想运行一个命令来完全清空 Development/文件夹并给我一个新的空版本。

我还需要它与 Windows FTP 客户端兼容。

最佳答案

由于您澄清您不限于 ncftp,您应该使用 lftp相反,它内置了对使用 glob 之类的操作的支持。和 rm -r .这是一个完整的演示:

~/ftptest$ find .    # Test folder with a number of files and directories in it.
.
./dir1
./dir1/subdir1
./dir1/subdir1/subsubfile1
./dir1/subfile1
./dir2
./file1
./file2

~/ftptest$ lftp localhost # Connect
Password:
lftp blahdiblah@localhost:~> cd ~/ftptest/ # cd to test folder
cd ok, cwd=/Users/blahdiblah/ftptest

lftp blahdiblah@localhost:~ftptest> ls # The files are there...
total 0
drwxr-xr-x 4 blahdiblah staff 136 Jul 30 15:40 dir1
drwxr-xr-x 2 blahdiblah staff 68 Jul 30 15:40 dir2
-rw-r--r-- 1 blahdiblah staff 0 Jul 30 15:40 file1
-rw-r--r-- 1 blahdiblah staff 0 Jul 30 15:40 file2

lftp blahdiblah@localhost:~/ftptest> glob -a rm -r * # the magic happens...
rm ok, 7 files removed

lftp blahdiblah@localhost:~/ftptest> bye
~/ftptest$ find . # ...and then they're gone!
.
~/ftptest$

The docs给出完整的解释:

rm [-r] [-f] files

Remove remote files. Does not expand wildcards, use mrm for that. -r is for recursive directory remove. Be careful, if something goes wrong you can lose files. -f suppress error messages.

glob [-d] [-a] [-f] command patterns

Glob given patterns containing metacharacters and pass result to given command. E.g.
glob echo *

-f plain files (default)
-d directories
-a all types



(请注意, mrm 在这种情况下不可用,因为它不会扩展 * 以包含目录。)

关于ftp - 使用ncftp删除文件夹中所有文件和文件夹的命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11692928/

38 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com