Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to view file date of result of find command in bash

Tags:

find

bash

ls

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?

like image 897
Farshid Avatar asked May 21 '12 07:05

Farshid


People also ask

What is the use of find command in Linux?

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.

How to use the date command in Bash format?

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 ...

How do I find a file's modified date in Linux?

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.

How do I find a file by its name in Linux?

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.


2 Answers

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.)

like image 128
Kilian Foth Avatar answered Oct 09 '22 17:10

Kilian Foth


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
like image 43
Bram Avatar answered Oct 09 '22 18:10

Bram