I am attempting to run a program that looks through a group of folders, and finds a type of file inside them. The format of the files is this
MAIN
SUBDIR01
FILE01.TXT
FILE02.TXT
SUBDIR02
FILE03.TXT
FILE04.TXT
The problem is that there are many files and many directories that the program runs through. And, as it was written, the program searches for .txt files. Being case-sensitive it finds none. The simple workaround I had was to re-write the program to search for .TXT and problem solved. I also have found that "rename" and "mv" can be used to rename files in bulk if I am located in the directory in which they are contained. But, have not found a way for me to be in the MAIN directory and have the bulk change go through a group of folders.
The closest thing I've found is find . -name "*.TXT" will print all of them out.
I feel like I'm pretty close, so I was wondering if anyone might off-hand know of a solution to this issue. Not using the above work around. Thank you for your help.
You can use find
to locate the files and print the names and then use xargs
in combination with rename
to do the actual renaming. To avoid problems with file and directory names containing spaces you should use -print0
instead of -print
with find and add -0' to the
xargs` command line. See the example below.
find . -name '*.TXT' -print0 | xargs -0 rename 's/.TXT/.other/'