Jump to content
We're Hiring! Full Stack Developer ×

Trying to run some code, but having problems


Recommended Posts

I'm trying to run some code from a script that will more or less copy the 2 oldest files from one directory to another.


My intent is to throw a bunch of files into a directory and have my windows machine grab them and do some processing. The reason for the two oldest was something I came up with simply because I want to limit it to two files. LOL


Anyways heres what I have, but I'm having issues and wondered if somebody could look at it and tell me what I'm doing wrong.


mv `ls -t |tail -1` /mnt/disk3/Movies/HandBrake/test


The problem I have is I want to run it from cron by simply droping it in the cron folder for daily, but of course its trying to run what I typed in there for that folder when I want to point it at /mnt/disk3/Movies/Handbrake/2do


I tried using the following

mv `ls -t  /mnt/disk3/Movies/Handbrake/2do/ |tail -1` /mnt/disk3/Movies/HandBrake/test

but it gives me a no such file or directory found


I can run excluding the location for ls, but its rather important. LOL

Can anybody give me a clue to what I'm doing wrong.



Simply put I want to move the two oldest files from






Link to comment

Heres the results from that and thank you for the help at least.


root@Tower:/mnt/disk3/Movies/HandBrake/2do# mv `ls -t  /mnt/disk3/Movies/Handbrake/2do/* | tail -2` /mnt/disk3/Movies/HandBrake/test

/bin/ls: cannot access /mnt/disk3/Movies/Handbrake/2do/*: No such file or directory

mv: missing destination file operand after `/mnt/disk3/Movies/HandBrake/test'

Try `mv --help' for more information.


root@Tower:/mnt/disk3/Movies/HandBrake/2do# cd /mnt/disk3/Movies/Handbrake/2do/ && mv `ls -t | tail -2` /mnt/disk3/Movies/HandBrake/test

-bash: cd: /mnt/disk3/Movies/Handbrake/2do/: No such file or directory



Link to comment

Wow it works. LOL


Damn I feel aweful stupid now. LOL


Thanks for the catch. I don't know why I missed that, but well it works now. ;)


cd /mnt/disk3/Movies/HandBrake/2do/ && mv `ls -t | tail -2` /mnt/disk3/Movies/HandBrake/test


I think the first time I some how missed the && when I used the cd command myself in a little script. Now I have a million files to encode and my little windows box and a little script on my unRAID machine to make it all go smooth.

Link to comment


This topic is now archived and is closed to further replies.

  • Create New...