I have a directory where there are subdirectories which have numbers as directories. For example I have a parent directory test now I have some subdirectories like 1,2,3,4,5,6,7. Now I have a local exported variable like export a=3. I want to delete directories that are above or equal to $a and below or equal to $a+3, So I want to delete files 4,5. How can I achieve this in Ubuntu 18.04.6 LTS.
I tried rm -rf {$a..$($a+3)}, it didn't work, I tried so many other things but not successful.
2 Answers
One possible solution:
rm -r $(seq $a $((a+3)))(Provided you really meant what you illustrated with your code sample, ie. directories above or equal to $a and below or equal to $a+3, instead of what you wrote in the text, "above >$3 but below <$3+2".
You could use the following method to remove folders or files.
Send the output of the respective folder to a text file
ls >> text.txtEdit the text.txt file to remove all those entries which you don't want to remove.
issue the command
sudo rm -r -i $(cat text.txt). Use-iflag if you want the process to be interactive.When removing files, do not use
-rflag.
This method would work where the folders that you wish to remove are not in consecutive order.
2