A program to solve a problem: filter Linux/Unix 'ls' output - Printable Version +- QB64 Phoenix Edition (https://staging.qb64phoenix.com) +-- Forum: QB64 Rising (https://staging.qb64phoenix.com/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://staging.qb64phoenix.com/forumdisplay.php?fid=3) +---- Forum: Programs (https://staging.qb64phoenix.com/forumdisplay.php?fid=7) +---- Thread: A program to solve a problem: filter Linux/Unix 'ls' output (/showthread.php?tid=1673) |
A program to solve a problem: filter Linux/Unix 'ls' output - TDarcos - 05-10-2023 This is my first program contribution, it worked so well I thought I'd pass it on. Here is the backstory about why I wrote this program. I had a problem. My Windows computer started BSODing during initial boot/startup. Since it was an actual BSOD with frowny face, this means it's a Windows problem, not a hardware one. After several attempts to use any of the recovery methods which would leave my files intact, I came to the conclusion that I am in a pickle. Then, I find the recovery partition no longer works. Now, I came to the condclusion that I was, quite frankly, screwed. So, I used the time-tested method of attacking a problem: I threw money at it. I went on Amazon and purchased a refurbished machine. The new (to me) machine is actually better than the one I had. A "Dell OptiPlex 7020 Desktop Computer,Intel Quad Core i7 4790 3.6Ghz, 32GB Ram New 2TB SSD." After I received it, I discovered that while it has 4 cores (as I had expected) it has 8 threads (which i did not.) So the computer is actually better than what I thought I was buying. With that I purchased something I really needed: a 4 TB ruggedized external hard drive, so I can back up my computers without worrying about someone dropping it. I already have a 6 TB external, but I don't feel good about it being moved around. The price was terrific: with Windows 10 Professional, it was $265.00. Add the external drive and sales tax, $401. So I set up the new computer, and have it build a Windows recovery SSD on an SD card. Plug the reader into the old computer, reset the BIOS to allow boot from an external drive, and I try again. Nothing works. So, from my new computer, I download a Linux distribution,Xubuntu. Repeat the process and it boots fine, file manager can see the internal drive, and it can even see the 6TB external, but not the 4TB ruggedized (even though the new machine does). So I copied my most recent files from my working directory to the 6 TB. The Problem I do have a backup of my huge collection of downloaded open-source software on the 6TB but it's old., from last year. It does not have local changes I made from writing programs. On Windows, I just have Free File Sync scan the work directory and mirror to backup. So that is out. I had, however, downloaded the Linux version of QB64PE, but attempt to install it fails because the Wifi adapter apparently is not recognized; it can't download required packages. Well, I could just copy the new archive to replace the backup. About 1.3 million files, 100,000+ directories, 411 GB, and will take about 500 hours, So, that's not an answer. So how can I solve this problem? So, it hits me: run an 'ls' directory scan with recursive subdirectory search, piped to a file, then take that file over to my new computer and write a filtering program to run there. I had ls exclude owner and group, and list one file per line. Output from ls looks like this: Output: Code: (Select All) Paul (From LENOVO)/: What can be determined from this is:
I have one additional problem. Just the listing of files itself is an 88 megabyte text file! The solution: Code: (Select All) ' Process ls program output to exclude files before this year Result? Of more than 900,000 files scanned, I need to copy 53. That's all. The program took 5 minutes, processing an average of about 2500 items per second. A really satisfying conclusion, and should put paid to those who claim Basic, and specifically QuickBasic, is not relevant for solving real-world problems. Paul RE: A program to solve a problem: filter Linux/Unix 'ls' output - grymmjack - 07-15-2023 Hi @TDarcos Clever program. Did you know you can actually use find command in linux and either pass the results to xargs or use the -exec method to do something ? Find all files modified since the the last year (run from root directory of where you are scanning): Code: (Select All) find . -mtime +365 -print Code: (Select All) find . -mtime +365 -exec cp {} destination/dir/{} \; Code: (Select All) cp (foundfile) destination/dir/(foundfile) Your program is cool too, not saying to not use it. Also it's lots of fun to solve our own problems! I just wanted to share this 1 liner since i've used it so much in my life. The linux find command is a life saver. Check out the docs: Code: (Select All) man find |