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


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.


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?.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.