?
Solved

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

Posted on 2012-03-28
3
Medium Priority
?
428 Views
Last Modified: 2012-03-30
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.
0
Comment
Question by:jasonslogan
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 31

Expert Comment

by:farzanj
ID: 37777794
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

0
 
LVL 19

Accepted Solution

by:
simon3270 earned 2000 total points
ID: 37780256
If you need a recursive version, only reporting *.txt files and allowing for spaces in file names:
find /path/to/file -type f -name "*.txt" | while read f
do
echo ${dirname "$f")'|'$(basename "$f")'|'$(stat -c "%s" "$f")
done > result.dat

Open in new window

It will be a lot slower that farzanj's awk version.
0
 
LVL 1

Author Closing Comment

by:jasonslogan
ID: 37789339
It worked great, thank you!
0

Featured Post

PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
It’s 2016. Password authentication should be dead — or at least close to dying. But, unfortunately, it has not traversed Quagga stage yet. Using password authentication is like laundering hotel guest linens with a washboard — it’s Passé.
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
Suggested Courses
Course of the Month9 days, 1 hour left to enroll

765 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question