Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all files (with full paths) in a directory (and subdirectories), order by access time

Tags:

I'd like to construct a Linux command to list all files (with their full paths) within a specific directory (and subdirectories) ordered by access time.

ls can order by access time, but doesn't give the full path. find gives the full path, but the only control you have over the access time is to specify a range with -atime N (accessed at least 24*N hours ago), which isn't what I want.

Is there a way to order by access time and get the full path at once? I could just write a script, but it seems there should be a way to do this with the standard Linux programs.

like image 526
Andrew Avatar asked Mar 08 '12 15:03

Andrew


People also ask

How do I list files in a directory with full path?

Listing the full path The command DIR /b will return just a list of filenames, when displaying subfolders with DIR /b /s the command will return a full pathname. To list the full path without including subfolders, use the WHERE command.

How do I get a list of files in a directory and subdirectories?

The dir command displays a list of files and subdirectories in a directory. With the /S option, it recurses subdirectories and lists their contents as well.

Which command is used to list all the files in sorted order?

The ls command is used to list files or directories in Linux and other Unix-based operating systems. Just like you navigate in your File explorer or Finder with a GUI, the ls command allows you to list all files or directories in the current directory by default, and further interact with them via the command line.

Which command will make a long listing of all the files on your system sorted by modification date?

ls command ls – Listing contents of directory, this utility can list the files and directories and can even list all the status information about them including: date and time of modification or access, permissions, size, owner, group etc.


2 Answers

find . -type f -exec ls -l {} \; 2> /dev/null | sort -t' ' -k +6,6 -k +7,7 

This will find all files, and sort them by date and then time. You can then use awk or cut to extract the dates and files name from the ls -l output

like image 172
Alex Avatar answered Sep 30 '22 19:09

Alex


you could try:

 ls -l $(find /foo/bar -type f ) 
  • you can add other options (e.g. -t for sorting) to ls command to achieve your goal.
  • also you could add your searching criteria to find cmd
like image 24
Kent Avatar answered Sep 30 '22 18:09

Kent