LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   Move files contained in source dir to destination dir, but not source dir itself (https://www.linuxquestions.org/questions/linux-software-2/move-files-contained-in-source-dir-to-destination-dir-but-not-source-dir-itself-4175477086/)

unixunderground 09-14-2013 04:18 AM

Move files contained in source dir to destination dir, but not source dir itself
 
Hello folks,

I am runninng a debian server at a remote location, that I use as a media streaming server with subsonic.

What I want to do, is that I would like to "drag-and-drop" files to my Subsonic server remotely, and in order to do so I am planning to use bittorrent sync + some scheduled cron command that will move the incoming files from the source directory (bittorrent sync folder synced to my local pc) to the media directory on the server (subsonic)

Basically what I need this scheduled script to do, is to move all the contents of a given directory (but not the directory itself) to another directory, at a scheduled time (cron)

I was thinking of using mv but I am not sure wether or not an option is present to only move the contents of the folder, but not the folder itself

Any ideas on how I could do this?

Thanks in advance!

unSpawn 09-14-2013 07:06 AM

Code:

TMPFILE=`mktemp -p /tmp cron.XXXXXXXXXX` && {
crontab -u $LOGNAME -l > "${TMPFILE}"
echo "# Move files every hour:" >> "${TMPFILE}"
echo "* */1 * * * find /some/path -maxdepth 1 -type f -iname \*.torrent -print0 | xargs -0 -iX mv 'X' /some/other/path" >> "${TMPFILE}"
crontab -u $LOGNAME "${TMPFILE}" && "${TMPFILE}"; }
crontab -u $LOGNAME -l


druuna 09-14-2013 07:17 AM

@ unSpawn: Nice!

unixunderground 09-20-2013 11:17 AM

Quote:

Originally Posted by unSpawn (Post 5027558)
Code:

TMPFILE=`mktemp -p /tmp cron.XXXXXXXXXX` && {
crontab -u $LOGNAME -l > "${TMPFILE}"
echo "# Move files every hour:" >> "${TMPFILE}"
echo "* */1 * * * find /some/path -maxdepth 1 -type f -iname \*.torrent -print0 | xargs -0 -iX mv 'X' /some/other/path" >> "${TMPFILE}"
crontab -u $LOGNAME "${TMPFILE}" && "${TMPFILE}"; }
crontab -u $LOGNAME -l


Wow thank you!

That was a really classy way to go about it.

I got everything working smoothly with your script and the whole thing is just awesome now.

Thanks again!


All times are GMT -5. The time now is 12:28 AM.