简体   繁体   中英

Upload to aws s3 using cli without folder path

I'd like to upload a file.txt on aws s3 that is located in something like main/part1/part2/file.txt , where part1 and part2 are unknown (those folders always change). I can do that with the command aws s3 cp./main s3://mybucket --exclude "*" --include "*.txt" --recursive , but then in my bucket I have the file located in part1/part2/file.txt . I'd like file.txt to be at the base of the bucket, not inside part1/part2

Is that possible given that part1 and part2 are constantly changing?

for dir1 in $(ls main); do
    for dir2 in $(ls main/$dir1); do
        aws s3 cp ./main/$dir1/$dir2/ s3://my-bucket --exclude "*" --include "*.txt" --recursive
    done
done
upload: main/part1/part2/file.txt to s3://my-bucket/file.txt
upload: main/part11/part22/file2.txt to s3://my-bucket/file2.txt

The following will work if main will never contain more than 1 subdirectory at a time ( part1 ) & that subdirectory in-turn will never contain more than 1 subdirectory at a time ( part2 ):

aws s3 cp ./main/*/*/ s3://my-bucket --exclude "*" --include "*.txt" --recursive
upload: main/part1/part2/file.txt to s3://my-bucket/file.txt

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM