How can I get 1 by 1 the results of a command like
# locate file.txt
/home/alex/file.txt
/backup/file.txt
What I want to do is to make an interactive script where to ask: Which of the following files would you like to copy/recover? [1],[2]:
Example:
filetorecover.txt
_________________
file.txt
file1.txt
...
./recover filestorecover.txt /home/alex/data/
file.txt could not be located at /home/alex/data, but it was locate here:
[1] /home/alex/files/
[2] /backup/file.txt
- filestorecover => is the file that contains file to look for
- /home/alex/files/ => is the main folder where to look for and if the file is not located there, then do a
locate file.txt
So, mainly I am looking for a way of grabbing those X results from find or locate one by one for the late use as explained above.
UPDATE
Is it possible to see the most common path for find/locate’s result? I mean if I have 6 files located at /backup/ and 2 at /home/alex/files/ I would like to set, or ask if they what to get all the files from the most common folder, /backup/!
This is meant when I have more than X files (ex: 10), because sometimes I can get up to hundreds of results and I can’t go 1 by 1!
I’d use awk and read.