Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - General
User Name
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.


  Search this Thread
Old 06-02-2006, 08:52 AM   #1
LQ Newbie
Registered: Jun 2006
Distribution: Ubuntu Dapper
Posts: 1

Rep: Reputation: 0
Question Script to change date in filename minus one day

Hi, this is my first post at LQ. I have been listening to the podcast for a while and have just joined. I know the value of the site as I have found the answers to questions in the past by way of Google directing me here.
I look forward learning some new skills and helping out where I can.

I would like to help to change some filenames.

Currently they are in a WORDS1_YYYY_MM_DD_WORDS2 and I would like to change the both sets of words and change the date to be in the same format but minus one day.

I know it's easy to change the words with a simple sed command but I don't know how to fix the date section. Can someone help me out with this please?

Old 06-02-2006, 09:47 AM   #2
spirit receiver
Registered: May 2006
Location: Frankfurt, Germany
Distribution: SUSE 10.2
Posts: 424

Rep: Reputation: 33
So, welcome to LQ (although I'm not yet naturalized myself, I guess).

I think the easiest solution to your problem is to convert the date to seconds since epoch and then subtract 86400. From your post I understand that you know how to extract the date and convert it to the format "YYYYMMDD" . Then you can use something like:
#! /bin/bash

# date set to YYYYMMDD
TODAY=$(date +'%Y%m%d')

echo "Yesterday was" $(date --date=@$(( $(date --date=$TODAY +%s) - 86400 )) +'%Y %m %d')

Last edited by spirit receiver; 06-02-2006 at 09:49 AM.
Old 06-02-2006, 09:56 AM   #3
Registered: Sep 2004
Location: Dayton, Oh
Distribution: Linux Mint 17
Posts: 150

Rep: Reputation: 18
Actually, if it was something as simlpe as "yesterday" you can

date --date='1 day ago' +%Y%m%d
I'm having a problem trying to figure out how to feed it a date other than today. I'll keey looking though.
1 members found this post helpful.
Old 06-02-2006, 09:56 AM   #4
Registered: Aug 2004
Distribution: LFS
Posts: 350

Rep: Reputation: 31

date -d "-1 day" +"%Y%m%d"


bash, shell script

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Date in a filename. Garp Linux - General 7 12-09-2005 01:57 PM
Bash script to change a filename associated with an inode index number. Ziv Programming 22 06-19-2004 08:41 AM
Script add date to filename amphion Linux - Newbie 2 06-02-2004 07:12 AM
use date as output filename? wijnands Linux - Newbie 1 05-12-2004 03:39 PM
Script to change several filename jan_81 Linux - Newbie 5 04-28-2004 11:10 AM > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 01:57 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration