Link to home
Start Free TrialLog in
Avatar of jasonslogan
jasonslogan

asked on

Shell command to list file path, file names, and file size.

I would like a single line command in shell that will produce the following output:

/path/to/file/|3333.txt|374

/path/to/file is the root path to all the text files in sub directories built from this path
3333.txt is the file name of the text file found in the path
374 is the file size in bytes of the file

I want this output so I can dump this into an array and separate it by |
I only need text (txt) files and don't want . or .. or anything else. Just the text files recursively from the /path/to/file/ directory.
Avatar of farzanj
farzanj
Flag of Canada image

What would be the input?  Which directory would you be in ?

If you are in the same directory as the files are, something like this would work

 ls -l  | grep "^-" |awk -v path=$(pwd) -F" " '{print path"|"$NF"|"$4}'

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of simon3270
simon3270
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of jasonslogan
jasonslogan

ASKER

It worked great, thank you!