Sunday, April 28, 2024
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 1297  / 2 Years ago, thu, september 22, 2022, 8:10:33

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.


More From » command-line

 Answers
3

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".


[#1132] Saturday, September 24, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
bleger

Total Points: 468
Total Questions: 108
Total Answers: 100

Location: Belarus
Member since Wed, Dec 7, 2022
1 Year ago
bleger questions
Wed, Mar 1, 23, 03:00, 1 Year ago
Mon, Feb 6, 23, 14:44, 1 Year ago
Wed, Dec 29, 21, 13:59, 2 Years ago
Fri, May 5, 23, 16:10, 1 Year ago
;