Find all files of specific type modified - find

I need a command or script that I can run from a folder in RedHat linux to find all files modified within a specified period.
I know I can use find ./ -mtime -120 which will find all files in relative sub-folders modified less than 120 days ago.
What I need is a way to specify certain file types.
[Edit] I have progressed a little with:
find ./ -mtime -120 -type f -name '*.H'
The question now is how do I specify multiple file types in the above ?

find ./ -mtime -120 -type f -name '*.[C|H]'
Finds all files in all relative sub-folders of with type C or H. Modified less than 120 days ago.

Related

how to rename multiple files in a folder with a specific format? perl syntax explanation [duplicate]

This question already has answers here:
How to rename multiple files in a folder with a specific format?
(2 answers)
Closed 2 years ago.
I asked a similar question previously, but need help to understand the Perl commands that achieve the renaming process. I have many files in a folder with format '{galaxyID}-psf-calexp-pdr2_wide-HSC-I-{#}-{#}-{#}.fits'. Here are some examples:
7-psf-calexp-pdr2_wide-HSC-I-9608-7,2-205.41092-0.41487.fits
50-psf-calexp-pdr2_wide-HSC-I-9332-6,8-156.64674--0.03277.fits
124-psf-calexp-pdr2_wide-HSC-I-9323-4,3-143.73514--0.84442.fits
I want to rename all .fits files in the directory to match the following format:
7-HSC-I-psf.fits
50-HSC-I-psf.fits
124-HSC-I-psf.fits
namely, I want to remove "psf-calexp-pdr2_wide", all of the numbers after "HSC-I", and add "-psf" to the end of each file after HSC-I. I have tried the following command:
rename -n -e 's/-/-\d+-calexp-/-\d+pdr2_wide; /-/-//' *.fits
which gave me the error message: Argument list too long. You can probably tell I don't understand the Perl syntax. Thanks in advance!
First of all, Argument list too long doesn't come from perl; it comes from the shell because you have so many files that *.fits expanded to something too long.
To fix this, use
# GNU
find . -maxdepth 1 -name '*.fits' -exec rename ... {} +
# Non-GNU
find . -maxdepth 1 -name '*.fits' -print0 | xargs -0 rename ...
But your Perl code is also incorrect. All you need is
s/^(\d+).*/$1-HSC-I-psf.fits/
which can also be written as
s/^\d+\K.*/-HSC-I-psf.fits/

Command line find if path matches and remove all contents

I'm trying to locate all folders that match a certain path.
The path is public_html/core/cache
I can find all instances of cache with the command below, however this does return results from elsewhere which are undesired!
find . -name cache -print
I've tried the below, but it presents an error.
find . -name public_html/core/cache -print
I'd like to run the script once to ensure the results are accurate, then afterwards run it again, removing all contents of the returned folder.
Many thanks in advance
A kind friend gave me the solution:
find / -type d -path "*core/cache" -print

find -type d and ls return different results on same directory

I'm trying to think of a reason find would return partial results on Ubuntu 16.04. I have a google drive mount (using plexdrive) located at
/home/user/media
When using
find $HOME/media -type d
16 results are returned. When using
ls -d $HOME/media/*/
186 results are returned. The folders are all browsable via sftp and samba shares, all permissions on relevant directories are 775. The content in the media directory is formatted as
a/a.ext
b/b.ext
c/c.ext
Has anyone seen this type of behavior before or have any clues on how to get find to return the full results?
This happens when find is looking at a directory with symbolic links. Use the -L flag to see the proper folder structure. find -L $HOME/media -type d

Recursively replace colons with underscores in Linux

First of all, this is my first post here and I must specify that I'm a total Linux newb.
We have recently bought a QNAP NAS box for the office, on this box we have a large amount of data which was copied off an old Mac XServe machine. A lot of files and folders originally had forward slashes in the name (HFS+ should never have allowed this in the first place), which when copied to the NAS were all replaced with a colon.
I now want to rename all colons to underscores, and have found the following commands in another thread here: pitfalls in renaming files in bash
However, the flavour of Linux that is on this box does not understand the rename command, so I'm having to use mv instead. I have tried using the code below, but this will only work for the files in the current folder, is there a way I can change this to include all subfolders?
for f in *.*; do mv -- "$f" "${f//:/_}"; done
I have found that I can find al the files and folders in question using the find command as follows
Files:
find . -type f -name "*:*"
Folders:
find . -type d -name "*:*"
I have been able to export a list of the results above by using
find . -type f -name "*:*" > files.txt
I tried using the command below but I'm getting an error message from find saying it doesn't understand the exec switch, so is there a way to pipe this all into one command, or could I somehow use the files I exported previously?
find . -depth -name "*:*" -exec bash -c 'dir=${1%/*} base=${1##*/}; mv "$1" "$dir/${base//:/_}"' _ {} \;
Thank you!
Vincent
So your for loop code works, but only in the current dir. Also, you are able to use find to build a file with all the files with : in the filename.
So, as you've already done all this, I would just loop over each line of your file, and perform the same mv command.
Something like this:
for f in `cat files.txt`; do mv $f "${f//:/_}"; done
EDIT:
As pointed out by tripleee, using a while loop is a better solution
EG
while read -r f; do mv "$f" "${f//:/_}"; done <files.txt
Hope this helps.
Will

Find files modified within one hour in HP-UX

I'm searching through the manual page for find I can't see a way to run a command which will find all files modified within an hour. I can see only a way to do it for days.
Guess this should do
find / -type f -mmin -60
This will be listing files starting from root and modified since the past 60 mins.
the best you can do in HP-UX using the find command is to look for everything that was modified in the last 24 hours. The HP-UX find command only checks modified time in 24-hour increments. This is done by:
find / -type f -mtime 1
This will list all of the filed recursively starting in the root directory that were modified in the last 24 hours. Here's the entry from the man page on the -mtime option:
-mtime n
True if the file modification time subtracted from the initialization time is n-1 to n multiples of 24 h. The initialization time shall be a time between the invocation of the find utility and the first access by that invocation of the find utility to any file specified in its path operands.
If you have the permissions to create the file, use this:
touch -t YYYYMMDDHHMM temp
Then use the -newer option
find . -newer temp
This should list the files newer than the temp file which can be created one hour ago.