I have a multiple layers of folder example a(b(c(d(u,v))))
Here in every level there is a folder sync
, for example in every directory sync
folder is present i.e a/sync
, a/b/sync
and so on.
I am looking to write a shell or tcl script which will go in every folder and delete the particular file(sync).
Can anyone guide me?
Thanks
Good day
CodePudding user response:
You can use rmdir ./**/.sync
.
This will search recursive in the current directory for every directory called sync
and delete it.
For use of the double asterisk also see this answer
Note that this will only delete directories(folders) and if it's not empty.
To remove the directories with all files in it, use rm -r ./**/.sync
CodePudding user response:
Find and remove...
find . -type d -name sync -exec rm -rf {} \;
Explanations:
.
: search for current directory-type d
: search for directories only-name sync
: search for file/directory named "sync
"-exec ...
: execute this command on each file/directory foundrm -rf
: remove file and directories named ...{}
: is replaced by each file/directory found byfind
command\;
: and of-exec
option
CodePudding user response:
Since all the answers so far have been shell approaches, here's a tcl one:
#!/usr/bin/env tclsh
proc delete_syncs {dir} {
foreach subdir [glob -directory $dir -types d -nocomplain *] {
delete_syncs $subdir
set sync [file join $subdir .sync] ;# Or sync or .SYNC or whatever it's actually named
if {[file exists $sync]} {
file delete -force -- $sync
}
}
}
foreach basedir $argv {
delete_syncs $basedir
}
Takes the base directory (Or directories) to scan as command line arguments.