Solved

Linux Find syntax

Posted on 2014-01-29
4
421 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

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Over the last ten+ years I have seen Linux configuration tools come and go. In the early days there was the tried-and-true, all-powerful linuxconf that many thought would remain the one and only Linux configuration tool until the end of times. Well,…
Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to find files with the shell using the find and locate commands. Use locate to find a needle in a haystack.: With locate, check if the file still exists.: Use find to get the actual location of the file.:

708 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

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now