简体   繁体   English

Linux查找命令问题

[英]Linux find command questions

I do not have a working Linux system to try these commands out with so I am asking on here if what I am planning on doing is the correct thing to do. 我没有运行正常的Linux系统来尝试使用这些命令,因此我在这里询问我计划做的事情是否正确。 (Doing this while I am downloading an ISO via a connection that I think dial-up is faster). (在我通过拨号速度更快的连接下载ISO时执行此操作)。

1, I am trying to find all files with the .log extension in the /var/log directory and sub-directories, writing the standard out to logdata.txt and standard out to logerrors.txt 1,我试图在/ var / log目录和子目录中找到所有带有.log扩展名的文件,将标准输出写入logdata.txt,将标准输出写入logerrors.txt

I believe the command would be: 我相信命令将是:

$ find /var/log/ -name *.log 1>logdata.txt 2>/home/username/logs/logerrors.txt. $查找/ var / log / -name * .log 1> logdata.txt 2> /home/username/logs/logerrors.txt。

2, Find all files with .conf in the /etc directory. 2,在/ etc目录中找到所有带有.conf的文件。 standard out will be a file called etcdata and standard error to etcerrors. 标准输出将是一个名为etcdata的文件,而标准错误将为etcerrors。

$ find /etc -name *.conf 1>etcdata 2>etcerrors $ find / etc -name * .conf 1> etcdata 2> etcerrors

3, find all files that have been modified in the last 30 minutes in the /var directory. 3,在/ var目录中查找最近30分钟内已修改的所有文件。 standard out is to go into vardata and errors into varerrors. 标准的做法是进入vardata,将错误放入varerrors。

Would that be: 会是:

$ find /var -mmin 30 1>vardata 2>varerrors. $ find / var -mmin 30 1> vardata 2> varerrors。

Are these correct? 这些正确吗? If not what am I doing wrong? 如果不是,我在做什么错?

1, I am trying to find all files with the .log extension in the /var/log directory and sub-directories, writing the standard out to logdata.txt and standard out to logerrors.txt 1,我试图在/ var / log目录和子目录中找到所有带有.log扩展名的文件,将标准输出写入logdata.txt,将标准输出写入logerrors.txt

Here you go: 干得好:

find /var/log/ -name '*.log' >logdata.txt 2>/home/username/logs/logerrors.txt

Notes: 笔记:

  • You need to quote '*.log', otherwise the shell will expand them before passing to find . 您需要引用'* .log',否则shell将在传递给find之前将其展开。
  • No need to write 1>file , >file is enough 无需写1>file>file就足够了

2, Find all files with .conf in the /etc directory. 2,在/ etc目录中找到所有带有.conf的文件。 standard out will be a file called etcdata and standard error to etcerrors. 标准输出将是一个名为etcdata的文件,而标准错误将为etcerrors。

As earlier: 如前所述:

find /etc -name \*.conf >etcdata 2>etcerrors

Here I escaped the * another way, for the sake of an example. 为了举例,在这里我以另一种方式逃脱了* This is equivalent to '*.conf' . 这等效于'*.conf'

3, find all files that have been modified in the last 30 minutes in the /var directory. 3,在/ var目录中查找最近30分钟内已修改的所有文件。 standard out is to go into vardata and errors into varerrors. 标准的做法是进入vardata,将错误放入varerrors。

find /var -mmin -30 >vardata 2>varerrors

I changed -mmin 30 to -mmin -30 . 我将-mmin 30更改为-mmin -30 This way it matches files modified within 30 minutes. 这样,它可以匹配30分钟修改的文件。 Otherwise it matches files were modified exactly 30 minutes ago. 否则,它匹配的文件恰好在30分钟前被修改。

When using wildcards in the command, you need to make sure that they do not get interpreted by the shell. 在命令中使用通配符时,需要确保外壳程序不会解释通配符。 So, it is better to include the expression with wildcards in quotes. 因此,最好在引号中包含通配符的表达式。 Thus, the first one will be: 因此,第一个将是:

find /var/log/ -name "*.log" 1>logdata.txt 2>/home/username/logs/logerrors.txt

Same comment on the second one where you should have "*.conf" . 对于第二个相同的注释,应该在其中具有"*.conf"

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM