[Solved] Creation of directories


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting [Solved] Creation of directories
# 1  
Old 03-15-2014
[Solved] Creation of directories

i am having trouble creating a directory with last months date as the folder name.
what i am using is
Code:
echo `date +%b%y`

which gives
Code:
Mar14

as the result but i want to get Feb14 as the result.Smilie

Last edited by Scrutinizer; 03-15-2014 at 09:00 AM.. Reason: code tags
# 2  
Old 03-15-2014
Hi, what is your OS?

If you have GNU date you could do:
Code:
date -d"last month" +%b%y

or
And if you then also have a recent ksh93 you could use:
Code:
printf "%(%b%y)T\n" "last month"

# 3  
Old 03-15-2014
Question Creation of directories

hi I am using HP -UX

this is what iam getting

Code:
simka$printf "%(%b%y)T\n" "last month"

printf:  Error processing format last month
printf:  Error processing format
)T


Last edited by Scrutinizer; 03-15-2014 at 10:39 AM..
# 4  
Old 03-15-2014
Try:
Code:
perl -MPOSIX -sle '@t=localtime; $t[4]-=1 ; print strftime("%b%y",@t)'

or:
Code:
perl -MPOSIX -sle '@t=localtime; $t[4]-=$m ; print strftime("%b%y",@t)' -- -m=1


--
EDIT:

This does not work reliably when $t[4]-=1 is not a valid date..
Instead try:

Code:
perl -MPOSIX -sle '@t=localtime; $t[4]-=1 ; $t[3]=15; print strftime("%b%y",@t)'

or
Code:
perl -MPOSIX -sle '@t=localtime; $t[4]-=$m ; $t[3]=15; print strftime("%b%y",@t)' -- -m=1


Last edited by Scrutinizer; 03-30-2014 at 08:02 AM..
# 5  
Old 03-15-2014
thanks a lot the first one works and displays the date as i want but please tell me how do i create a directory using that..
ie
Code:
 NewLogDirName=`date +%d%b%Y`
mkdir -p ${LogDestDir}/${NewLogDirName}

so in this command how do i put it

Last edited by Scrutinizer; 03-15-2014 at 12:50 PM.. Reason: code tags
# 6  
Old 03-15-2014
Like so?
Code:
NewLogDirName=$(perl -MPOSIX -sle '@t=localtime; $t[4]-=1 ; print strftime("%b%y",@t)')

I noticed you used %d%b%Y though? Then use [ICODE]"%d%b%Y"[/ICODE] instead of [ICODE]"%b%y"[/ICODE]

--EDIT:--
That should be
Code:
perl -MPOSIX -sle '@t=localtime; $t[4]-=1 ; $t[3]=15; print strftime("%b%y",@t)'


Last edited by Scrutinizer; 03-30-2014 at 08:04 AM..
# 7  
Old 03-17-2014
thanks a lot Scrutinizer it has worked Smilie..
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

[Solved] Find the newest file in two directories

Hi i have two directories and files inside them Directory 1: Directory 2: These files are the same but song.mp3 in Directory 1 is newer than song.mp3 in Directory 2, and work.txt in Directory 2 is newer than work.txt in Directory 1. Now is my question. How i can compare these files... (10 Replies)
Discussion started by: Falstaff
10 Replies

2. UNIX for Dummies Questions & Answers

List the directories, having given pattern in the directories name, sorted by creation date

It is for HP-Unix B.11.31. Requirement: 1. List the directories, having given pattern in the directories name, sorted by creation date. Example: Directories with name "pkg32*" or "pkg33*" 2. On the output of 1. list the directories by creation date as sort order, with creation date... (2 Replies)
Discussion started by: Siva SQL
2 Replies

3. Shell Programming and Scripting

[Solved] Perform an operation to all directories

Sorry, about this thread - I solved my own problem! Thanks for taking a look. edit by bakunin: no problem, but it would have been a nice touch to actually tell us what the solution was. This would have been slightlich more educating than just knowing that you found it. I changed your title to... (0 Replies)
Discussion started by: Blue Solo
0 Replies

4. Shell Programming and Scripting

Automating creation of directories

I have a top-level directory called work and I would like to create subdirectories work1 work2... under this directory. Also I would like to create subdirectory under work1 -- test, work2 -- test etc., Can I automate this using a command-line script? work |_work 1 |_test |_work 2 ... (2 Replies)
Discussion started by: sharone
2 Replies

5. HP-UX

Symbolic link creation between 2 directories on different machines

I am trying to link 2 directories using: ln -s /net/<hostname>/srcdir/ /net/<desthostname>/dstdir/ I get the following error: ln: /net/<desthostname>/dstdir: Function is not available What is it that i am trying to do wrongly in the above operation? Please use next time code tags (3 Replies)
Discussion started by: Amit Kulkarni
3 Replies

6. UNIX for Dummies Questions & Answers

[Solved] Finding the Files In the Same Name Directories

Hi, In the Unix Box, I have a situation, where there is folder name called "Projects" and in that i have 20 Folders S1,S2,S3...S20. In each of the Folders S1,S2,S3,...S20 , there is a same name folder named "MP". So Now, I want to get all the files in all the "MP" Folders and write all those... (6 Replies)
Discussion started by: Siva Sankar
6 Replies

7. UNIX for Dummies Questions & Answers

List directories with given string, sort by creation date

It is for HP-Unix B.11.31. Requirement: 1. List the directories, which directories name has given particular string. Example: Directories with name "Build" 2. On the output of 1. list the directories by creation date as sort order. I tried with; find . -type d -name "Build*" ... (3 Replies)
Discussion started by: Siva SQL
3 Replies

8. UNIX for Dummies Questions & Answers

[solved] Script creation (how to include options in the script)

Hi guys i have written a script which takes the options given to him and execute itself accordingly. for example if a script name is doctortux then executing doctortux without option should made doctortux to be executed in automatic mode i.e. doctortux -a or if a doctortux is needed to run in... (4 Replies)
Discussion started by: pinga123
4 Replies

9. Shell Programming and Scripting

Creation of multiple directories

I have a folder structure like the below /test/test1/test2/app /test/test3/app /test/test4/test5/app .. I need to create a new folder under "app" in all the above listed directory structure at one shot by the name "subapp" . How can we acheive this using a script . New to unix... (4 Replies)
Discussion started by: rajeshnatarajan
4 Replies
Login or Register to Ask a Question