Архив рубрики: find

find php

link

I would recommend creating a new test.php files and inserting this code:

<?php
phpinfo();
?>

Then browse to test.php in a browser. This should give you a lot of information on php.

If you installed via an rpm also try

 rpm -ql php

or

 find / -name php.ini

find files between two dates

link

It’s two steps but I like to do it this way:

First create a file with a particular date/time. In this case, the file is 2008-10-01 at midnight

touch -t 0810010000/tmp/t

Now we can find all files that are newer or older than the above file (going by file modified date. You can also use -anewer for accessed and -cnewer file status changed).

find /-newer /tmp/t
find /-not -newer /tmp/t

You could also look at files between certain dates by creating two files with touch

touch -t 0810010000/tmp/t1
touch -t 0810011000/tmp/t2

This will find files between the two dates & times

find /-newer /tmp/t1 -and -not -newer /tmp/t2

Other Example

link

The syntax is as follows:

ls -l  | grep 'yyyy-mm-dd'
ls -l | grep --color=auto '2006-01-05'

Where,

  • 2006 – Year
  • 01 – Month
  • 05 – Day

You can sort it as follows:

ls -lu | grep --color=auto '2006-01-05'

find Command Example

If you need a specific date range many days ago, than consider using the find command. In this example find files modified between Jan/1/2007 and Jan/1/2008, in /data/images directory:

touch --date "2007-01-01" /tmp/start
touch --date "2008-01-01" /tmp/end
find /data/images -type f -newer /tmp/start -not -newer /tmp/end

You can save list to a text file called output.txt as follows:

find /data/images -type f -newer /tmp/start -not -newer /tmp/end > output.txt

List ALL *.c File Accessed 30 Days Ago

Type the following command

find /home/you -iname "*.c" -atime -30 -type -f

See also:

You need to use the find command. Each file has three time stamps, which record the last time that certain operations were performed on the file:

 

[a] access (read the file’s contents) – atime

[b] change the status (modify the file or its attributes) – ctime

[c] modify (change the file’s contents) – mtime

You can search for files whose time stamps are within a certain age range, or compare them to other time stamps.

You can use -mtime option. It returns list of file if the file was last accessed N*24 hours ago. For example to find file in last 2 months (60 days) you need to use -mtime +60 option.

  • -mtime +60 means you are looking for a file modified 60 days ago.
  • -mtime -60 means less than 60 days.
  • -mtime 60 If you skip + or – it means exactly 60 days.

So to find text files that were last modified 60 days ago, use
$ find /home/you -iname "*.txt" -mtime -60 -print

Display content of file on screen that were last modified 60 days ago, use
$ find /home/you -iname "*.txt" -mtime -60 -exec cat {} \;

Count total number of files using wc command
$ find /home/you -iname "*.txt" -mtime -60 | wc -l

You can also use access time to find out pdf files. Following command will print the list of all pdf file that were accessed in last 60 days:
$ find /home/you -iname "*.pdf" -atime -60 -type -f

List all mp3s that were accessed exactly 10 days ago:
$ find /home/you -iname "*.mp3" -atime 10 -type -f

There is also an option called -daystart. It measure times from the beginning of today rather than from 24 hours ago. So, to list the all mp3s in your home directory that were accessed yesterday, type the command
$ find /home/you -iname "*.mp3" -daystart -type f -mtime 1

Where,

  • -type f – Only search for files and not directories

-daystart option

The -daystart option is used to measure time from the beginning of the current day instead of 24 hours ago. Find out all perl (*.pl) file modified yesterday, enter:

find /nas/projects/mgmt/scripts/perl -mtime 1 -daystart -iname "*.pl"

You can also list perl files that were modified 8-10 days ago, enter:
To list all of the files in your home directory tree that were modified from two to four days ago, type:

find /nas/projects/mgmt/scripts/perl -mtime 8 -mtime -10 -daystart -iname "*.pl"

-newer option

To find files in the /nas/images directory tree that are newer than the file /tmp/foo file, enter:

find /etc -newer /tmp/foo

You can use the touch command to set date timestamp you would like to search for, and then use -newer option as follows

touch --date "2010-01-05" /tmp/foo
# Find files newer than 2010/Jan/05, in /data/images
find /data/images -newer /tmp/foo

Read the man page of find command for more information:
man find

 

mogrify resize compress and examples of find

many examples

Delete files by dir:

find path ./*/big_kartochka -print
find . -path ./*/big_kartochka -exec rm -rfv {} +

Find by:

find . -maxdepth 4 -iname "*original.jpg" ! -iname "*original.jpeg" ! -iname "*original.png"  -print -exec mogrify -resize 1280 {} \;
find \( -name '*.JPG' -o -name '*.jpg' -o -name '*.jpeg' -o -name '*.JPEG' \) -print -exec mogrify -compress JPEG -quality 80 {} \;
find ./*/original \( -name '*.JPG' -o -name '*.jpg' -o -name '*.jpeg' -o -name '*.JPEG' -o -name '*.png' -o -name '*.PNG' \) -print -exec mogrify -resize 1280 {} \;

Use the prune switch, for example if you want to exclude the misc directory just add a -path ./misc -prune -o to your find command:

find .-path ./misc -prune -o -name '*.txt'-print

Here is an example with multiple directories:

find .-type d \( -path dir1 -o -path dir2 -o -path dir3 \) -prune -o -print

Here we exclude dir1, dir2 and dir3, since in find expressions it is an action, that acts on the criteria -path dir1 -o -path dir2 -o -path dir3 (if dir1 or dir2 or dir3), ANDed with type -d. Further action is -o print, just print.

find ./*/a -name '*.jpg' -print
find -name "*.jpg" -print -exec mogrify -compress JPEG -quality 80 {} \;
find -name "*.jpg" -print -exec mogrify -compress JPEG {} \;
find -name "*.jpg" -print -exec mogrify -resize 320 -quality 75 {} \;
cd /Users/fred/tmp1
mogrify -path /Users/fred/cyclops2/ -format "_Resized.jpg" -resize 50% *.png
cd /Users/fred/tmp2
filelist=$(ls)
for file in $filelist; do
mv "$file" "$(echo "$file" | sed 's/._/_/g' )"
done
mogrify -resize 35%
cd fullsize
mogrify -resize 400x238 *.png
cd thumbs
mogrify -resize 288x171 *.png
cd $DIR
&& (
mogrify -resize 1024x768 *.JPG;
mogrify -auto-orient *.JPG
)
mogrify -density 200 -units PixelsPerInch *.png