Getting total bytes of all files in a directory (NOT ANYTHING IN SUB DIRECTORIES)
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
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.
Getting total bytes of all files in a directory (NOT ANYTHING IN SUB DIRECTORIES)
I wrote a program in C# for winndows that is backing up my windows server to a remote linux box over the internet. So I am trying to find the most efficient way to get the total bytes of all files in a directory (NOT INCLUDING ANYTHING IN SUB DIRECTORIES). There are lots of options using the "du" command but I cannot find any option that does not interrogate sub directories, reason is my main folder that I am wanting to get just the files has over 80,000 sub directories and 2.8 million files inside of the those sub directories. So all du commands even using the --max-depth end up taking hours to return an answer. I am currently using du and adding all the files from each folder to the command, which creates a lot of traffic in and out (the linux box is at a remote location). So hopefully someone has a good solution using du or maybe even ls. Just remember I am trying to keep network traffic small and tight for speed.
Distribution: Debian testing/sid; OpenSuSE; Fedora; Mint
Posts: 5,524
Rep:
Hi ktoonsez,
Welcome!
You can try rsync --dry-run, which will output the total size of everything it would have transferred. To save bandwidth you can use rsync -c, to compress everything before transferring it. There's many tricks using rsync. Debian has the ftpsync scripts that are used to mirror the debian archive. I mirror the i386 and amd64 architectures, which together are about 500,000 objects, and the machine doesn't even break a sweat.
You can just take the ftpsync package and customize it to your needs.
You can try rsync --dry-run, which will output the total size of everything it would have transferred. To save bandwidth you can use rsync -c, to compress everything before transferring it. There's many tricks using rsync. Debian has the ftpsync scripts that are used to mirror the debian archive. I mirror the i386 and amd64 architectures, which together are about 500,000 objects, and the machine doesn't even break a sweat.
You can just take the ftpsync package and customize it to your needs.
Shoot, I should have mentioned that the data I am backing up is from a windows machine with a .NET program I wrote that is is executing SSH command from a dll so rsync isn't going to work. Thanks
You could use "find" with maxdepth and print the size and simply sum it yourself, but simpler to just use "ls -l" and then sum it ignoring the dir entries. Trivial awk one-liner will do it.
You could use "find" with maxdepth and print the size and simply sum it yourself, but simpler to just use "ls -l" and then sum it ignoring the dir entries. Trivial awk one-liner will do it.
Actually this might work pretty good. Using the command below that will give me only the sizes which I think will work great and keep the data down to a minimum:
i am runing ubuntu for the first time. its my first time installing lenux ever. how do i install sound drivers for gigabyte ax370 gaming 5. this is all new to me so i dont know any code. can anybody help a beginer-
i am runing ubuntu for the first time. its my first time installing lenux ever. how do i install sound drivers for gigabyte ax370 gaming 5. this is all new to me so i dont know any code. can anybody help a beginer-
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.