Bash script to browse directory with a custom 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.
Bash script to browse directory with a custom output ?
Hello,
I need to browse a storage disk with almost 700GB of datas. There is a lot of directories.
I would like to make a script that browse all the structure and store it in a text file each night. Then I could make a little search program and it'll be much more faster than searching with the FIND command. Even store it in a mysql database.
I looked the docs about LS and TREE, but I can't get exactly what I want .
With this format it's easy to sort by last modification.
- TREE is great, but sometimes dates aren't well displayed.
- LS is nice too, but I can't find a parameter to display the fullpath for each files on one line like TREE with the recursive option.
Your code is working, but refuse to run with long filnames, directores with spaces and stuff like that.
Code:
[root@fileserver _array]# find . | xargs stat -c '[%y][%s][%n]'
xargs: unmatched single quote; by default quotes are special to xargs unless you use the -0 option
[root@fileserver _array]#
I tried to play with the xags -0 but I can't run it. May be do you know a tip or something for this problem ?
Your code is working, but refuse to run with long filnames, directores with spaces and stuff like that
[..snip..]
I tried to play with the xags -0 but I can't run it. May be do you know a tip or something for this problem ?
You're right. The command line I posted doesn't handle correctly file/dirs with spaces, newlines, or other "strange" characters in the name.
"xargs -o stat ..." should solve the problem though, but be sure to use the "-print0" option with "find" in that case:
Code:
find /your/path -print0 | xargs -0 stat -c '[%y][%s][%n]'
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.