-1

Task: Write a script that will copy subdirectories (and all files inside) from directory A to directory B. Only directories containing pdf, tif, jpg files should be copied. The whole parent directory with subdirectories and files should be copied. The directory names may contain service symbols. Problem: I don't know how to specify the parent directory instead of the current directory.

#!/bin/bash
IFS=$'/n'

#mentioning to move the string as a delimiter instead of a space

for file -name "*.pdf" -o "*.tif" -o "*.jpg" in catalog_A/*

#loop "for" for files with a name ending in ".pdf" or ".tif" or ".jpg" in directory A 

do 

#loop body

echo $(pwd) 

#current absolute path output

dirname="$dirname"

#upload the name of the current directory for a holistic view of its name, which may contain system symbols

cp -a . catalog_B/

#copy the current directory with attached files to directory B

done

#end of cycle
  • 1
    I suggest to tackle the task in small steps. At the moment, your script has syntax errors and won't work as you expected. Don't try solve the next step if the previous steps are not solved yet. Start by fixing the loop. Once you have everything, you can access the parent directory of `path` using `path/..`. – Socowi Jun 04 '20 at 10:47

2 Answers2

0

Use command "foldername" to get parent directory of a file

Saran Brar
  • 147
  • 1
  • 1
  • 8
0

./ is your current directory and ../ is the parent directory of your current directory.

I think you should change the cp -a . catalog_B/ with cp -a ../ catalog_B/