how can i find the modified files in ubuntu - unix

I want to find the details of the modified files such as size, permission and modified time in ubuntu and set the cron jobs in cpanel,i have used like this
find /home1/sitename/public_html/ -type f -ctime -1 -exec ls -ls {}
and also like this
find /home1/sitename/public_html/-type f -ctime -1 -exec ls -ls {} \;
but it is not working .
Now I want all the details of the files modified .

try this :
find /home1/sitename/public_html/-type f -ctime -1 | xargs ls -ls

Related

Searching for particular files in a directory non-recursively using find. AIX

I have a script which has the following command. I am trying to edit this in such a way that it only searches the files in the directory of the path without going in the subdirectories. That is not recursive search
find {Path} -name "cor*" -type f -exec ls -l {} \;
Example: The command should give cor123.log only and not cor456.log. Currently it gives both
<Path>
..cor123.log
<directory>
..cor456.log
I tried using -maxdepth but it's not supported in AIX. -prune and -depth didn't help either.
Will appreciate any help. Thanks
You can use
find . -name . -o -prune
to find files and directories non-recursively.
So in your case this one will work:
find . -name . -o -prune -name 'cor*' -type f -exec ls -l {} \;
Do you need find for selecting files only?
When you know that all files starting with cor are regula files, you can use
ls -l ${Path}/cor*
or
ls -l ${Path}/cor*.log
When you need the -type f, you can try to filter the results.
The filename can not have a /, so remove everything with an / after the Path.
We do not know the last char of ${Path}. It can be /, which will make the grep -Ev "${Path}/.*/" filter useless. After the Path at least one character is needed before looking for the next /.
find "${Path}" -name "cor*" -type f 2>/dev/null| grep -Ev "${Path}..*/" | xargs -ls
Late answer but may save some. In aix
find /some/directory/* -prune -type f -name *.log
For instance make your path have the last forward slash with a wildcard then -prune
/*
find /some/directory/* -prune -name "cor*" -type f -exec ls -l {} \
Tested.

KSH - Check return code on individual commands in find -maxdepth 0 $path -type f -mtime +$daysold -exec rm -fv {}\;

I am trying to figure out how to check the return codes on the find command and the rm -fv command in the following statement:
find -maxdepth 0 $path -type f -mtime +$daysold -exec rm -fv {}\;
Basically, if an error occurs, I want to know if it occurred in the find or the rm command and forward that information to our developers via e-mail. How would I go about this? I understand if I look at $?, it will just look at the statement as a whole.
The find uses the return code of the -exec command as a predicate: if the command was successful - the file matches.
Thus you can make the find to print all the files for which the rm -fv command has failed by negating the predicate with the !:
find -maxdepth 0 $path -type f -mtime +$daysold ! -exec rm -fv {} \; -print
(You have to add -print since the presence of -exec overrides the default implicit -print.)
You can redirect the output of the find into a file, and if the file is not empty, then you can e-mail it accordingly.

Unix: find files in every subdirectory named upd

I have directory tree structure which looks like this
/app/bad/upd /app/pass/upd /app/bad/upd /app/warn/upd
I want to build a find command which can list all the files in every sub-directory named upd.
Currently I list it individually
find /app/bad/upd -type f -name "*${FILE_NAME}*"
This might be what you look for:
find /app -type d -name upd -exec ls -l {} +
or perhaps:
find /tmp/* -type d -name upd -exec sh -c "ls -l {}/*${FILE_NAME}* 2>/dev/null" sh {} \;
If the upd directory is always in the 2nd directory down, you could simply do:
ls /app/*/upd

Concatenate all files recursively, ignoring one file extension

I want to create a concatenated file which appends all files except those which end in .XYZ from a directory (recursing into subdirectories).
I tried this but it does not work:
find . -type f | grep -v *.XYZ -exec cat {} \; > /tmp/alldata.txt
This works but fails to exclude files ending in ".XYZ":
find . -type f -exec cat {} \; > /tmp/alldata.txt
find . -type f -not -name "*.XYZ" -exec cat {} \; > /tmp/alldata.txt
More recent versions of gnu find include -not which negates the next argument. In this case, you can combine that with the -name argument to get what you want without invoking grep -v.

How to move or copy files listed by 'find' command in unix?

I have a list of certain files that I see using the command below, but how can I copy those files listed into another folder, say ~/test?
find . -mtime 1 -exec du -hc {} +
Adding to Eric Jablow's answer, here is a possible solution (it worked for me - linux mint 14 /nadia)
find /path/to/search/ -type f -name "glob-to-find-files" | xargs cp -t /target/path/
You can refer to "How can I use xargs to copy files that have spaces and quotes in their names?" as well.
Actually, you can process the find command output in a copy command in two ways:
If the find command's output doesn't contain any space, i.e if the filename doesn't contain a space in it, then you can use:
Syntax:
find <Path> <Conditions> | xargs cp -t <copy file path>
Example:
find -mtime -1 -type f | xargs cp -t inner/
But our production data files might contain spaces, so most of time this command is effective:
Syntax:
find <path> <condition> -exec cp '{}' <copy path> \;
Example
find -mtime -1 -type f -exec cp '{}' inner/ \;
In the second example, the last part, the semi-colon is also considered as part of the find command, and should be escaped before pressing Enter. Otherwise you will get an error something like:
find: missing argument to `-exec'
find /PATH/TO/YOUR/FILES -name NAME.EXT -exec cp -rfp {} /DST_DIR \;
If you're using GNU find,
find . -mtime 1 -exec cp -t ~/test/ {} +
This works as well as piping the output into xargs while avoiding the pitfalls of doing so (it handles embedded spaces and newlines without having to use find ... -print0 | xargs -0 ...).
This is the best way for me:
cat filename.tsv |
while read FILENAME
do
sudo find /PATH_FROM/ -name "$FILENAME" -maxdepth 4 -exec cp '{}' /PATH_TO/ \; ;
done

Resources