Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Creating a directory based on date Post 302952659 by wisecracker on Thursday 20th of August 2015 04:19:34 PM
Old 08-20-2015
Not sure if this is what you want...
OSX 10.7.5, default bash terminal.
Just loop it as required and modify to suit...
Code:
#!/bin/bash
# newdir
YEARPATH="/Users/barrywalker/"
DATE=( $(date) )
if [ -e "$YEARPATH${DATE[3]}" ]
then
	echo "Drawer exists..."
	sleep 1
else
	mkdir "$YEARPATH${DATE[3]}"
fi
exit 0

Results...
Code:
Last login: Thu Aug 20 21:12:56 on ttys000
AMIGA:barrywalker~> cd Desktop/Code/Shell
AMIGA:barrywalker~/Desktop/Code/Shell> chmod 755 newdir
AMIGA:barrywalker~/Desktop/Code/Shell> ls /Users/barrywalker/
03080.sh		AAWG			Movies
03083.sh		AudioScope.sh		Music
03090.sh		AudioScope.sh.txt	Pictures
03100.sh		AudioScope.sh~		Public
03120.sh		AudioScope.txt		Scope
03140.sh		BW_HELP			URL
03180.sh		Desktop			listing.txt
03197.sh		Documents		sox-14.4.0
03220.sh		Downloads
03220.txt		Library
AMIGA:barrywalker~/Desktop/Code/Shell> ./newdir
AMIGA:barrywalker~/Desktop/Code/Shell> ls /Users/barrywalker/
03080.sh		2015			Library
03083.sh		AAWG			Movies
03090.sh		AudioScope.sh		Music
03100.sh		AudioScope.sh.txt	Pictures
03120.sh		AudioScope.sh~		Public
03140.sh		AudioScope.txt		Scope
03180.sh		BW_HELP			URL
03197.sh		Desktop			listing.txt
03220.sh		Documents		sox-14.4.0
03220.txt		Downloads
AMIGA:barrywalker~/Desktop/Code/Shell> ./newdir
Drawer exists...
AMIGA:barrywalker~/Desktop/Code/Shell> ./newdir
Drawer exists...
AMIGA:barrywalker~/Desktop/Code/Shell> ./newdir
Drawer exists...
AMIGA:barrywalker~/Desktop/Code/Shell> _

Notice the 2015 drawer now exists and is ignored until the next year is reached.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script for Creating Directory with name as system date

Dear Sir/Madam, I need a bit of your help. The problem is as follows : I have to create a directory in unix whose name is that of system date in the dd_mon_yyyy format . I am able to extract a date in required format ina variable , but when i'm using this variable in mkdir it is not... (7 Replies)
Discussion started by: aarora_98
7 Replies

2. Shell Programming and Scripting

shell script to selectively tar directory based on date

hye everybody :) , i'm new to the scripting world.. hope you guys can help me out with this one.. i'm trying to identify any directory under /tmp/saya that is created more than one day from the current date.. e.g, today is March 14, so any directory that has time stamp March 13 backwards, i... (2 Replies)
Discussion started by: fara_aris
2 Replies

3. Shell Programming and Scripting

Creating date directory and moving files into that directory

I have list of files named file_username_051208_025233.log. Here 051208 is the date and 025233 is the time.I have to run thousands of files daily.I want to put all the files depending on the date of running into a date directory.Suppose if we run files today they should put into 05:Dec:08... (3 Replies)
Discussion started by: ravi030
3 Replies

4. Shell Programming and Scripting

Need script to select multiple files from archive directory based on the date range

hi all, here is the description to my problem. input parameters: $date1 & $date2 based on the range i need to select the archived files from the archived directory and moved them in to working directory. can u please help me in writing the code to select the multiple files based on the... (3 Replies)
Discussion started by: bbc17484
3 Replies

5. Shell Programming and Scripting

creating a file name based on date

I need to automate a weekly process of piping a directory list to a csv file. Normally I do ls -l > files_04182010.csv (04182010 being the date..) Can someome show me how I would script this, so that when the script is ran it grabs the current date and formats it and allows me to use that... (8 Replies)
Discussion started by: jeffs42885
8 Replies

6. Shell Programming and Scripting

finding the previous day date and creating a file with date

Hi guys, I had a scenario... 1. I had to get the previous days date in yyyymmdd format 2. i had to create a file with Date inthe format yyyymmdd.txt format both are different thanks guys in advance.. (4 Replies)
Discussion started by: apple2685
4 Replies

7. Shell Programming and Scripting

Moving files from one directory to another based on 2 date variables

Hi All, I am currently coding for a requirement(LINUX OS) where I am supposed to move a file (Lets Call it Employee.txt) from Directory A to Directory B based on 2 date fields as below, Date_Current = 20120620 Date_Previous = 20120610 Source Directory : /iis_data/source Target... (11 Replies)
Discussion started by: dsfreddie
11 Replies

8. Shell Programming and Scripting

Move files from one directory to another based on creation/modification date

Hi All, Really stuck up with a requirement where I need to move a file (Lets say date_Employee.txt--the date will have different date values like 20120612/20120613 etc) from one directory to another based on creation/modification dates. While visiting couple of posts, i could see we can... (3 Replies)
Discussion started by: dsfreddie
3 Replies

9. UNIX for Dummies Questions & Answers

Unable to find files, those can be present anywhere in the directory tree,based on its creation date

Hi I am unable to find files, those are present anywhere in the same directory tree, based on the creation date. I need to find the files with their path, as I need to create them in another location and move them. I need some help with a script that may do the job. Please help (2 Replies)
Discussion started by: sam192837465
2 Replies

10. UNIX for Beginners Questions & Answers

Searching for a files based on current date directory

Hi All, I've been trying to do some recursive searching but not been very successful. Can someone please help. Scenario: I have directory structure /dir1/dir2/dir3/ 2019/ 11/ 17 18 19 20 so what I want to do is run a script and as its 2019/11/18/ today it would go and only search... (3 Replies)
Discussion started by: israr75
3 Replies
sysman_intro(8) 					      System Manager's Manual						   sysman_intro(8)

NAME
sysman_intro - Introduction of SysMan applications DESCRIPTION
SysMan is a suite of applications for managing Tru64 UNIX systems. The SysMan applications provide a simple, easy to use, graphical user interface (GUI) for common system management tasks including installation and configuration. When you follow the installation instructions in the Installation Guide, the installation GUI, Installation Setup, is displayed automati- cally. To help you prepare the system for general use, the Tru64 UNIX: System Setup checklist is displayed when you log in as root for the first time after performing an installation. SysMan applications and help are available from the Application Manager (tool drawer) icon on the CDE front panel, or from the SysMan Applications panel above the SysMan Station icon on the root CDE window. For additional information, see the Welcome to SysMan help volume by performing the following procedure: Click on the Application Manager icon (the file drawer) on the CDE front panel. Double click on the System_Admin application group icon. Double click on the Welcome to SysMan icon. If you are not running CDE, but have installed it, you can open the Welcome to Sysman help volume by entering the following sequence of commands at the command line: /bin/sh PATH=$PATH:/usr/dt/bin export PATH DTHELPSEARCHPATH=/usr/dt/appconfig/help/C/%H export DTHELPSEARCH- PATH DTUSERSESSION=${USER}-`uname -n`-0 export DTUSERSESSION dthelpgen -dir $HOME/.dt/help/$DTUSERSESSION dthelpview -helpVolume browser SEE ALSO
Commands: bttape(8), bindconfig(8), diskconfig(8), dxaccounts(8), dxadvfs(8), dxarchiver(8), dxdw(8), dxfileshare(8), dxhosts(8), dxkernel- tuner(8), dxlicenses(8), dxlsm(8), dxpower(8), dxpresto(8), dxproctuner(8), dxshutdown(8), dxsysinfo(8), mailconfig(8), mailusradm(8), net- config(8), nfsconfig(8), printconfig(8), sysman(8), System Administration Release Notes Installation Guide Technical Overview X Window System Administrator's Guide Network Administration Common Desktop Environment: User's Guide CDE Companion Common Desktop Environment: Advanced User's and System Administrator's Guide Common Desktop Environment: Programmer's Overview Common Desktop Environment: Programmer's Guide Common Desktop Environment: Help System Author's and Programmer's Guide Common Desktop Environment: Style Guide and Certification Checklist OSF/Motif Style Guide sysman_intro(8)
All times are GMT -4. The time now is 06:24 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy