Find todays files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Find todays files
# 1  
Old 10-12-2018
Find todays files

I am trying to find todays files only in the "root directories like /etc, /opt etc.

I do not want to search in my home directory or any of its subdirectories.

That's hard because a directory listing does not show the year?

-rw------- 1 andy andy 22487 Oct 12 13:40 .xsession-errors

Code:
find . -type f -ls |grep 'Oct 12'

# 2  
Old 10-12-2018
You dont mention your OS...
Have you seen all the options of find cmd?
# 3  
Old 10-12-2018
Code:
today=$(date +"%Y-%m-%d")

for dir in /etc /opt /tmp
do
   find $dir -type f -mtime -1 2>/dev/null | while read file
   do
      cdate=$(stat -c %y "$file")
      [[ ${cdate%% *} = $today ]] && echo "$file"
   done
done

This User Gave Thanks to rdrtx1 For This Post:
# 4  
Old 10-12-2018
Quote:
Originally Posted by vbe
You dont mention your OS...
Have you seen all the options of find cmd?
Ubuntu Mate 18.04

I looked for a way to add a signature here where I could list that.

Did not find it.
# 5  
Old 10-12-2018
Why not



Code:
stat -c"%y %n" /etc/* /opt/* | awk -vTD="$today" '$0 ~ "^" TD {sub ($1 FS $2 FS "\\" $3 FS, ""); print}'

or
Code:
stat -c"%y %n" /etc/* /opt/* | grep "^$today" | cut -d" " -f4-

# 6  
Old 10-12-2018
Quote:
Originally Posted by rdrtx1
Code:
today=$(date +"%Y-%m-%d")

for dir in /etc /opt /tmp
do
   find $dir -type f -mtime -1 2>/dev/null | while read file
   do
      cdate=$(stat -c %y "$file")
      [[ ${cdate%% *} = $today ]] && echo "$file"
   done
done

I would like the output to show the date and time of each file.

I can read up on it, just need a link. :-)
# 7  
Old 10-12-2018
Code:
DREF=/tmp/dref
# set file time to one second before midnight of today in
# this example midnight is 201810120000   %Y %m %d %H %S format (with no spaces)

touch -t 201810115959  $DREF

ls -a /etc /opt /foo /bar /farkle | while read fname 
do
  # regular file from today
  if [[  $fname -nt $DREF && -f $fname ]]; then
       echo $fname
  fi
done > todays_files
$rm $DREF

This User Gave Thanks to jim mcnamara For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to keep todays files based on Timestamp

Hi i need to keep todays files based on timestamp and archive the remaining files ex: Managerial_Country_PRD_20150907.csv Managerial_Country_PRD_20150907.csv Managerial_Country_PRD_20150906.csv Managerial_Country_PRD_20150905.csv (6 Replies)
Discussion started by: ram1228
6 Replies

2. UNIX for Dummies Questions & Answers

Script to keep todays files based on Timestamp

Hi i need to keep todays files based on timestamp and archive the remaining files ex: Managerial_Country_PRD_20150907.csv Managerial_Country_PRD_20150906.csv Managerial_Country_PRD_20150905.csv (2 Replies)
Discussion started by: ram1228
2 Replies

3. Shell Programming and Scripting

Shell script to compare two files of todays date and yesterday's date

hi all, How to compare two files whether they are same are not...? like i had my input files as 20141201_file.txt and 20141130_file2.txt how to compare the above files based on date .. like todays file and yesterdays file...? (4 Replies)
Discussion started by: hemanthsaikumar
4 Replies

4. Shell Programming and Scripting

Count for only todays files.

Hi, I unable to find the direct command get the total count for the below files with today date. ls -lrt c90.txt n5.txt t1.txt k3.txt h9.txt s1.txt n2.txt a123.txt -rw-rw-r-- kkk klkl 980 Apr 26 19:00 c90.txt -rw-rw-r-- kkk klkl 80 Apr 26 19:00 n5.txt -rw-rw-r-- kkk klkl 12890 Apr 26... (3 Replies)
Discussion started by: onesuri
3 Replies

5. Shell Programming and Scripting

How to list todays and yesterdays .rej files from a directory?

I am trying to display todays and yesterdays .rej files from a directory. ls -lrt *.rej | grep 'Aug 12' ; ls -lrt *.rej | grep 'Aug 13' Which is working as above. But i want take 'Aug 12' and 'Aug 13' from a variable and the command should work everyday. I am able to get todays files by... (9 Replies)
Discussion started by: GopalKrishnaP
9 Replies

6. Shell Programming and Scripting

Find and copy files based on todays date and search for a particular string

Hi All, I am new to shell srcipting. Problem : I need to write a script which copy the log files from /prod/logs directory based on todays date like (Jul 17) and place it to /home/hzjnr0 directory and then search the copied logfiles for the string "@ending successfully on Thu Jul 17". If... (2 Replies)
Discussion started by: mail.chiranjit
2 Replies

7. UNIX for Dummies Questions & Answers

need to zip all the files excluding todays file

HI All, At present in my server the log folder was filled up and causing memory issue. So I am planning to write a script in such a way that the files which are older than 30 days will be deleted and also need to find the files which were not compressed and need to compress this file.... (4 Replies)
Discussion started by: arumilli
4 Replies

8. Shell Programming and Scripting

Find files having todays date and hostname in its name.

Hello, I am quite new to unix/shell and want to write a script using bash which will process the files. Basically i want to search files having name as "date+hostname+somestring.out" i am using below variables and then will use them in find command :- TODAY_DATE=$('date +%d')... (5 Replies)
Discussion started by: apm
5 Replies

9. Shell Programming and Scripting

Count todays created files and old files

Hello experts, I used following approach to get listing of all files of remote server. Now I have remote server file information on same server. I am getting listing in the output.txt I want to count today's created files and old files. I want to compare the numbers... (11 Replies)
Discussion started by: dipeshvshah
11 Replies

10. Shell Programming and Scripting

Shell script help to eliminate files of todays date

Hi I am very new to shell scripting and have written a script (below). However the directory I am searching will contain a file with a .trn extension each day which I want to eliminate. Each day the file extension overnight will change to trx, if this fails I want to know. Basically what I... (2 Replies)
Discussion started by: richM
2 Replies
Login or Register to Ask a Question