我发现自己不断地查找语法
find . -name "FILENAME" -exec rm {} \;
Run Code Online (Sandbox Code Playgroud)
主要是因为我不明白这-exec部分是如何工作的。大括号、反斜杠和分号的含义是什么?该语法还有其他用例吗?
我正在AAA使用以下命令搜索名称包含在其路径中的文件:
find path_A -name "*AAA*"
Run Code Online (Sandbox Code Playgroud)
鉴于上述命令显示的输出,我想将这些文件移动到另一个路径,例如path_B. 我可以通过在 find 命令之后立即移动这些文件来优化命令,而不是一个一个地移动这些文件吗?
我正在 WD My Book World Edition 上通过 SSH 工作。基本上我想从特定的目录级别开始,并递归地删除所有匹配.Apple*. 我该怎么做?
我试过
rm -rf .Apple* 和 rm -fR .Apple*
都没有删除子目录中与该名称匹配的目录。
我以某种方式设法创建了一个似乎没有文件名的文件。我在以下线程中找到了一些有关如何获取文件的更多详细信息的信息。
但是,我尝试了列出的一些建议,但似乎无法删除该文件。我不确定我做了什么来创建它,但是在尝试复制 xml 文件时发生了。
该文件的一些信息如下;
> ls -lb
total 296
-rw-r--r-- 1 voyager endeavor 137627 Jan 12 12:49 \177
> file *
: XML document
> ls -i
417777
Run Code Online (Sandbox Code Playgroud)
我试图找到使用 inum 开关,然后将其通过管道传递给 rm,因为这似乎是摆脱它的最简单的方法。但是,下面链接的线程底部给出的示例对我来说失败了。例子是:
> find -inum 41777 -exec ls -al {} \;
find: illegal option -- i
find: [-H | -L] path-list predicate-list
Run Code Online (Sandbox Code Playgroud)
所以我首先尝试使用路径列表,如下所示,但这也不起作用:
> find . -inum 41777 -exec ls -al {} \;
Run Code Online (Sandbox Code Playgroud)
我不确定不可打印的字符 \177 是什么,或者我如何将它传递给rm命令,但我真的想确保我在尝试删除此文件时不会弄乱任何其他文件/目录。
我有一个 bash 脚本循环查找的结果并执行一些 FLV 文件的 ffmpeg 编码。虽然脚本正在运行 ffmpeg 输出似乎被中断,并且正在输出一些看起来很奇怪的错误,如下所示。我不知道这里发生了什么。任何人都可以指出我正确的方向吗?
就好像循环在不应该运行时仍在运行并中断了 ffmpeg 进程。
具体错误是:
frame= 68 fps= 67 q=28.0 00000000000000000000000000001000size= 22kB time=00:00:00.50 bitrate= 363.2kbits/s dup=1 drop=0
Enter command: <target> <time> <command>[ <argument>]
Parse error, at least 3 arguments were expected, only 1 given in string 'om/pt_br/nx/R3T4N2_HD3D_demoCheckedOut.flv'
Run Code Online (Sandbox Code Playgroud)
ffmpeg 输出的更多细节:
[buffer @ 0xa30e1e0] w:800 h:600 pixfmt:yuv420p tb:1/1000000 sar:0/1 sws_param:flags=2
[libx264 @ 0xa333240] using cpu capabilities: MMX2 SSE2Fast SSSE3 FastShuffle SSE4.1 Cache64
[libx264 @ 0xa333240] profile High, level 3.1
[libx264 @ 0xa333240] 264 - …Run Code Online (Sandbox Code Playgroud) 我有一个包含崩溃日志的目录,我想在基于 find 命令的 bash 脚本中使用条件语句。
日志文件以这种格式存储:
/var/log/crashes/app-2012-08-28.log
/var/log/crashes/otherapp-2012-08-28.log
Run Code Online (Sandbox Code Playgroud)
我希望 if 语句仅在特定应用程序的崩溃日志在过去 5 分钟内被修改时才返回 true。find我会使用的命令是:
find /var/log/crashes -name app-\*\.log -mmin -5
Run Code Online (Sandbox Code Playgroud)
我不确定如何将其if正确地合并到声明中。我认为这可能有效:
if [ test `find /var/log/crashes -name app-\*\.log -mmin -5` ] then
service myapp restart
fi
Run Code Online (Sandbox Code Playgroud)
有几个地方我不清楚:
test指令,还是应该直接针对 find 命令的结果进行处理,或者可能用于find... | wc -l获取行数?test为了测试命令返回的返回码?而且它们有点不可见 - 在stdout/之外stderr?我阅读了该man页面,但我仍然不清楚何时使用test以及如何调试它。我创建了以下脚本,将定义的旧文件从源目录移动到目标目录。它运行良好。
#!/bin/bash
echo "Enter Your Source Directory"
read soure
echo "Enter Your Destination Directory"
read destination
echo "Enter Days"
read days
find "$soure" -type f -mtime "-$days" -exec mv {} "$destination" \;
echo "Files which were $days Days old moved from $soure to $destination"
Run Code Online (Sandbox Code Playgroud)
这个脚本移动文件很好,它也移动源子目录的文件,但它不会在目标目录中创建子目录。我想在其中实现这个附加功能。
举例
/home/ketan : source directory
/home/ketan/hex : source subdirectory
/home/maxi : destination directory
Run Code Online (Sandbox Code Playgroud)
当我运行这个脚本时,它也会在 maxi 目录中移动十六进制的文件,但我需要在 maxi 目录中创建相同的十六进制并将其文件以相同的十六进制移动到那里。
我有一个目录,我想在其中列出所有内容(文件和子目录)而不显示符号链接。我在 Linux 上使用 GNU 实用程序。该ls版本是8.13。
例子:
完整目录列表:
~/test$ ls -Gg
total 12
drwxrwxr-x 2 4096 Jul 9 10:29 dir1
drwxrwxr-x 2 4096 Jul 9 10:29 dir2
drwxrwxr-x 2 4096 Jul 9 10:29 dir3
-rw-rw-r-- 1 0 Jul 9 10:29 file1
-rw-rw-r-- 1 0 Jul 9 10:29 file2
lrwxrwxrwx 1 5 Jul 9 10:29 link1 -> link1
lrwxrwxrwx 1 5 Jul 9 10:30 link2 -> link2
Run Code Online (Sandbox Code Playgroud)
我想得到什么
~/test$ ls -somthing (or bash hack)
total 12
dir1 dir2 dir3 file1 …Run Code Online (Sandbox Code Playgroud) 我目前最好的选择是:
for i in $(find . -name *.jpg); do echo $i; done
Run Code Online (Sandbox Code Playgroud)
问题:不处理文件名中的空格。
注意:我也喜欢这样做的图形方式,例如“树”命令。
我想写一个bash脚本把.pdf当前目录下的每个文件都转换成一个.png文件。例如:
$ls .
a.pdf b.pdf
$./pdf2png.sh
Converting pdfs to pngs
a.pdf -> a.png
b.pdf -> b.png
Run Code Online (Sandbox Code Playgroud)
这是我最好的尝试:
#!/bin/bash
convert -verbose -density 500 -resize '800' a.pdf a.png
convert -verbose -density 500 -resize '800' b.pdf b.png
Run Code Online (Sandbox Code Playgroud)