简体   繁体   English

搜索和替换文件(Linux)

[英]Search and replace files (Linux)

I'm quite new to Linux. 我对Linux很陌生。 I'm using Linux Mint and I've just found a situation where I have a file which exists multiple times inside the tree/folders of a folder. 我正在使用Linux Mint,但刚刚发现一种情况,我的文件在文件夹的树/文件夹中存在多次。 I want to replace all occurrences of this file with a new version of it. 我想用新版本替换所有出现的文件。 So instead of looking for that file once and again and replacing it with the new one, I wonder if there is any kind of search & replace command for files. 因此,我想知道是否存在某种针对文件的搜索和替换命令,而不是一次又一次地寻找该文件并将其替换为新文件。

I've already searched for a similar question in stackoverflow, but I was only able to find commands to search & replace TEXT in files, not the file itself. 我已经在stackoverflow中搜索了类似的问题,但是我只能找到用于搜索和替换文件中TEXT的命令,而不是文件本身。

Can anyone please point me to the right direction? 谁能指出我正确的方向?

Thank you. 谢谢。

you can always do it in parts, like: 您可以始终按部分进行操作,例如:

  1. Get a list of items matching your search. 获取与您的搜索匹配的项目列表。
  2. Replace every match (using mv for example) with your file. 用文件替换每个匹配项(例如,使用mv)。

something like: 就像是:

foreach dir ( `ls | egrep '^(i686\|amd64)\.'` )
   mv yourfile $dir
end

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

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