0

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.

  • I don't have the time to write a full answer (should go to work ^^) but have a look at the find and sort commands. – soulsource Jul 26 '13 at 6:23
1

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
| improve this answer | |
1

The find command can filter by mtime, e.g.

find path/to/some/directory -type f -name *.txt -mtime 5

That will display any files in path/to/some/directory that were modified in the last 5*24 hours. They will not be sorted by creation date, however -- assuming you haven't modified too many text files recently -- with a tight enough mtime filter, the list of files returned should be pretty small. Rather than sorting by date, this command will only show files that have been recently modified...

You could probably combine that with a pipe into xargs ls as AJefferiss describes to add the sort, if necessary.

| improve this answer | |
1

You can find *.txt files and sort them by modified date using the following command in terminal in terminal:

find /path/to/search -type f -iname '*.txt' -printf "%-.22T+ %Tx %.8TX %p\n" | sort | awk '{print $2 "\t" $3 "\t" $4}'

or:

cd /path/to/search
find . -type f -iname '*.txt' -printf "%-.22T+ %Tx %.8TX %p\n" | sort | awk '{print $2 "\t" $3 "\t" $4}'

For last 10 modified *.txt files use:

find . -type f -iname '*.txt' -printf "%-.22T+ %Tx %.8TX %p\n" | sort | awk '{print $2 "\t" $3 "\t" $4}' | tail
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.