Monday, May 6, 2024
 Popular · Latest · Hot · Upcoming
7
rated 0 times [  7] [ 0]  / answers: 1 / hits: 7591  / 2 Years ago, sat, august 27, 2022, 9:23:36

I need to find all .nfo files in my media directory so I can use sed to change some parts. The problem is my folders have spaces in the names.



find  /media/media1/HDTV -name  *.nfo -type f 
media/media1/HDTV/Band of Brothers/Season 1/



The output file won't found by a sed command to change the strings I want.


More From » find

 Answers
3

find doesn't care about special characters in file names, but the program that's parsing the output of find might. If you're using xargs, use the -print0 option to find, and the -0 option to xargs. This tells find and xargs to use null characters (which cannot appear in file names) as a separator between file names, and xargs not to do any other parsing which would mangle file names containing spaces.



find /media/media1/HDTV -name '*.nfo' -type f -print0 |
xargs -0 sed -i 's/pattern/replacement/'


Another way to invoke a command on many files is to use find only.



find /media/media1/HDTV -name '*.nfo' -type f -exec sed -i 's/pattern/replacement/' {} +

[#37752] Sunday, August 28, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
eaderitable

Total Points: 368
Total Questions: 117
Total Answers: 111

Location: Tuvalu
Member since Sat, Feb 11, 2023
1 Year ago
;