-1
我在Linux上我想知道如何在目錄中找到最新的可執行文件? 我已經知道如何找到最新的搭配:如何在目錄中找到最新的可執行文件
ls -rt1 | tail -1
但如何過濾掉可執行文件?
編輯: 我發現了一個解決方案:
find path/to/dir/myfile* -perm /u=x,g=x,o=x -mtime 0 | tail -1
是該救?還是有更好的解決方案?
我在Linux上我想知道如何在目錄中找到最新的可執行文件? 我已經知道如何找到最新的搭配:如何在目錄中找到最新的可執行文件
ls -rt1 | tail -1
但如何過濾掉可執行文件?
編輯: 我發現了一個解決方案:
find path/to/dir/myfile* -perm /u=x,g=x,o=x -mtime 0 | tail -1
是該救?還是有更好的解決方案?
鑑於基本find
命令查找開始在當前目錄下的文件:
find . -type f
讓我們添加的功能:
要找到可執行文件,你可以使用-executable
選項:
find . -type f -executable
只是發現深度的一個水平,即不包含子目錄,使用-maxdepth 1
選項:
find . -maxdepth 1 -type f
要在目錄中找到最後修改的文件,你可以使用How to recursively find the latest modified file in a directory?:
find . -type f -printf '%[email protected] %p\n' | sort -n | tail -1 | cut -f2- -d" "
一起,這尋找最後修改的可執行文件在一個級別的深度:
find . -maxdepth 1 -type f -executable -printf '%[email protected] %p\n' | sort -n | tail -1 | cut -f2- -d" "
好吧,但我想獲得特定目錄的** latest **可執行文件,而不是所有的可執行文件。我發現了一個解決方案,我添加到我的文章看看編輯說明。我想問問這是保存還是有更好的解決方案 – user1895268 2014-09-03 14:41:17
您是否閱讀完整的答案? Last命令返回一個文件,你只需要替換'find/your/dir'的'find .'。 – fedorqui 2014-09-03 14:42:24
@downvoter:介意指出什麼是錯誤或不準確? – fedorqui 2014-09-03 14:46:58