Solved

Linux Find syntax

Posted on 2014-01-29
4
426 Views
Last Modified: 2014-02-14
Let's say I wanted to find all php files created on the server within the past month.  What would the syntax be?

find / -name *.php ...and?

Thanks!
0
Comment
Question by:erzoolander
  • 2
4 Comments
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 250 total points
ID: 39818831
find / -name "*.php" -ctime -30

will find all files whose inode information was changed within the last 30 days.
File creation times don't get recorded in Linux/Unix, unfortunately.
0
 
LVL 34

Assisted Solution

by:Dan Craciun
Dan Craciun earned 125 total points
ID: 39818836
find / -type f -name "*.php" -newermt 2014-01-01
0
 
LVL 68

Assisted Solution

by:woolmilkporc
woolmilkporc earned 250 total points
ID: 39818942
OK,

in case your "find" doesn't support "-newermt" and if you really want to find all "*.php" files from the last calendar month (Dec. 2013 in our case) then try this:

touch -t $(date -d "1 month ago" "+%Y%m")"010000" /tmp/from
touch -t $(date "+%Y%m")"010000" /tmp/to
find / -name "*.php" -newer /tmp/from ! -newer /tmp/to
rm /tmp/from /tmp/to

The script calculates the last month and the corresponding year on its own, no need to customize anything.
0
 
LVL 13

Assisted Solution

by:Sandy
Sandy earned 125 total points
ID: 39823432
find / -name "*.php" -ctime -30
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How many times have you wanted to quickly do the same thing to a list but found yourself typing it again and again? I first figured out a small time saver with the up arrow to recall the last command but that can only get you so far if you have a bi…
Join Greg Farro and Ethan Banks from Packet Pushers (http://packetpushers.net/podcast/podcasts/pq-show-93-smart-network-monitoring-paessler-sponsored/) and Greg Ross from Paessler (https://www.paessler.com/prtg) for a discussion about smart network …
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question