Solved

move all files from directories and subdirectories to folder

Posted on 2010-08-23
10
782 Views
Last Modified: 2013-11-22
Hi,

   I need some help in creating a .sh script where it will go through my /mnt/CVSSTank/dicom/hold directory, including the many sub-directories with it and move all of the files it finds to the path /mnt/CVSSTank/dicom/hold1.  When it is done moving the files, it would be nice if it deletes the sub-directories within /mnt/CVSSTank/dicom/hold -

thanks!
0
Comment
Question by:doc_jay
  • 5
  • 5
10 Comments
 
LVL 16

Expert Comment

by:santoshmotwani
Comment Utility
if [ -e /mnt/CVSSTank/dicom/hold1 ]; then
      rsync -a -u -v  -e --delete-after /mnt/CVSSTank/dicom/hold/mnt/CVSSTank/dicom/hold1 > /var/log/backuplog.txt
else
      echo "USB Disk not mounted /mnt/CVSSTank/dicom/hold1 " > /var/log/backuplog.txt
fi

/bin/mail -s "my backedup files " abc@abc.com < /var/log/backuplog.txt
0
 

Author Comment

by:doc_jay
Comment Utility
got an error with this:

cvssarch:/mnt/CVSSTank# sh test.sh
rsync: change_dir "/mnt/CVSSTank/dicom/hold/mnt/CVSSTank/dicom" failed: No such file or directory (2)
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1042) [sender=3.0.7]
test.sh: /bin/mail: not found
cvssarch:/mnt/CVSSTank#


Thanks for looking--
0
 

Author Comment

by:doc_jay
Comment Utility
okay I got it to run... just missed a 'space':

Thanks for your help on this --

this actually places a 'hold' directory in inside of my 'hold1' directory.  Is there a way to change it so that it so that it only moves the files that it finds inside '/mnt/CVSSTank/dicom/hold/' and its many sub-directories to 'mnt/CVSSTank/dicom/hold1'?  I don't want to retain the path, so in other words, I don't want any sub-directories moved over, only the contents of the 'hold' directory and the sub-directories with it.

Thanks
if [ -e /mnt/CVSSTank/dicom/hold1 ]; then
      rsync -a -u -v  -e --delete-after /mnt/CVSSTank/dicom/hold /mnt/CVSSTank/dicom/hold1 > /var/log/backuplog.txt
else
      echo "USB Disk not mounted /mnt/CVSSTank/dicom/hold1 " > /var/log/backuplog.txt
fi

/bin/mail -s "my backedup files " abc@abc.com < /var/log/backuplog.txt

Open in new window

0
 
LVL 16

Expert Comment

by:santoshmotwani
Comment Utility
Was this comment helpful?
Yes No
santoshmotwani:
if [ -e /mnt/CVSSTank/dicom/hold1 ]; then
      rsync -a -u -v  -e --delete-after /mnt/CVSSTank/dicom/hold /mnt/CVSSTank/dicom/hold1 > /var/log/backuplog.txt
else
      echo "USB Disk not mounted /mnt/CVSSTank/dicom/hold1 " > /var/log/backuplog.txt
fi

0
 
LVL 16

Expert Comment

by:santoshmotwani
Comment Utility
there is a space between

/mnt/CVSSTank/dicom/hold (space) /mnt/CVSSTank/dicom/hold1
0
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 16

Expert Comment

by:santoshmotwani
Comment Utility
if [ -e /mnt/CVSSTank/dicom/hold1 ]; then
      rsync -a -u -v  -e --delete-after /mnt/CVSSTank/dicom/hold/* /mnt/CVSSTank/dicom/hold1 > /var/log/backuplog.txt
else
      echo "USB Disk not mounted /mnt/CVSSTank/dicom/hold1 " > /var/log/backuplog.txt
fi




try this
0
 

Author Comment

by:doc_jay
Comment Utility
that only copied the contents of '/mnt/CVSSTank/dicom/hold' which included a lot of sub-directories.  So, your last attempt didn't work.

All of the files within '/mnt/CVSSTank/dicom/hold' are '.dcm' files.  Is there any way you could write a script that does a 'find' of all '.dcm' files within '/mnt/CVSSTAnk/dicom/hold/' and all of the sub-directories and then 'move' them to the '/mnt/CVSSTank/dicom/hold1' path?  After that could it delete all of the sub-directories within '/mnt/CVSSTank/dicom/hold'?  I also liked that log file idea you had.

Thanks
0
 
LVL 16

Expert Comment

by:santoshmotwani
Comment Utility
if [ -e /mnt/CVSSTank/dicom/hold1 ]; then
      rsync -av   -r --remove-source-files /mnt/CVSSTank/dicom/hold/*  /mnt/CVSSTank/dicom/hold1 > /var/log/backuplog.txt
else
      echo "USB Disk not mounted /mnt/CVSSTank/dicom/hold1 " > /var/log/backuplog.txt
fi



Hi this will copy everything under HOLD including sub- directories. It will also delete all the files , but m not certain about directories.

I tested it on my PC
0
 

Author Comment

by:doc_jay
Comment Utility
this did not work either.  All it did was copy all of the sub-directories inside of /mnt/CVSSTank/dicom/hold to /mnt/CVSSTank/dicom/hold1.  

Is there anyone else who might have any ideas, particularly one that does not include 'rsync'?

Here is my idea of how the script could be written:

'All of the files within '/mnt/CVSSTank/dicom/hold' are '.dcm' files.  Is there any way you could write a script that does a 'find' of all '.dcm' files within '/mnt/CVSSTAnk/dicom/hold/' and all of the sub-directories and then 'move' them to the '/mnt/CVSSTank/dicom/hold1' path?  After that could it delete all of the sub-directories within '/mnt/CVSSTank/dicom/hold'?'

thank you all
0
 

Accepted Solution

by:
doc_jay earned 0 total points
Comment Utility
I found a solution:

find . -type f -name "*.dcm" -exec mv {} /mnt/CVSSTank/dicom/hold1/ \;

thanks for all of your help on this
0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Installing FreeBSD… FreeBSD is a darling of an operating system. The stability and usability make it a clear choice for servers and desktops (for the cunning). Savvy?  The Ports collection makes available every popular FOSS application and packag…
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap (http://www.tcpdump.org) Version 1.2 2.      Jpcap(http://netresearch.ics.uci.edu/kfujii/Jpcap/doc/index.html) Version 0.6 Prerequisite: 1.      GCC …
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now