File Versioning with Shell Script

Thread Tools Search this Thread
Top Forums Shell Programming and Scripting File Versioning with Shell Script
# 1  
Old 07-18-2011
Java File Versioning with Shell Script

Need to add the version date to the moved file if same file name in folder exists and limit the same files in the folder.

Ex: If moved or copy file abc.txt to folder XYZ then append the version date abc07112011.txt or abc07122011.txt in the folder.


And if the number of files is 10 i.e date more than 10 days then delete last file and add latest file

If a new file abc.txt is moved on 07182011 the new file need to be added with date abc07182011.txt and if more than 10 days old file exists then delete
# 2  
Old 07-19-2011
To count the number of files in the current directory, you can use "ls" (<>) and "wc" (<>) as follows:
ls -1 | wc -l

Then use "[" a.k.a. "test" (<>) to see if the result is greater than or equal to 10.
if [ "`ls -1 | wc -l`" -ge 10 ]; then
    # Do something.

And you can get the name of the oldest file using "ls" and "tail" (<>) as follows:
ls -t | tail -n 1

To get the date, use "date" (<>). Something like this should be what you want:
date '+%m%d%Y'

And you can add the date to a file whose name ends in ".txt" using "sed" (<>). For example:
echo 'abc.txt' | sed "s/[.]txt\$/${the_date}.txt/"

I'm not sure exactly what you're trying to do, but hopefully this will help get you started.
# 3  
Old 07-19-2011
Thanks . .. This will surely get me started. I am trying to take the backups for the past 10 days with the same file name and I need last ten days versions to be in the folder.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Versioning up a file with initials?

I have this code that works great ... #!/bin/sh for file in "$@" do ext=${file##*.} base=${file%.*} num=${base##*v} zeroes=${num%%*} num=${num#$zeroes} #remove leading zeros, or it uses octal num=$((num+1)) base=${base%v*} ... (5 Replies)
Discussion started by: scribling
5 Replies

2. Shell Programming and Scripting

Need to get versioning of the branch name dynamically

Hi, I need to get versioning of the branch name dynamically. can you please help us to achieve this functionality. curl curl everytime... (5 Replies)
Discussion started by: lkeswar
5 Replies

3. Shell Programming and Scripting

Help with Shell Scrip in Masking particular columns in .csv file or .txt file using shell script

Hello Unix Shell Script Experts, I have a script that would mask the columns in .csv file or .txt file. First the script will untar the .zip files from Archive folder and processes into work folder and finally pushes the masked .csv files into Feed folder. Two parameters are passed ... (5 Replies)
Discussion started by: Mahesh G
5 Replies

4. SCO

Versioning through undelete

Hi , I am using SCO openserver realease 3.2 and tried to test versioning on a directory with undelete -s . The command executes well but it is not creating any versions of the files in it. I have also setted versioning options via filesystem and then remounted it but of ... (0 Replies)
Discussion started by: dextergenious
0 Replies

5. Shell Programming and Scripting

how to read dbf file in shell script and to convert dbf file usinf shell script

Hi all, I am new to shell scripting. I have dbf file and I need to convert it into csv file. OR, can i read the fields from a .dbf file and OR seprate the records in dbf file and put into .csv or txt. Actually in the .dbf files I am getting , the numbers of fields may vary in very record and... (6 Replies)
Discussion started by: gauara
6 Replies

6. Linux

Any Filesystems in Linux Support Versioning?

A question that has come up repeatedly where I work from our former VMS guys is... "will any Linux filesystem ever support versioning like RMS did"? When they talk about versioning they really are talking about something that *I think* would involve having apps that support versioning. For... (7 Replies)
Discussion started by: deckard
7 Replies

7. Programming

binary versioning

Dear Members, Do you know any information about versioning a binary file. That means test.out 1.0.0, 1.0.1, 1.1.0, and so on. Can I manually edit version number (both major and minor) and revision number myself (how?) or any utility to set version number (which one?). Best Regards, Francesco (2 Replies)
Discussion started by: francescoandrio
2 Replies

8. Solaris

Solaris versioning

Please correct me if I am wrong... Isnt the only difference between minor releases of Solaris, ex. 9/04 and 9/05, is the patche revs between them? If so, why does the /etc/release info stay static when patched? (4 Replies)
Discussion started by: mhm4
4 Replies
Login or Register to Ask a Question