bash - Running a command in multiple directories -


i running command in 1 of many subdirectories:

ls *.rst -c1 -t | awk 'nr>1' | xargs rm 

essentially, lists files end .rst , sort them based on time created , want created file. delete rest of *.rst files.

i have 200 directories need execute command in. have tried using find command pass location of directories command have not been successful. of these directories contain files inputs.in. have tried:

find . -name inputs.in | xargs ls *.rst -c1 -t | awk 'nr>1' | xargs rm 

but believe since input ls *.rst bit full path including file name, has not been working.

i'm sure it's quick fix , comments appreciated. run command parent directory. thanks!

some ugly way:

find . -name inputs.in | xargs dirname |                     \      xargs -i{} -n 1 find {} -name '*.rst' | xargs ls -c1 -t |    \      awk 'nr>1' | xargs rm 

ls wildcard fail because globbing happens before find executed.


Comments

Popular posts from this blog

java - Jmockit String final length method mocking Issue -

What is the difference between data design and data model(ERD) -

ios - Can NSManagedObject conform to NSCoding -