List versus find command


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers List versus find command
# 8  
Old 01-09-2014
This should work:

Code:
find /path/to/dir/* ! -name . -prune -type f -ls

This User Gave Thanks to in2nix4life For This Post:
# 9  
Old 01-09-2014
Quote:
Originally Posted by in2nix4life
This should work:

Code:
find /path/to/dir/* ! -name . -prune -type f -ls

How can we filter this command with .css file only and by date !!
# 10  
Old 01-09-2014
You just add all the options you need as suggested before, such as the -name, -newer etc.

I would worry though that using /var/output/* as the place to search from might be expanded by the shell to a very long list and exceed the command line limit if there are lots of files in /var/output.



Robin

Last edited by rbatte1; 01-09-2014 at 12:20 PM.. Reason: Clarity (I hope)
# 11  
Old 01-09-2014
I agree Robin.

Personally I'd just yield to performing the task using a script myself, but that's just me. ;-)
# 12  
Old 01-09-2014
There are still two problems with the current command.

Code:
find . ! -name . -prune -type f -name "*.css" -ls -mtime 7
9697084 4883 -rw-rw----   1 5000032 Dec 30 11:59 ./P010111.css
9464599 4883 -rw-rw----   1 5000032 Jan  8 09:04 ./P020367.css
8896700 4883 -rw-rw----   1 5000032 Jan  2 21:19 ./P013461.css
9404834 4883 -rw-rw----   1 5000032 Jan  8 14:12 ./P020427.css

A) I wanted files for 2nd Jan only. But it displays all .css files

The help for find told me to use mtime

B) The file names is displays as ./P010111.css instead of just P010111.css
# 13  
Old 01-10-2014
Quote:
Originally Posted by mohtashims
There are still two problems with the current command.

Code:
find . ! -name . -prune -type f -name "*.css" -ls -mtime 7
9697084 4883 -rw-rw----   1 5000032 Dec 30 11:59 ./P010111.css
9464599 4883 -rw-rw----   1 5000032 Jan  8 09:04 ./P020367.css
8896700 4883 -rw-rw----   1 5000032 Jan  2 21:19 ./P013461.css
9404834 4883 -rw-rw----   1 5000032 Jan  8 14:12 ./P020427.css

A) I wanted files for 2nd Jan only. But it displays all .css files

The help for find told me to use mtime

B) The file names is displays as ./P010111.css instead of just P010111.css
There are other problems with this that you didn't mention. But, to get closer to what you wanted move the -ls primary after the -mtime primary:
Code:
find . ! -name . -prune -type f -name "*.css" -mtime 7 -ls
8896700 4883 -rw-rw----   1 5000032 Jan  2 21:19 ./P013461.css

But the files this lists will be files that are more than 6 * 24 hours old and less than or equal to 7 * 24 hours old at the time find starts; not files with dates between midnight at the start of the day and midnight at the end of the day on January 2, 2014.

If you want files with the date January 2, 2014 and you don't want the names to have the leading ./, you have several choices. Among them are:
Code:
#!/bin/ksh
trap 'rm -f $$.start $$.end' 0
touch -t 201401020000 $$.start
touch -t 201401030000 $$.end

printf "Using shell for loop:\n"
for i in *.css
do      if [[ "$i" -ot $$.end ]] && [[ "$i" -nt $$.start ]]
        then    ls -l "$i"
        fi
done

and:
Code:
#!/bin/ksh
trap 'rm -f $$.start $$.end' 0
touch -t 201401020000 $$.start
touch -t 201401030000 $$.end

printf "\nUsing find:\n"
find *.css -newer $$.start ! -newer $$.end -ls

Both of these scripts use features that are not defined by the POSIX Standards nor the Single UNIX Specifications. Although written using the Korn shell, the 1st script above should work with any ksh or bash shell.

The 2nd script may fail if *.css expands to a list of files that creates a find command line longer than your system's ARG_MAX limits or if the version of find on your system doesn't support the -ls primary.

If you just want a list of the file names (instead of long format ls output), change:
Code:
        then    ls -l "$i"

in the 1st script to:
Code:
        then    printf "%s\n" "$i"

and change:
Code:
find *.css -newer $$.start ! -newer $$.end -ls

in the 2nd script to:
Code:
find *.css -newer $$.start ! -newer $$.end

This User Gave Thanks to Don Cragun For This Post:
# 14  
Old 01-10-2014
thank you so much !!

Last edited by mohtashims; 01-10-2014 at 10:18 AM..
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Find command to find a word from list of files

I need to find a word '% Retail by State' in the folder /usr/sas/reports/RetailSalesTaxallocation. When I tried like below, -bash-4.1$ cd /usr/sas/reports/RetailSalesTaxallocation -bash-4.1$ find ./ -name % Retail by State find: paths must precede expression: Retail Usage: find ... (10 Replies)
Discussion started by: Ram Kumar_BE
10 Replies

2. Shell Programming and Scripting

List last 1 hour files with out FIND command

Hi Friends, Can we have an alternate command to list last 1hour files with out FIND command? Thanks Suresh (6 Replies)
Discussion started by: suresh3566
6 Replies

3. UNIX for Dummies Questions & Answers

Code to list the files of find command

hi, i want to list the files from the below find commands output. find ./* -name "*.txt" -type f -mtime +10 will give the output like ./a.txt but i need the output in the format like (ls -lrt a.txt ) -rw-rw-rw- 1 srea nast 5 May 23 07:34 a.txt i used xargs for the... (4 Replies)
Discussion started by: msathees
4 Replies

4. Shell Programming and Scripting

How to list the files based on the modification time using the find command?

Hi All, I need to list the files based modification time of the files from a directory, I cannot use "ls -t" as there are lot of files, which "ls" command cannot handle. New files will land there daily. So iam looking for an alternative through "find"command. All suggestions are welcomed. ... (6 Replies)
Discussion started by: Kesavan
6 Replies

5. Shell Programming and Scripting

how assign the O/p of find command to a list.

i want to take the o/p of find command into a list like in java. can anyone help me regarding this. (10 Replies)
Discussion started by: dineshmurs
10 Replies

6. Shell Programming and Scripting

Help with find command and list in a long format each found file

The purpose of those comands are to find the newest file in a directory acvrdind to system date, and it has to be recursively found in each directory. The problem is that i want to list in a long format every found file, but the commands i use produce unexpected results ,so the output lists in a... (5 Replies)
Discussion started by: alexcol
5 Replies

7. Shell Programming and Scripting

command find returned bash: /usr/bin/find: Argument list too long

Hello, I create a file touch 1201093003 fichcomp and inside a repertory (which hava a lot of files) I want to list all files created before this file : find *.* \! -maxdepth 1 - newer fichcomp but this command returned bash: /usr/bin/find: Argument list too long but i make a filter all... (1 Reply)
Discussion started by: yacsil
1 Replies

8. UNIX for Dummies Questions & Answers

Question about DOS versus Unix Command?

Okay here is a DOS comparison. When I search for a file in DOS and I was not sure what directory it was in then I would put dir /s/o/p filename the s would tell it to look in every directory including subs, the o would sort it alphabetically and the p would limit the display to one page at a... (1 Reply)
Discussion started by: wmosley2
1 Replies

9. UNIX for Dummies Questions & Answers

CTRL+H versus ^? versus BACKSPACE

Hi Gurus! I recently got my shell account (HP UX v11) created by our sysadmin and am having problem deleting with the backspace key. After doing some reading, I believe I need to enter a custom "STTY..." statement in my profile. Can someone please help me with the correct "STTY" sequence... (3 Replies)
Discussion started by: alan
3 Replies

10. UNIX for Dummies Questions & Answers

solaris2.6 command to find/list system configuration

Hi. What command can be used to determine the system configuration. For example I want to find out how much CPU, how much memory, what CPU and 233mhz or 400mhz, etc. Please help.... (4 Replies)
Discussion started by: subhransu
4 Replies
Login or Register to Ask a Question