0

I have got a Ubuntu 14.04.5 LTS with a lot of folders and files. My goal is to find some old files which I think I know a naming format for them say "%A%.csv" or ".csv" or ".xls".

Anyway I want somehow to "unfolder" everything and display chronologically file name + date + details (size etc).

In other words without physically unfolder all the directory, but logically what command should I use to write to txt file all file names with their parameters in chronological order? Please advise.

Some examples for what I need:

  1. A folder which have 140 subfolders and each has 3 20 subfolders with files. Finally you get the all leaves (files) and what I want is to "unfolder them - extract all the files outside all folders and sort them chronologically and write their names + size + data created + date modified to a txt file. Everything without physical unfoldering.

  2. The C drive contains some folders, these folders contain files and subfolders etc. I want to extract all your files get their meta data and write it to a txt file. How can I do this without physically unfoldering?

3
  • A different way to do this is, instead of putting the files names in a file, to create soft links to them in a directory (assuming no name clashes or adding some disambiguation in the soft links). Then you have all the info in one file explorer window, you can sort by name/size/date, and you can click the files to see their contents.
    – xenoid
    Commented Oct 25, 2017 at 10:05
  • @xenoid how can I do this? Commented Oct 25, 2017 at 12:21
  • If no name clashes expected: find . -name "*.csv" -type f -exec ln -s {} target_directory \; or find . -name "*.csv" -type f -exec ln -s -t target_directory {} +. If there are possible name clashes then it's a bit more complicated to add disambiguation, but nothing scary.
    – xenoid
    Commented Oct 25, 2017 at 12:33

1 Answer 1

0

Use the find command. Example of recursivly finding all files ending in .csv from the current directory:

find . -name "*.csv" -type f -exec ls -lh {} \; > result.txt

Breakdown of the command:

  • .: means the top directory, a dot means the current directory where the command is used.
  • -name "*.csv": finds all files (and directories) ending in .csv.
  • type f: Only consider files. For only directories use d, for both remove this part.
  • -exec ls -lh {} \;: exectutes the command ls -lh on all the files found. This will list information about them. Another command could be used here.
  • > results.txt: Writes the result to a file results.txt instead of printing it to the screen.

The ls -lh command gives a result similar to this, and that is what is written to the file as well:

enter image description here

0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .