Blog

Print Out File Names and Replace Strings in Directory Using Linux Shell
Posted on February 8, 2012 in Linux by Matt Jennings

Print Out File Names in a Directory

  1. Navigate to the folder you want using cd.
  2. While inside the folder you want enter ls > filenames.txt and press enter. A file named filesname.txt will be created in the directory you are in listing all file names in that directory.

Replace Strings in Directory Using Linux Shell

Inside a directory, enter:
[apache]grep -rl ‘about-us.html’ ./ | xargs sed -i ‘s/about-us.html/about-us.php/g'[/apache]

This replaces an about-us.html string with about-us.php.

Leave a Reply