1

I have multiple files in multiple directories some buried under subdirectories. I want to be able to move all files until they are only 1 directory deep.

for example:

/home/folder/subfolder/file1.txt
/home/folder2/file2.txt
/home/folder3/subfolder/subfolder/subfolder/file3.txt

becomes:

/home/folder/file1.txt
/home/folder2/file2.txt
/home/folder3/file3.txt

I found that I can use

find ./*/ -type f

to locate all the files. But I'm not sure how to move them so that they are only 1 directory deep.

1 Answer 1

0

I found an answer in the form of a bash script

#!/bin/sh

IFS='
'
for i in $(find ./*/ -mindepth 2 -type f); do
    mv -- "${i}" "${i%/*/*}"
done

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .