Having trouble writing a Bash script that checks if a directory is empty and deletes it if it is -


Searching for older files compared to script X, copies files and root directories to a new directory and Deletes source files + The directory is empty if it is empty, it changes in the above changes and checks again.

By copying the files and DIR, it also succeeds in deleting files, but checking that the DIR is empty, then they will be left blank.

  #! / Bin / bash source = / Root / Desktop DESTINATION = / type $ backup type type f -amine +1 -exec ./move_file.sh {} $ DESTINATION \;  

move_file.sh

  #! / Bin / bash PFAD = `Dynamic name $ 1` mkdir -p $ 2 $ PFAD cp $ 1 $ 2 $ 1 rm $ while while [` ls-aa $ pfad | Wc -l` -l 2] What is resonant is $ PFAD and it is much less rmdir $ PFAD $ PFAD = `echo $ PFAD | Rev | Cut-D / -F2- | Whenever there should be a problem in the loop   

rmdir will not delete such a directory Which is not empty, so that you can check and delete at a time

  while rmdir "$ PFAD" 2 & gt; / Dev / null; "PFAD =" $ (Dynamic "$ PFAD") "done  

2> Dev / null is there to suppress the error message there, If a directory is not empty and rmdir refuses to delete it.

Note that

  $ PFAD = `resonance $ PFAD | | Rev. Cut-D / -F 2- | Rev ' 

is a problem in which the output of this command is named after the content of $ PFAD Specifies for a variable. It can be solved by removing the dollar sign, lake You have to deal with the Dynamic Name directory and are better suited for the job. You should probably take care to test for . , however, if you have a relative path And the current working directory is empty, and possibly / , if the / ends empty, then unlimited Dynamic Loop Script Problems before becoming a Problem


Comments

Popular posts from this blog

python - Overriding the save method in Django ModelForm -

html - CSS autoheight, but fit content to height of div -

qt - How to prevent QAudioInput from automatically boosting the master volume to 100%? -