replacing folder icon of all sub directories with a given/matching name - using cp xargs and find commands
by MDM-Pen from LinuxQuestions.org on (#558MR)
Hi all. I need some help with the cp, xargs, and find commands.
I have a large directory tree, and I would like to replace the folder icon of all the directories in the tree whose name matches "Target Dir" (theoretical name of course but white spaces are, indeed, present in the folder names of my real world case). The "Target Dir" folders are scattered at various levels throughout the tree. For Example:
Parent Directory/
Sub Directory 1/Sub Sub Directory A/Target Dir/
Sub Directory 1 (again)/Sub Sub Directory B/Sub Sub Sub Directory 001/Target Dir/
Sub Directory 2/Target Dir/
Sub Directory 3/Sub Sub Directory A/Sub Sub Sub Directory 001/Sub Sub Sub Sub Directory AAA/Target Dir/
What I would like to do is take an existing .directory file (a hidden file, always named ".directory", that points to the icon graphic I want to use and replaces the default folder icon of any directory it is sitting in), and copy it in to all of the "Target Dir" folders throughout the directory hierarchy. After much research, I've figured out that I probably need to use some combination of the find, grep, xargs, and cp commands but, as a relative noob, I'm having a hard time putting this all together (especially because the directory names throughout my tree have white space in the names - which confuses xargs. I'm also not particularly strong at manipulating string variables and wildcards yet).
Would any of you kind folks be able to suggest a command template/example that would help me replace all of those "Target Dir" folder icons?
Thanks in advance, everyone!


I have a large directory tree, and I would like to replace the folder icon of all the directories in the tree whose name matches "Target Dir" (theoretical name of course but white spaces are, indeed, present in the folder names of my real world case). The "Target Dir" folders are scattered at various levels throughout the tree. For Example:
Parent Directory/
Sub Directory 1/Sub Sub Directory A/Target Dir/
Sub Directory 1 (again)/Sub Sub Directory B/Sub Sub Sub Directory 001/Target Dir/
Sub Directory 2/Target Dir/
Sub Directory 3/Sub Sub Directory A/Sub Sub Sub Directory 001/Sub Sub Sub Sub Directory AAA/Target Dir/
What I would like to do is take an existing .directory file (a hidden file, always named ".directory", that points to the icon graphic I want to use and replaces the default folder icon of any directory it is sitting in), and copy it in to all of the "Target Dir" folders throughout the directory hierarchy. After much research, I've figured out that I probably need to use some combination of the find, grep, xargs, and cp commands but, as a relative noob, I'm having a hard time putting this all together (especially because the directory names throughout my tree have white space in the names - which confuses xargs. I'm also not particularly strong at manipulating string variables and wildcards yet).
Would any of you kind folks be able to suggest a command template/example that would help me replace all of those "Target Dir" folder icons?
Thanks in advance, everyone!