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


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers List the directories, having given pattern in the directories name, sorted by creation date
# 1  
Old 05-04-2013
HP 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

# 2  
Old 05-05-2013
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?
# 3  
Old 05-05-2013
Quote:
But I want the output to be sorted with creation date
Look at man ls for your HP-UX and see if there is an option to print the date in YYYY-MM-DD format, which you could sort.

On linux, the command is:
Code:
$ ls -l --time-style=full-iso
-rw-rw-r--  1 xxxxxx xxx       6586 2009-10-23 17:33:32.000000000 -0700 colors.html
-rw-------  1 xxxxxx xxx      37158 2013-05-04 00:48:19.403318848 -0700 toc.hpp

 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

List all files and directories in the current directory separated by commas and sorted by crtime

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)
Discussion started by: chstewar
13 Replies

2. Shell Programming and Scripting

[Solved] Creation of directories

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)
Discussion started by: simkazw
6 Replies

3. Shell Programming and Scripting

How to list all the files, directories and sub-directories in the current path except one directory?

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)
Discussion started by: Manjunath B
7 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

Using grep command to find the pattern of text in all directories and sub-directories.

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)
Discussion started by: vinothrajan55
1 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

List directories and sub directories recursively excluding files

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)
Discussion started by: pointers
3 Replies

9. Shell Programming and Scripting

How to list all the directories, sub directories in a mount along with size in ascending order?

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)
Discussion started by: nmakkena
4 Replies

10. 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