2

I am trying to get a list of folders in my directory 'KEAX', and then dive into each one of them.

After entering each folder, I want to run the command:

foreach f(*.tar)
tar -xvf$f
end

After running this command, I want to back out, and then go into the next folder that is in 'KEAX' and run the same command as above. However, I am getting an error running the above command

Byte Commander
  • 105,631
  • 46
  • 284
  • 425
WX_M
  • 121
  • 2

1 Answers1

1

This command should work. It searches for all *.tar files in the current directory recursively and cds into its location in a Bash subshell and unpacks it there for each result:

find . -iname '*.tar' -exec bash -c 'cd "$(dirname "{}")" ; tar -xvf "$(basename "{}")"' \;
Byte Commander
  • 105,631
  • 46
  • 284
  • 425
  • If this answer solves your question, please consider accepting it by clicking the grey check button on its left. You can take the short [tour] to learn some basics about how our site works. Thanks and welcome to Ask Ubuntu. – Byte Commander Sep 27 '16 at 18:09