Home > Blockchain >  Shell script to delete perticular files
Shell script to delete perticular files

Time:07-11

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 found
    • rm -rf: remove file and directories named ...
    • {}: is replaced by each file/directory found by find command
    • \;: and of -exec option
  • Related