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

Moving files from one directory to other by skipping one directory

I want to move all files from SrcFiles to TgtFiles but I should not copy the files from SrcFiles_Backup to TgtFiles using bash- shell script.

Source Path - /test/dev_env/proj/Data/ALB/ALBT/SrcFiles/SrcFiles_Backup

Target Path - /test/dev_env/proj/Data/ALB/ALBT/TgtFiles/

mv /test/dev_env/proj/Data/ALB/ALBT/SrcFiles/* /test/dev_env/proj/Data/ALB/ALBT/TgtFiles/

The above command is copy all files and folders inside SrcFiles. I want to copy all files from SrcFiles Folder. Can anyone guide me on this?

Thanks!

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 can use a for loop to loop over all of the files in SrcFiles and then use grep -v to ignore the SrcFiles_Backup sub folder and only move the other files.

For example,

src_file_dir=/test/dev_env/proj/Data/ALB/ALBT/SrcFiles
tgt_file_dir=/test/dev_env/proj/Data/ALB/ALBT/TgtFiles

for file in $(ls $src_file_dir | grep -v "SrcFiles_Backup"); do
    mv $src_file_dir/$file $tgt_file_dir/$file
done

Does that meet your needs?

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