based on file type

base on time

Print all the files that were accessed within the last 7 days as follows:

$ find . -type f -atime -7 -print

Print all the files that are having access time exactly 7 days old as follows:

$ find . -type f -atime 7 -print

Print all the files that are having access time older than 7 days as follows:

$ find . -type f -atime +7 -print

Access time (-atime): This is the last timestamp of when the file was accessed by some user
Modification time (-mtime): This is the last timestamp of when the file content was modified
Change time (-ctime): This is the last timestamp of when the metadata for a file

based on user or permission

exec

find . -type f –user root –exec chown xyz {} \;

For each file match, {} will be replaced with the file name in place for –exec. For example, if the find command
finds two files test1.txt and test2.txt with owner slynux, the find command will perform:
chown xyz {} This gets resolved to chown xyz test1.txt and chown xyz test2.txt.

\; is the exec command termination symbol. some system will also allow to use + to terminate the command.

Another usage example is to concatenate all the C program files in a given directory and write
it to a single file all_c_files.txt. We can use find to match all the C files recursively and
use the cat command with the -exec flag as follows:

$ find . -type f -name "*.c" -exec cat {} \;>all_c_files.txt

interesting, we used the > operator instead of » (append) because the entire output from the find command
is a single data stream (stdin).

find . -type f -name "*.txt" -exec printf "Text file: %s\n" {} \;

xargs

background

pipe is used to redirect stdout (standard output) of a command to stdin (standard input) of another command.

however, some of the commands/applications accept data as command-line arguments rather than a data
stream through stdin (standard input). In that case, we cannot use pipes to supply data through command-line arguments.

xargs is a command that is very helpful in handling standard input data to the command-line argument conversions