[SOLVED] Standard Scripts for Linux: Bash Script to List all Files Inside a Directory, Line by Line to Standard Output
ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Standard Scripts for Linux: Bash Script to List all Files Inside a Directory, Line by Line to Standard Output
I'm now in the process of updating and creating a working set of standard scripts for linux. This is the base, I will build everything else off of. Everything above it, will assume that the standard scripts are installed. They will eventually, want to be cross platform, at least on Windows and Linux. Since I'm focusing now on Linux, as it works better, this will be the first to be finished again. I'm writing here because I'm having some trouble. This is a network specific thing, for my home network. I may use them on other networks as time goes on, but let's start with my network. And then, soon after, I can work on my github page for my network, I hope, so that others can benefit possibly and stuff later, though I may start with making them private on there. We'll see. If I have to make them private, it's just because they contain some specific code identifying my network, which I may or may not want to share.
OK. Let's start with specifics, where I'm having trouble.
The first thing I'm going to want to do, is modify my install script, so that upon installing, as it's last task, it will output a log to its directory it's ran from, which will list in this format:
Code:
filename
filename
filename
...
..the files it installed, which can be gotten from listing in that format, the files in it's below directory of ./scripts/ all the files in there. Then, in my install file, I'll use that script in that folder, to output the files, line by line, and then I'll redirect it to a text (log) file. I want to include itself in this listing.
This, will then be able to be printed, by sending the text file to a printer, probably for now, at the library, and I will be able to have a checklist once it's on paper, of what's debugged, and what still needs to be debugged, very easily. Then I can come back to you guys and have some help debugging these files. Otherwise, I need a checklist by hand, which is trickier. I am losing time trying to create it by hand.
I know how to list, with the ls command, in general in bash. But this is a trickier problem, because I want it in a certain format. I assume it will just be a list command of some sort.
I just mean I don't want it to list side by side, but as straight up and down. Let me try the command given, and see if it does what I want. Just a second...
Almost! Just get rid of the directory name in the front of each thing, because I know that! I don't need the path in my output. Other than that, that commmand works just fine. As long as it really listed everything in the dir. I can't tell for sure, but that's because it's too hard to check, hence my reason for wanting the command in the first place.
Will list files in the current directory one file per line but the find command above will recurse down the directory tree.
Review man find about controlling the print output.
command, was just what I needed. Now I can find out, what I really need to debug! The tough work is ahead for these scripts! But at least it's going to be simpler with this list!
Not sure if it helps but I know "ls -a" lists even hidden stuff. Maybe if you make it an array and pipe it through a function that does line by line. grep may be useful. X E.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.