- 只是要找文件时,find 很好用
- 但是当要删文件时,如果
-exec rm -vrf {} \;
,
The problem with-exec rm -r {}
is thatfind
tries doesn't know that the command deletes the file, so it throws an error when it tries to recurse into the directory. 会存在删了父再访问子的问题。方法是 -depth 设定遍历顺序。
- 如果用
-delete
,它会默认 rmdir, 提示非空不能删。
一个方法是
find -type f -delete
再 find -type d -empty -delete
打包时可以用 /dev/stdin 当输入,然后 install -Dm755 直接输出到 shell 里,一步完成输入内容 + 设定权限。
^ by chatGPT
删除时只删 f 不删 d 可以避免父子问题。用 -not -path 保留某个 folder
install -Dm755 /dev/null $pkgdir/usr/bin/rubick2 echo "#!/bin/bash" >$pkgdir/usr/bin/rubick2 echo "electron13 /opt/rubick2/resources/app.asar" >>$pkgdir/usr/bin/rubick2 make these 3 line of code shorter.but it's not exectuablecan it be in one command?use install -Dm755
then chatGPT gives what I want.
有时我们想对整个 find 出的文件做一些事. 比如覆盖内容, 这时不能用 >
重定向会作用在 find 而不是 -exec 后的 bin 上.
解决方法是
这里可以用 bash -c + {} , 但是我被引号转义搞烦了.
清空文件可以
ref
居然还惊动了一位 700k 的史前大佬解答问题.