Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Bash script for moving directories only moving the content within directories

I am trying to move some directories and files within said directories to a new directory, the code I am using utilises a for loop and checks the content of a txt file which is used to determine what it is we want to move. I only insert the directory names into the txt file.

The code only seems to move the content within the directories and not the directory and it’s content.

#!/bin/bash

cp "files_for_moving.txt" /Users/johndoe/project/for_moving

cd /Users/johndoe/project/for_moving

FILESFORMOVING="files_for_moving.txt"

LINES=$(cat $FILESFORMOVING)

echo $LINES

for i in $LINES
        do
        echo 'running the mover script'
        cp -R $i/ ../simple_done_updated/


done

cd /Users/johndoe/project
                                        

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You should try removing the first / from:

cp -R $i/ ../simple_done_updated/

to:

cp -R $i ../simple_done_updated/
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading