1

I have a directory, and it has many sub-directories.

home/folderA/*
home/folderB/*

What I want to do is to delete all lines that have certain text 'password' in files in each sub-directory.

sed -i '/password/d' *

this command can only work with files and can't go inside directories. I'd be thankful for any advice in how to do this.

muru
  • 197,895
  • 55
  • 485
  • 740
Thwe
  • 13

1 Answers1

0

I would use find with sed like:

find /path/to/source -type f -exec sed '/password/d' {} +

Add -i to sed -i '/password/d' above to write the changes into files in place.

  • the /path/to/source is your directory path that you want to run sed for the files in and its sub-directories.
  • the -type f looks for the files type only.
  • with -exec command {} +, the command will be executed for the files found.

See and read also What is the difference between using '+' (plus) and ';' (semicolon) in -exec command?.

αғsнιη
  • 35,660