Saturday, April 27, 2024
1
rated 0 times [  1] [ 0]  / answers: 1 / hits: 1270  / 2 Years ago, sat, august 6, 2022, 3:30:18

I had created a .txt file but now I forgot where I save it and also the file name of it. So my question is: is there any method to filter out .txt files on descending order of created date? I'm currently using Ubuntu 12.04 on 32 bits.


More From » command-line

 Answers
6

Expanding on the comment from @soulsource you need to use the find command the most basic usage you could use is finding all files which end in .txt on your machine, the following command will descend though the file system starting at the root directory:



find / -type f -iname '*.txt' 


Now if you know you saved the file in a specific directory, your home directory for instance, but forget which sub directory you can always speed up the find by changing the path:



find ~/ -type f -iname '*.txt'


Now, you just need to pipe, |, the resulting files to ls to order them by date



find ~/ -type f -iname '*.txt' | xargs ls -td1


If you're getting a large number of files back, you can always limit the number of responses by piping it again to head. As an example, if you're only interested in the 10 most recent results you can use:



find ~/ -type f -iname '*.txt' | xargs ls -td1 | head -n10


One thing to note about find is that by default it does not follow symbolic links, if like me you have a few symbolic links in your home directory and want to check those too you need to use the -follow option to find.



find ~/ -type f -iname '*.txt' -follow | xargs ls -td1 | head -n10

[#30198] Sunday, August 7, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ightrushi

Total Points: 129
Total Questions: 125
Total Answers: 127

Location: French Southern and Antarctic Lands
Member since Fri, Jan 6, 2023
1 Year ago
;