1

aws s3 rm s3://f1/f2/f3/f4/ --recursive --exclude "/f4"

inside f1 bucket there are sereval folders(obj) i want to delete the files(objects) inside f4(parth given above) file objects without removing the folder f4 but using the above command in cli deletes the f3 objects(f3 objects are f3 files and f4 folder and f4 objects) getting deleted by using above cmd

Note:-

  1. inside f3(500)objects and f4(999+ objects)
  2. i want to delete the f4(999) objects only without deleting the folder f4 (keep folder,remove files inside f4)
Sampath
  • 71
  • 5
  • 2
    There are no folders in S3. If you remove everything in /f4 then /f4 no longer exists because it only exists when there is anything under /f4. – luk2302 Feb 10 '22 at 16:07
  • okay okay inside the s3 . i've created a f1 bucket (inside that bucket i've created several folders.. is there any way to delete files inside f4 using cli because there are thousands of files in f4 (s3://f1/f2/f3/f4/)without removing the folder (f4) – Sampath Feb 10 '22 at 16:30
  • Note that [include/exclude filters](https://docs.aws.amazon.com/cli/latest/reference/s3/index.html#use-of-exclude-and-include-filters) are appended to the S3 URI that you indicated for the purposes of filtering, so your command is trying to exclude `s3://f1/f2/f3/f4//f4` which would not match any object and is effectively ignored. – jarmod Feb 10 '22 at 16:32
  • 2
    @sampath Unless you explicitly created an object with the key `f1/f2/f3/f4/` using the AWS S3 Console (or awscli or SDK) then it doesn't actually exist. You might for example have an object with key `f1/f2/f3/f4/cat.png` and a listing makes it appear that you have an f4 folder but the moment you delete f4/cat.png, f4 doesn't exist - it never existed, it was inferred from the presence of f4/cat.png. This is [not](https://stackoverflow.com/questions/19459893/how-to-create-folder-or-key-on-s3-using-aws-sdk-for-node-js/31728298#31728298) your typical Windows or Mac file system. – jarmod Feb 10 '22 at 16:36
  • @jarmod Thank you for explanation, i understand what you have said,But i need some clarification **for suppose we delete the same by navigating inside aws s3 console _'f1/f2/f3/f4/cat.png'_ inside console manually the cat.png gets deleted and f4 folder still exists then why this is happening if its working well in the s3 console then there should be some other way that it works in cli as well that deletes only cat.png without deleting the folder f4 folder** or is there any other way to delete object pls suggest ? – Sampath Feb 17 '22 at 18:19
  • 1
    The `f4/` folder still appears in the console after you delete `f4/cat.png` because you explicitly used the console's 'Create Folder' feature beforehand to create `f4/`. It exists as an object independently of `f4/cat.png`. You can also create this folder using the awscli or any SDK by creating an object with the same key (e.g. `f1/f2/f3/f4/`) and a size of zero. If `f4/` did not exist before you deleted `f4/cat.png`, then it won't exist afterwards either. Also, read [this answer](https://stackoverflow.com/a/69623164/271415). – jarmod Feb 17 '22 at 18:34
  • Please provide enough code so others can better understand or reproduce the problem. – user1811107 Feb 22 '22 at 13:09

0 Answers0