我試圖在大於給定數字的輸出的第一個字段中grep行。在這種情況下,該號碼是755
。最終,我在做的是試圖通過使用stat -c '%a %n' *
列出每個文件的權限大於(並且不等於)755
,然後管道到grep'ing(或可能sed'ing?)以獲得最終列表。任何想法如何最好地完成?對於大於給定數字的數字的grep行
回答
試試這個:
stat -c '%a %n' *|awk '$1>755'
,如果你只是想在你的最終輸出的文件名,跳過權限數字,你可以:
stat -c '%a %n' *|awk '$1>755{print $2}'
編輯
其實你可以在awk中執行chmod
。但你應該確保用戶執行的awk行有權修改這些文件。
stat -c '%a %n' *|awk '$1>755{system("chmod 755 "$2)}'
再次假設文件名沒有空格。
噢,感謝那個小插件。我只是想削減場地2,但是你的場地只需一個管道就可以完成! – user2150250 2013-04-30 22:35:36
注意帶空格的文件名。 – 2013-04-30 22:37:21
@ user2150250注意,我的第二個awk單行假定你的文件名沒有空格。 – Kent 2013-04-30 22:38:05
我會使用awk(1)
:第一個字段是大於755,如果你想打印線或一些不同的子集,你可以添加一個動作
stat -c '%a %n' * | awk '$1 > 755'
的awk
模式匹配線, (請參閱@肯特的答案)。
grep
和sed
都不擅長算術。 awk
可以幫助(不幸的是我不知道它)。但請注意,find
都能得心應手這裏,太:
-perm mode
File's permission bits are exactly mode (octal or symbolic).
Since an exact match is required, if you want to use this form
for symbolic modes, you may have to specify a rather complex
mode string. For example -perm g=w will only match files which
have mode 0020 (that is, ones for which group write permission
is the only permission set). It is more likely that you will
want to use the `/' or `-' forms, for example -perm -g=w, which
matches any file with group write permission. See the EXAMPLES
section for some illustrative examples.
-perm -mode
All of the permission bits mode are set for the file. Symbolic
modes are accepted in this form, and this is usually the way in
which would want to use them. You must specify `u', `g' or `o'
if you use a symbolic mode. See the EXAMPLES section for some
illustrative examples.
-perm /mode
Any of the permission bits mode are set for the file. Symbolic
modes are accepted in this form. You must specify `u', `g' or
`o' if you use a symbolic mode. See the EXAMPLES section for
some illustrative examples. If no permission bits in mode are
set, this test matches any file (the idea here is to be consis‐
tent with the behaviour of -perm -000).
那麼什麼可以爲你工作是:
find . -perm -755 -printf '%m %p\n'
只需卸下-printf
的一部分,如果你只需要文件名。
- 1. 從數組中計算等於或大於給定數字的數字
- 2. 查找給定BST中小於給定數字(n)的最大數字
- 3. 刪除任何其數值大於給定數字的屬性
- 4. 數字大於2的複數字PHP
- 5. 數字大於浮點數
- 6. jQuery的選擇器ID,類,相對等,其中值大於給定的數字
- 7. Csvwrite的數字大於7位數
- 8. Can Kinosearch可以對「大於」等數字進行數學比較?
- 9. 查找比數組給定數字的比較大的數字
- 10. 陣列中有多少數字小於給定數字?
- 11. SQL - 基於字段中特定數字值的行數
- 12. 的TeeChart:舍入數字例外對於非常大的數據
- 13. 字節數組大於255
- 14. 要查找字典順序大於給定的字符串
- 15. 對於給定數組大小爲N的三個數的最大乘積
- 16. 球拍函數返回所有總和小於給定數字的數字嗎?
- 17. 遞歸 - 返回一個數字大於參數的新數字
- 18. 給定行的列值大於0的數量?
- 19. 無法獲得基於給定整數的字符數組
- 20. 大於2位的數字總和的數字
- 21. JQuery不驗證大於9999的數字
- 22. VBScript和大於Long的數字
- 23. RewriteRule檢測大於9的數字
- 24. 乘以兩個大於255的數字
- 25. 關於大數字聚集的錯誤
- 26. Convert.ToBase64String()與大於255的數字
- 27. 什麼是在MySQL快,對數字列等於或大於?
- 28. 數量大於給定的整數數組鄰居
- 29. R:數字級別並分配給新列,對於大數據集
- 30. VBA中2位數字大於3位數字的問題
由於'755'實際上是一個代表比特序列的八進制數,「大於」意味着什麼? '666'給大家寫入權限;是「大於」'755'? 「755」大於「666」嗎? – 2013-05-01 00:04:31
OS X用戶:相當於'stat -c'%a%n'*'(Linux)似乎是'stat -f'%Lp%N'*' – mklement0 2013-05-01 03:11:04
該人要求grep,而人們仍然給予AWK? – Soncire 2014-01-23 04:27:51