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 display in mm/dd/yyyy format
I tried with;
Code:
find ./ -name "pkg3[23]*" -type d | xargs ls -ld
find ./ -name "pkg3[23]*" -type d -exec ls -ld {} \; | awk '{print $6,$7,$8,$9}'
But I want the output to be sorted with creation date;
Code:
$ find ./ -name "pkg3[2]*" -type d -exec ls -ld {} \; | awk '{print $6,$7,$8,$9}'
Oct 24 2012 ./pkg320.0_20121025_mrg
Oct 25 2012 ./pkg320.0_20121025_fix
Oct 31 2012 ./pkg320.0_20121101
Oct 31 2012 ./pkg320.0_20121101_ret
Nov 4 2012 ./pkg320.0_dev02_20121104
Nov 7 23:24 ./pkg320.0_20121108
Nov 13 19:57 ./pkg320.0_20121114
Nov 29 13:56 ./pkg320.0_20121004_prof
Nov 29 13:56 ./pkg320.0_20121129_fix
Nov 28 14:42 ./pkg320.0_20121101_prof
Nov 28 14:43 ./pkg320.0_20121108_prof
Nov 29 15:31 ./pkg320.0_20121129_fix1
Dec 7 12:51 ./pkg321.0_20121207_56
Dec 11 15:06 ./pkg321.0_20121211_CR5875
Dec 4 21:48 ./pkg321.0_20121205
Dec 11 23:03 ./pkg321.0_20121212
Dec 11 23:05 ./pkg321.0_20121212_ret
Dec 14 11:02 ./pkg321.0_20121214_CR_fix
Dec 17 09:53 ./pkg321.0_20121217_fix
Dec 17 10:08 ./pkg321.0_20121216_fix
Dec 19 15:57 ./pkg321.0_20121219
Dec 31 23:50 ./pkg322.0_20130102
Jan 9 09:56 ./pkg322.0_20130109
Jan 9 09:57 ./pkg322.0_20130109_ret
Jan 11 11:28 ./pkg322.0_20130111_fix
Jan 16 10:41 ./pkg322.1_20130116_ret
Jan 23 21:12 ./pkg322.3_20130124
Feb 12 22:18 ./pkg322.6_20130212_ret
Mar 19 16:30 ./pkg321.0_20121205_prof
Mar 19 17:51 ./pkg321.0_20121212_prof
Mar 19 18:32 ./pkg322.0_20130102_prof
May 1 2012 ./pkg320.0_dev02_20120205
May 1 2012 ./pkg320.0_dev02_20120401
Jul 6 2012 ./pkg320.0_dev02_20120708
Aug 3 2012 ./pkg320.0_dev02_20120805
Most UNIX Systems do not keep track of the creation date of a file (only the last access time, the last (data) modification time, and the last status modification time timestamps are specified by the standards). Sorting by ls (with the -t option and without the -S, -c, and -m options) sorts by increasing data modification time. But, as I'm sure you've noticed from the output in your examples, anything with a date in the future and anything with a date more than six months old will print the month, day, and year of the date while dates within the last six months will be printed with the month, day, and time of day (in 24 hour format).
So the command:
Code:
ls -ldt pkg3[23]* | grep '^d'
will give you the list of directories in the current directory matching the patterns you want sorted by increasing timestamp and the command:
Code:
ls -lrdt pkg3[23]* | grep '^d'
will give you the same list sorted in reverse order.
But, neither of these will print the date in MM/DD/YYYY format.
Does HP/UX B.11.31 include a stat utility?
Do you just want directories located in the current directory, or do you also want to process subdirectories with matching names?
Do any of your directory names contain one or more space or tab characters? Do any of your directory names contain one or more newline characters? If the answer to both of these is no, there are several simplifying assumptions we can make.
Is MM/DD/YYYY format a requirement or a nice-to-have feature? If it is a requirement and your system doesn't have a stat utility, would you rather have a complicated shell script or a relatively simple C program?
What I know so far:
ls -A will list all files except those starting with a dot
ls -d will list all directories
ls -m will separate contents by commas
For getting crtimes use:
stat filename will give me the inode number
or
ls -i filename will give... (13 Replies)
i am having trouble creating a directory with last months date as the folder name.
what i am using is echo `date +%b%y`
which gives
Mar14 as the result but i want to get Feb14 as the result.:wall: (6 Replies)
Can anyone come up with a unix command that lists
all the files, directories and sub-directories in the current directory
except a folder called log.?
Thank you in advance. (7 Replies)
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)
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)
Hi all,
Using grep command, i want to find the pattern of text in all directories and sub-directories.
e.g: if i want to search for a pattern named "parmeter", i used the command
grep -i "param" ../*
is this correct? (1 Reply)
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)
Hi,
Please help me, how to get all the direcotries, its sub directories and its sub directories recursively, need to exclude all the files in the process.
I wanted to disply using a unix command all the directories recursively excluding files.
I tried 'ls -FR' but that display files as... (3 Replies)
Hi ,
I am very new to unix as well as shell scripting. I have to write a script for the following requirement.
In a particular mount, have to list all the directories and sub directories along with size of the directory and sub directory in ascending order.
Please help me in this regard and many... (4 Replies)
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)