Ls ignoring files from their modification time


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Ls ignoring files from their modification time
# 1  
Old 05-10-2012
Ls ignoring files from their modification time

Hi everyone,

I'd like to know if is there a way to list files but ignoring some according to their modification time (or creation, access time, etc.) with the command 'ls' alone.

I know the option -I exist, but it seems to only looking in the file name..

Thank you in advance for the answers.

P.S : Ftm, I'm transferring the result of 'ls' to awk (by pipe ofc)..maybe there is a more elegant way to do so..
# 2  
Old 05-10-2012
awk

Hi,

Try this out,

Code:
#! /usr/bin/bash
for file in *;
do
   if [ -d "${file}" ];
   then
      echo "${file} is a Directory"
   elif [ -s "${file}" ];
   then
     awk 'END{print FILENAME;}' ${file}
   else
      echo "${file} is unknown file type"
   fi
done

I think the loop around the awk is the best idea with *(excludes spaces in file name issue).
I just wrote some simple example.
Please modify the code based on your req.

Cheers,
RangaSmilie
# 3  
Old 05-10-2012
Quote:
Originally Posted by Keyhaku
Hi everyone,

I'd like to know if is there a way to list files but ignoring some according to their modification time (or creation, access time, etc.) with the command 'ls' alone.

I know the option -I exist, but it seems to only looking in the file name..

Thank you in advance for the answers.

P.S : Ftm, I'm transferring the result of 'ls' to awk (by pipe ofc)..maybe there is a more elegant way to do so..



find could be better choice for you.
look for -newer, -older, -mtime, -atime, -ctime options under that.
# 4  
Old 05-10-2012
Yes, I thought about find , the problem is that I have something like 1000 folders, and in each there are something like 200 files...And I'm only looking for one..

I tried to optimize find..but it's way way longer than ls..
# 5  
Old 05-10-2012
Quote:
tried to optimize find..but it's way way longer than ls..
I doubt it!

Please post what Operating System and version you are running and what Shell you are using. There is much variation in the ls command and as much variation in the find command.

Please state what your criteria are for selecting files.


(Please avoid using textspeak or obscure abbreviations when posting. Ftm? ofc?).
# 6  
Old 05-10-2012
@rangartasan
Not quite sure how the script addresses the original post. The script posted contains a couple of bugs and some excess semi-colon characters. Notably it did not deal with filenames containing spaces or files of zero length.

Code:
#! /usr/bin/bash
for file in *
do
   if [ -d "${file}" ]
   then
      echo "${file} is a Directory"
   elif [ -f "${file}" ]
   then
     awk 'END{print FILENAME;}' "${file}"
   else
      echo "${file} is unknown file type"
   fi
done

# 7  
Old 05-10-2012
Quote:
Originally Posted by Keyhaku
I tried to optimize find..but it's way way longer than ls..
How would find checking every single file, be slower than ls checking every single file?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

Getting files through find command and listing file modification time upto seconds

I have to list the files of particular directory using file filter like find -name abc* something and if multiple file exist I also want time of each file up to seconds. Currently we are getting time up to minutes in AIX is there any way I can get file last modification time up to seconds. (4 Replies)
Discussion started by: Nitesh sahu
4 Replies

2. OS X (Apple)

[OS X] Last modification time from shell in CCYYMMDDhhmm.ss format

This example shows last mtime from epoch $ stat -f %m somefile 752911565 But would like to see it like that: 199311100606.05 (2 Replies)
Discussion started by: Tribe
2 Replies

3. Shell Programming and Scripting

How to change modification time of file?

Explain it with proper e.g (4 Replies)
Discussion started by: sidpatil
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. UNIX for Dummies Questions & Answers

Need Modification Time of a file

Hi all, I need the modification time of a file on a particular day say 3 days before. I just don't want the last modification time. I need all the modification times on a particualar day. Is there anyway to do it? Kindly help. Could anyone tell me where the modification time is stored?... (1 Reply)
Discussion started by: vidhyab
1 Replies

6. Shell Programming and Scripting

Find and symbolic link modification time

Hi, I have a directory made up of many symbolic links to folders multiple file systems. I want to return folders modified within the last 50 days, but find is using the link time rather than the target time. find . -type d -mtime -50 Is there a way to either: a) Make a symbolic link... (1 Reply)
Discussion started by: earls
1 Replies

7. Shell Programming and Scripting

File modification time comparison

Hi All, I have two files (given below) each exists under different paths. I want to compare the modification time stamp of file1.txt is lessthan the modification time of file2.txt. month1=`ls -l file1.txt | awk '{ print $6}'` date1=`ls -file1.txt | awk '{ print $7}'` time1=`ls... (1 Reply)
Discussion started by: Arunprasad
1 Replies

8. Shell Programming and Scripting

time modification in script

Hi All.. I have a file with a number of non-unique entries as below: 1243 01:42:29,567 --> 01:42:32,108 blah blah .... blah blah .. 1244 01:42:32,709 --> 01:42:34,921 blah blah .... 1245 01:42:35,214 --> 01:42:36,533 blah blah .... blah blah .. blah blah .... blah blah .. (4 Replies)
Discussion started by: UniRock
4 Replies

9. Shell Programming and Scripting

Archive Files over certain modification time

Environment is cygwin on Windows Server 2003 as I could not think how I would achieve this using Windows tools. What I want ot achieve is the following. I have a Directory D:\Data which contains further subfolders and files. I need to move "files" older than 6 months modification time to... (4 Replies)
Discussion started by: jelloir
4 Replies

10. UNIX for Dummies Questions & Answers

File modification time

Does anyone know how to display the time with seconds of when a file was last modified. I can get hour & minutes but would also like seconds. --Running AIX (1 Reply)
Discussion started by: edog
1 Replies
Login or Register to Ask a Question