简体   繁体   中英

How to list last 10 files in all the subdirectories in Linux

I have a directory and there a multiple sub directories under that, i want to display the last 10 files recursively from all the subdirectories or if i can mention some date parameters to list also will be helpful

Save the name of all directories.

  ls -R $PWD/* | grep ./ > allDirectories

The next line show 10 files of each directory (only if the directory don't have spaces in their name). You can add more options to the ls command (ie sort by time using -c)

for directory in $(cat allDirectories); do echo '\n\n\n'$directory; ls $directory[1,-2] | head -n 10; done 2>> /dev/null

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM