How do I find files in a Linux system? or specifically on Centos Linus?
The command ls will list files in a specific directory. Using the asterisk (*) its possible to display list of files and directory with wildcards.
E.g.
ls -l
ls -lt
ls -lrt
ls /etc
ls /etc/h*
Search files with command grep and ls
ls -lt /etc/ | grep filename
Search files with command find
find directory -type f -name filename
The command find provide more flexibility in search for files.
Search ordinary files that has the extension .cpp
find /home/you -iname "*.cpp" -type f
Search ordinary files that has the extension .cpp that are more than 30 days
find /home/you -iname "*.cpp" -atime -30 -type f
Search files from a given modified date
find . -type f -newermt 2023-01-01
Search files from a given access date
find . -type f -newerat 2017-09-25 ! -newerat 2017-09-26
Search files given a date range
touch --date "2007-01-01" /tmp/start.file
touch --date "2008-01-01" /tmp/end.file
find /data/images -type f -newer /tmp/start.file -not -newer /tmp/end.file
No comments:
Post a Comment