Below is the format of the script to copy and to move the files and folders. The address of either folder or pic can be found by right clicking either folder or picture and selecting properties.
Find the location descriptor. Note that the picture ends with. So all you have to do is add the folder names. Renaming a file or folder would use the move command, since the copy command causes there to be duplicates. You can do it easily with ls , but parsing the output of ls is problematic, so this only works if the file names contain only printable characters other than newlines.
No one has yet posted a bash example which caters for embedded newline chars embedded anything in the the filename, so here's one. It moves the 3 oldest mdate regular files. It's easiest to do with GNU find. I use it every day on my Linux DVR to delete recordings from my video surveillance system older than a day. Remember that find defines a day as 24 hours from the time of execution.
Therefore files last modified at 11 pm won't get deleted at 1 am. You can even combine find with cron , so deletions can be scheduled automatically by running the following command as root:.
Sign up to join this community. The best answers are voted up and rise to the top. Stack Overflow for Teams — Collaborate and share knowledge with a private group. Create a free Team What is Teams? Learn more. Shell script for moving oldest files?
Ask Question. Asked 10 years, 3 months ago. Active 1 year, 2 months ago. Viewed 21k times. Improve this question. Gilles 'SO- stop being evil' k gold badges silver badges bronze badges.
Including or excluding subdirectories? And should it be done recursively in a directory tree? Many most? The typically available attributes are atime last access , ctime last permission change , and mtime last modified It seems, according to this link , that my ext4 partitions are capable of handling a creation date, but ls and find and stat don't have the appropriate options yet O, as of coreutils 8.
Add a comment. Active Oldest Votes. The list is piped to sort which is instructed to: -z Treat NULL as the line terminator character instead of newline. Isn't there a simpler way? Simpler ways are buggy. Improve this answer. Community Bot 1. Sorpigal Sorpigal 1, 9 9 silver badges 10 10 bronze badges. Asked 2 years, 3 months ago. Active 2 years, 3 months ago. Viewed times. I am receiving this error, mv: cannot stat 'file' : No such file or directory.
Improve this question. I'd recommend debugging a bit to find the problem Please post the actual code that you are using. The code that you have in your question will not give the error that you mention, but a bash: work: command not found error followed by several other errors mostly due to simple syntax errors. You may want to consider testing your code in shellcheck. Also test each command as you write them down in the script so that you know they do what you'd expect them to do.
Add a comment. Active Oldest Votes. This uses the GNU -t extension to mv, so that the target directory can be specified before the filenames. Improve this answer. Thanks cas for the answer and clear explanation along with, but still the files hasn't moved to another directory. That output is not possible with the find command in my answer. What did you do that was different? Did you try to pipe ls into it instead of using find?
What version of find etc are you using? As mentioned, this requires GNU or similarly-capable versions. It won't work with other versions As you said know and then i didn't try by using ls. It does not produce nicely formatted date strings with month and day names. Show 12 more comments. In that case, move the files individually using a loop:! Thanks Kusalananda for the explanation..
Is there any possible in this same scenario to move the file to another directory by calculating the size of the directory.
0コメント