Programming :: Sort Files In Directories Based On Files Date
Sep 8, 2009
I need a script that will take all the files in a given directory and create new monthly sub-directories and sort all the files based on the creation date into the appropriate directory.For example, all files created between 01/01/09 and 01/31/09 will be placed in 'JAN-2009'
Originally Posted by Kenny_StrawnPlease wrap [CODE] tags aroung any code posted here. The full source that way could still be posted.I am trying to copy all the files in the directory based on the modification date (i.e created on Dec 29). Not able to find the proper command for this. This is what I have tried.
I have very little linux experience. And need some help with a bash script. I need to a script I can set cron to run to sort files out of a holding folder into final folders. It doesn't necessarily have to be bash, but I think it would be sufficient for this. File names are formatted as such when created: Dest-Date-Time-CID-Destination# I want the files to be moved from a all in one holding folder to a folder structure like this.
I have a directory listing with many subdirectories having many files. I want to recursively search for the oldest 5 files starting from the base directory and not 5 from each subdirectory. I am writing a shell script which sorts them using ls -lRtur|egrep "txt|jpg" > /tmp/file1 Now from this /tmp/file1 file I want to sort the files same as what the ls -ltr command does that is oldest file time to newest file time first. How do I sort based on Linux time stamp? The files itself also have Linux timestamps embedded in them So I can sort based after extracting them as well if it is easier. My /tmp/file1 has entries like below.
I know find can do what I am looking for, but I am wondering if there is an alternative way to find files on the filesystem either created before/after a certain point, or at a certain time.
Typically I rely on updatedb & locate for most of my file searching needs. Issues with those tools, though, are that it only has directory and file names, and it only creates a database of local directories, not anything mounted via CIFS|NFS or via -o loop (eg, .iso images).
So if I need to find files created after yesterday across the entire system (local and remote filesystems), I am currently needing to use find.
What other tools, if any, would accomplish this in a similar fashion?
I have tried ls and grep, but that requires (in my attempts so far) multiple searches:
ls -lR | grep Aug | grep 10 ls -lR | grep Aug | grep 11
I have hundreds of MTS and AVI files since 2000 and would like to rename them in the following manner based on the date created: DD-MMM-YYYY HH.MM.SS_X; where X begins at 1 and increments by 1 if there are dublicate date/time stamped videos.
Ex: 19-Nov-2002 08.12.30.avi, 19-Nov-2002 08:13:30_1 and 19-Nov-2002 08:13:30_2
Someone previously wrote the following script for me, and it works great for photos. It uses EXIV2 to get the image date created info. I have tried to understand the script, but am struggling. The video files I have can use the date modified since I have not modified them since I filmed them.
#!/usr/bin/env python import os import stat import pyexiv2 import time directory = '/home/david/Desktop/test' [Code].....
what i wanted to do was find all the files with a specific name from a tree, sort them by modification time and have their directory appended to them so that i knew where they were (because they all have the same name). i tried a whole bunch of different things and finally did this:
this did the trick pretty well, but as you can see it is far from elegant and i think i'm doing some things wrong and kludgy
first thing i tried was "ls -lRt | grep world.sav" which worked except i couldnt distinguish the files because there were no directories. that took a lot of looking till i accepted i couldnt make ls print directories as well and append them to the files somehow that their relationship would be clear. i tried piping ls to find, doing it in reverse, passing them from grep etc. etc. until i read some more stuff online that got me using gawk and sort. the questions:
1. is there some other, more elegant and simple way to do this kind of detection and sorting?
2. is there any way to use a pipe after using exec? the semicolon seems to prevent this entirely, forcing me to use an intermediate file as above. i could just remove it later, but i'd prefer a straight piping.
Sequentially number files based on date modified (rename cli)
I'm almost done a larger script which takes all the pictures in a folder, converts it to video, and emails it to me. Everything worked fine until I realized the picture filenames weren't always starting at 1, then ffmpeg chokes.
I have a bunch of files in a folder which I need to rename to:
I don't want to install any additional packages and I'd like this to run in a single command if possible.
If not possible, then a bash script would work too.
I recovered some 60,000 files with PhotoRec and need a script to sort them into individual folders based on extension. I was able to do this once before but cannot find the script again (sad thing is that I probably saved it on another HD that I'm having partition issues with, but that's another story....).I found this script:
#!/bin/dash mkdir "$1" for file in *.$1; do mv "$file" "$1" done
While it does work, I am not looking forward to going through all 132 folders and typing in each extension. The last time I did it, the folder was automatically created based on the extension(s) found.
This might not be the right place to ask this question, but it's software so I'll try this before going to Audio-specific boards. I have a bunch of MP3s (some ogg) with crazy names in crazy directories. I would like to make sure the tags are correct (possibly by hand) and then rename them/move them so that they are in places like
So I imagine a magic program where I can edit tags and then push a magic button that makes directories and copies the files as above. Any ideas?
I have a folder named Pictures that contains a bunch of .jpg files. My problem is that they all have randomly numbered names, then there is a duplicate of the file that is random numbers then the letter a right before the .jpg.for example, there would be 123.jpg and 123a.jpg, where 123a.jpg is just a resized version of 123. What i'd like to do but have NO clue how to, is to have a script or something go through my Pictures folder, then copy the ones that end in a.jpg to a folder called Resized, and ones that dont have that to a folder called Originals. That way my Pictures folder will be in tact, and i'll have copies of them all separated out.I have to do this all through the CLI on a machine, maybe I dont even need a script and can just do it with a slick command?
the moment the file name goes as backup-"$(date +%d-%b-%y)" so something like backup-13-Feb-11.I have already setup in my script to make sure the backup was successful and is not corrupt what I need to do next if for exampleif I backup for 21st feburarybackup-21-Feb-11if it finds anything older than five days for examplebackup-13-Feb-11 it will delete this. I want the old delete part to work on the filename not a system time stamp
I'm looking for a c++ code that search for all files in computer between two input dates (example- 3.3.2011 and 11.4.2011)and copy all file in that range in new file .the user run the program and input date and path in dos system
I'm pretty sure I'm in over my head with this one. Here's the situation: My practice has been, after downloading and making changes to files, to use a certain GUI cataloging app to move them to categorized sub-folders inside one "umbrella" folder, then copy them to (what are in most cases) identically-named sub-folders in another one on the same HD. Emulation of this process on the command-line would look like:
This was in anticipation of making a "twin" of the second, now bigger, "umbrella" folder on anexternal HD and continuing the practice. At some point I intended to get rid of the original 2nd "parent folder" and just keep the first one on the drive with my OS install, using the twin on the backup folder as I'd been doing when it was on that same drive.
I'm very close (a matter of 2 to 3 weeks, it looks like) to getting a backup/external drive in a reasonably-reliable external enclosure. With the backup, originally the "twin" of the bigger "umbrella" folder and its sub-directories, on that other drive, I also anticipate that I will likely go at least a few days between backing up any new files to it.
For the sake of argument, let's say I gave the external the name "tuxs_twin". Is there any way to monitor copying activity from /Pictures/ on the boot HD to /media/tuxs_twin/Pictures/ and log the dates and times, then have something running that checks the log every so many hours and puts up a reminder dialog saying /tuxs_twin/Pictures/ hasn't had any new files copied to it since date X at time Y? I hope this was clear enough. If not, I'll try to break it down further when I know which details are confusing folks.
I have been searching for a solution to the following problem:
When my distro of choice updates Firefox web browser, the directory name is '/usr/lib/firefox-<version>'. The problem here is that the directory name is dynamic by nature and doesn't allow a simple static solution, e.g. 'cp -rf /usr/local/files/bookmarks.html /usr/lib/firefox/defaults/profile'.
The same quandary applies when adding extensions, changing prefs etc. I have looked at the following commands:- find, sed, xargs, grep, awk, fprint. Unfortunately my grasp of syntax and programming is very simple at best.
I need to, through a bash script, go through a given directory (given as argument 1) to list out the relative path in this directory (including $1) for eact subdirectory which contains files. Directories which only contain . .. and eventually only subdirectories SHALL NOT be listed. It is this last requirement that makes it difficult for me.
I have been using the tree command for now, but I have not found a way to ignore paths to directories which only contains other subdirs or nothing at all in any easy way. I may offcourse test each directory after they are listed but this gives an extra loop to go through and I beleive it should be possible to do it directly when creatring the list. I guess by using find or ls in conjuntion with the tree command or by itself it should be possible but I am not to conversant of nested script commands.
I was hoping to get some pointers on how to rename files based on database entry. I got hundreds of thousands of files that has GUID name assigned to it. only way to find out the file name is to look up the database table. Its obvious that this is not efficient. I couldn't find any tutorials on how to do this. Please point me to right direction. A starting point would be very helpful.
I have bought an external usb hard drive on which I back up my three computers every once in a while.Space will quickly be used up.I can't find that little bit of research that I need yesterday.Here is what I would like to find:An application that eliminates doubles in identical files and renames files that have changed by appending the last saved date yyyymmdd to the file name.Does such an application already exist?
I am new to perl scripting and wrote a perl script to read the directories and files and count the no of files in each directory and generate a log file. The problem is it is not printing anything to the log file. I am copying the script below.
I am newer to Linux ( using Ubuntu 10.04) : I have noticed that during replacement of a file , no date and size of the new and old files are shown in the dialogue box so how to show that ( like the one in windows)
I know that it is easy question , but i really don't know how to do that , by the way I have checked folder preferences and system --> preferences but i did not find something for that
I am trying to understnd where java preferences are stored based on web search I understand they are somewhat like windows registry - stored out there somewhere. web suggested things like hidden files or directories - and i've look all over th eplace withour result on Fedora 14. trying to start a program. got part way in and had given some info and then it blew. it still remembers my iput - which may have been wrong. ive looked at code and see it uses the java preferences system - wpould like to find and erase.