简体   繁体   English

grep命令查找文件

[英]grep command to find files

I'm looking for a command that use grep to search in /usr/bin for all the files who have 2 links and sort them in ascending.我正在寻找一个命令,该命令使用 grep 在 /usr/bin 中搜索所有具有 2 个链接的文件并按升序对它们进行排序。

The second command I'm looking for must use the first one and display just the files that contain the "x"我正在寻找的第二个命令必须使用第一个命令并仅显示包含“x”的文件

Thanks you谢谢

You can do this direct from grep, eg:您可以直接从 grep 执行此操作,例如:

grep -r --include=*.py "HOSTS" .

will search recursively ('-r') under the current directory ('.') in all python files ('*.py') for the string "HOSTS".将在所有 python 文件 ('*.py') 中的当前目录 ('.') 下递归 ('-r') 搜索字符串“HOSTS”。

This would do这会做

find /usr/bin -links 2 -print0 | xargs -0 ls -adltr

modify the ls to do the sorting you require修改 ls 以进行您需要的排序

find /usr/bin -links 2 -print0 | xargs -0 grep -l "x"

Files containing the "x" :)包含“x”的文件:)


If you meant: 'contain the x' as 'are executable (x appears in ls -l output), use如果您的意思是:“包含 x”为“可执行”(x 出现在 ls -l 输出中),请使用

find /usr/bin -links 2 -executable -print0 | ls -adltr

To see only dirs:仅查看目录:

find /usr/bin -links 2 -type d -executable -print0 | ls -adltr

To see only files:仅查看文件:

find /usr/bin -links 2 -type f -executable -print0 | ls -adltr

Note: directories get 2 links by default ( . is a link) so you might want to look for -links 3 with directories注意:默认情况下,目录获得 2 个链接( .是一个链接),因此您可能需要查找带有目录的-links 3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用“grep”命令查找包含电话号码的txt文件 - use “grep” command to find txt files containing telephone number Grep命令在php文件中查找单个等号运算符 - Grep command for find single equal operator in php files 如何在Linux中使用grep查找包含特定命令的所有文件? - How to use grep in linux to find all files contain a specific command? GREP命令查找整个字符串 - GREP command to find whole strings 在linux命令行中使用find和grep来搜索具有特定用户和文本内容的文件? - Using find and grep in linux command line to search for files with a specific user and text content? 使用grep命令查找包含文本的文件以文件名charector开头 - Find files containing text using grep command starts with file name charector 移动具有特定修改日期的文件; “find | xargs ls | grep | -exec”失败,“-exec: command not found” - Moving files with a specific modification date; "find | xargs ls | grep | -exec" fails w/ "-exec: command not found" 如何从Linux ls的文件列表中grep内容或find命令 - How to grep contents from list of files from Linux ls or find command 如何使用`文件 | grep<string> ` 在查找命令中?</string> - How to use `file | grep <string>` in a find command? grep命令用于带有“ String1”而不是“ String2”的文件 - grep Command for Files with “String1” AND NOT “String2”
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM