【问题标题】:-f unknown option bash-f 未知选项 bash
【发布时间】:2014-02-28 19:54:34
【问题描述】:

我正在尝试编写一个简短的函数,该函数将从主目录转到特定文件夹,然后查找过去几天访问过的所有文件。

function restore5 {
    cd /Volumes/FTP/RESTORES
    find . type -f -atime +5 | less
}

当我运行此函数时,我收到一条错误消息:find: -f: unknown option。 当我手动键入命令时,我没有收到此错误代码,所以我很想知道我错过了什么?

此外,如果我想对此进行扩展并在函数末尾添加一个如果不成功的类型命令,将“| |”是更合适的命令吗?我的想法是这样的:

| | echo "No files found"

【问题讨论】:

  • 我倾向于通过管道查找 wc -l 并对结果进行数字测试以显示消息

标签: macos bash


【解决方案1】:

应该是find . -type f -atime +5 | less

【讨论】:

    【解决方案2】:

    你不应该使用

    find . - type f -atime +5 | less
    

    从 find 的手册页中提取:

      -type c
              File is of type c:
    
              b      block (buffered) special
    
              c      character (unbuffered) special
    
              d      directory
    
              p      named pipe (FIFO)
    
              f      regular file
    
              l      symbolic link; this is never true if the -L option or the -follow option is in effect, unless the symbolic link is broken.  If you
                     want to search for symbolic links when -L is in effect, use -xtype.
    
              s      socket
    
              D      door (Solaris)
    

    【讨论】:

      【解决方案3】:

      查看手册以查找 type 命令的语法是 -type f 尝试使用它而不是您的 。输入-f

      不确定您是否正在使用 做某事。输入我看不懂,但希望对您有所帮助。

      【讨论】:

        猜你喜欢
        • 2012-05-03
        • 2014-09-02
        • 1970-01-01
        • 2018-03-29
        • 2021-01-17
        • 2012-08-18
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多