LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud
User Name
Password
Linux - Virtualization and Cloud This forum is for the discussion of all topics relating to Linux Virtualization and Linux Cloud platforms. Xen, KVM, OpenVZ, VirtualBox, VMware, Linux-VServer and all other Linux Virtualization platforms are welcome. OpenStack, CloudStack, ownCloud, Cloud Foundry, Eucalyptus, Nimbus, OpenNebula and all other Linux Cloud platforms are welcome. Note that questions relating solely to non-Linux OS's should be asked in the General forum.

Notices


Reply
  Search this Thread
Old 07-23-2021, 01:34 PM   #1
Pavanchowdary
LQ Newbie
 
Registered: Jul 2021
Posts: 3

Rep: Reputation: Disabled
Question Getting into the previous directory using date commands


Hi,
This is Pavan,

Every month we do a build for that we create a folder like 202107 for current month., then copy some files from previous month build 202106. Currently we're doing it manually.

Now we are automating the process. So for the current month build I'll create a folder with the command "$"(date +%Y%m)"". So how can i get to previous build directory. Can anyone tell exact command to use.

Thanks,
Pavan Kumar

Last edited by Pavanchowdary; 07-23-2021 at 01:37 PM.
 
Old 07-23-2021, 01:38 PM   #2
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,670

Rep: Reputation: Disabled
Code:
date -d '1 month ago' +%Y%m
 
1 members found this post helpful.
Old 07-23-2021, 02:20 PM   #3
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 26,632

Rep: Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965Reputation: 7965
Quote:
Originally Posted by Pavanchowdary View Post
Every month we do a build for that we create a folder like 202107 for current month., then copy some files from previous month build 202106. Currently we're doing it manually.

Now we are automating the process. So for the current month build I'll create a folder with the command "$"(date +%Y%m)"". So how can i get to previous build directory. Can anyone tell exact command to use.
Read the "Question Guidelines" link in my posting signature. We're happy to help you, but asking us to write scripts for you and look up exact commands is fairly rude. Why don't you start by showing us what YOU have done/tried/written so far, and tell us where you're stuck?

There are thousands of bash scripting tutorials and date examples you could find with a brief internet search; have you done any research?
 
Old 07-26-2021, 03:40 AM   #4
David the H.
Bash Guru
 
Registered: Jun 2004
Location: Osaka, Japan
Distribution: Arch + Xfce
Posts: 6,852

Rep: Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037Reputation: 2037
I'll bite, and offer a quick, general solution.

Assuming that...

1) this is a script for a modern shell like bash or zsh, and
2) the directories are named so that they sort naturally, and
3) there are no extraneous entries that could interfere with the sorting

...then you should be able to use simple shell globbing to match and capture all (or a range) of the directory names into an array, with the final array entry containing the one you want. There's no need to even worry about targeting exact dates with this technique.

I'll leave the implementation details for the user to research.
 
1 members found this post helpful.
  


Reply



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
[SOLVED] How to read date and convert it into yesterday's date ? sysmicuser Linux - Newbie 5 05-03-2018 11:28 PM
[SOLVED] Converting date feed into different date format keif Programming 5 07-08-2014 08:39 AM
how can i move to previous system date using command line karan_bagaria Linux - Newbie 5 09-22-2010 04:01 PM
Create a script to cd into my previous directory alpha883 Programming 4 05-08-2009 08:55 AM
date command getting previous day swinchen Programming 6 08-23-2004 12:17 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Virtualization and Cloud

All times are GMT -5. The time now is 07:36 AM.

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