There are many folders that are in a specific directory. In these folders, I look for files with a specific extension, *.txt for example. The task is to find those folders in which there is at least one txt file and copy this folder to another directory, for example txtfiles . I tried to just find a file and archive with the command
tar cf txts.tar `find /root/test/1/ -name '*.txt' ` But it adds only txt files to the archive, but I need a full copy of the folder with them (if txt is in /root/test/1/2/3/path /root/txtfiles /root/test/1/2/3/path , then I need to copy the whole folder 1 into /root/txtfiles from all files and directories attached to it).
|) say sed, which cut the beginning of the path to the desired depth (say, focusing on/). send all this to sort and uniq to get all the folders exactly one time - Mike