I use a find command to find some kinds of files in bash. Everything goes fine unlness the result that is shown to me just contains the file name but not the (last modification) date of file. I tried to pipe it into ls or ls -ltr but it just does not show the filedate column in result, also I tried this:
ls -ltr | find . -ctime 1
but actually I didn't work. Can you please guide me how can I view the filedate of files returned by a find command?
The find command in Linux is a command-line utility for traversing the file hierarchy. It can be used to find and track files and directories. It supports searching by file, folder, name, creation date, modification date, owner and permissions. By using the ‘-exec’ command, you can execute other Linux commands on the found files or folders.
Date command in Bash Format Description date +%a Gives name of the weekday [Mon, Sun, Fri ... date +%A Gives name of the weekday [Monday, Sunda ... date +%b Gives name of the month [Jan, Feb, Mar] date +%B Gives name of the month [January, Februa ... 15 more rows ...
In Linux, we can usually display a file’s modified date or timestamp by listing its parent directory. The other common way to get this information is by using the stat command. Sometimes, it might be handy or more efficient to display this information while searching for files.
If you want to find a file by its name, expression is the file name. If you want to find files with name matching a pattern, expression in the pattern. This command will run a search in the current directory and its subdirectories to find a file (not directory) named myfile. The option -type f asks it to look for files only.
You need either xargs
or -exec
for this:
find . -ctime 1 -exec ls -l {} \;
find . -ctime 1 | xargs ls -l
(The first executes ls
on every found file individually, the second bunches them up into one ore more big ls
invocations, so that they may be formatted slightly better.)
If all you want is to display an ls like output you can use the -ls
option of find:
$ find . -name resolv.conf -ls
1048592 8 -rw-r--r-- 1 root root 126 Dec 9 10:12 ./resolv.conf
If you want only the timestamp you'll need to look at the -printf
option
$ find . -name resolv.conf -printf "%a\n"
Mon May 21 09:15:24 2012
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With