1

How do I move a file 1 directory up using loop? Can someone maybe help me out?

I tried this:

for dir in */*/
    do mv "$dir"/*
done

1 Answer 1

1

Like that:

for dir in */*/
do
    echo mv "$dir"* "${dir%/*/}" # Drop the echo after tested it
done

Note that this will move all files and directories under $dir to the parent directory of the $dir. If you want to move a specific file, replace "$dir"* with "$dir"file where file is the filename of the specific file. Also be very careful where and how you use this code after echo removed (running in the wrong directory would be catastrophic)

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.