Solved

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

Posted on 2012-03-28
3
405 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
3 Comments
 
LVL 31

Expert Comment

by:farzanj
Comment Utility
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 500 total points
Comment Utility
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
Comment Utility
It worked great, thank you!
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.

743 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now