Delete the parent folder keeping the contained files?
Is it possible that if I have this:
/folder1/folder2/folder3
/folder1/folder2/file1.txt
Can I delete folder2 but keep its content?
So the result would look like:
/folder1/folder3
/folder1/file1.txt
cd /folder1/folder2/
mv * ../
cd ../
Now check the contents of the folder:
ls
Then use this command to delete the directory. It is completely safe since it will only delete empty directories:
rmdir folder2/
I think that you don't need to actually delete something... just move it away.
mv /folder1/folder2/* /folder1/
rmdir /folder1/folder2/
First command moves the contents to parent directory and the second removed the directory if it's empty. This won't move hidden/dot files. If you want also to move hidden files you would need:
mv /folder1/folder2/{*,.*} /folder1/
rmdir /folder1/folder2/
or use dotglob option in bash. If you don't have dot files it would lead to no matches found: dir1/dir2/.*
in bash and the command would fail. Also you can ignore the:
mv: cannot move ‘folder1/folder2/..’ to ‘folder1/..’: Device or resource busy
errors since bash passes .
and ..
to mv
.