nonethefewer: (Default)
[personal profile] nonethefewer
This is scripting stuff for work.  I don't script in Linux that often, sooo.

--

This directory has a series of folders with this naming convention:

update_[name][date]/

It's wicked simple.  Basically, I need to:

- get the most recent folder name for [name]
- make a new folder for today's date
- copy from most-recent to new-folder
- cd new-folder

Fucked if I know, though.

(no subject)

Date: 2009-06-16 07:08 pm (UTC)
From: [identity profile] australian-joe.livejournal.com
I don't have a Linux handy to get this right in, alas.

Assuming bash, this may be useful to get you going in the right direction:

#!/bin/bash

BASEDIR=[path]
NAME="[...]"
DATE=$( date +[format stuff here] )

# this is a "minus 1, not a minus lower-case L"
MOSTRECENT=$( ls -1 -t ${BASEDIR}/update_${NAME}* | head -1 )

# if the date is regularly formatted, maybe use cut to strip out the date
DATELESS=$( echo ${MOSTRECENT} | cut [cut args here] )

NEWFOLDER="${DATELESS}${DATE}"

mkdir ${NEWFOLDER}
cp -rp ${MOSTRECENT}/* ${NEWFOLDER}
cd ${NEWFOLDER}



Something like that. Hope that helps.

(no subject)

Date: 2009-06-16 07:44 pm (UTC)
From: [identity profile] novalis.livejournal.com
Use Python. os.listdir to get a list of file and directory names, re to split the name into the name, date, sort to sort them. Then use os.system to copy files.

(no subject)

Date: 2009-06-17 12:29 pm (UTC)
From: [identity profile] hitchhiker.livejournal.com
is the date in ansi format? (i take it you want to sort by nominal date, rather than the folder timestamp, just in case)
Page generated Jul. 22nd, 2025 05:12 am
Powered by Dreamwidth Studios