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.
I need to write a script to report useful information on disk utilization for each user's home directory.
For each directory I need to show:
1. the long listing of that directory entry (but not the files in the directory), so that I can see the rights and owners of the directory.
2. The amount of disk used by that directory, in human-readable format, including subdirectories.
I need to have two lines for each user one after the other. For example:
/home/user1 directory info
/home/user1 disk usage
/home/user2 directory info
/home/user2 disk usage
and so on.
The script will assume that all users, except user root, have their home directories in the /home directory (no need to do anything with the /etc/passwd file). And if the administrator adds or removes users, the script should still work correctly (so the script shows the information for all current users).
Here's what I do know. The command "ls -ld /home/user's_name" will give me the info I need for #1. And the command "du -hs" will give me the info I need for #2. What I don't know is how to grab each individual directory in order to apply the above commands to each of them in order. ???
Any insight on this problem would be greatly appreaciated. Thanks!
Actually, it's a peer challenge (and it's driving me nuts!). I can't figure out code to get my current users, and put them into a set of variables that I can work with. At least I'm assuming this is what I need to do.
Well--whatever it is--you still need to show us what you have tried. (did you try what leopard suggested? Was it useful? If not, what else was needed?)
By "current users", do you mean the ones logged in? Did you try the "users' command?
Thanks for the replies thus far. I've been trying various attempts with for loop logic, but have been coming up empty, until now I think. Here is what I currently have:
Code:
for i in /home/*
do
ls -ld $i
du -hs $i
done
Finally! But I still need to get the home directory for user root in here as well. Now I'm lost again. LOL, I'm guessing that for loop logic doesn't allow for multiple specified sets. Hmmm... Since we know the root user will always be there, maybe I can just tack on a simple statement above the for loop to operate on the root user folder. ???
I'm guessing that for loop logic doesn't allow for multiple specified sets.
Actually... yes. Every item separated by space or tab is part of the list to loop over. Since the "globbed" list is expanded before the loop is actually executed, you can add other items as well
Code:
for i in /home/* ~ /path/to/some/dir /root etc etc
Actually... yes. Every item separated by space or tab is part of the list to loop over. Since the "globbed" list is expanded before the loop is actually executed, you can add other items as well
Code:
for i in /home/* ~ /path/to/some/dir /root etc etc
Cool. I didn't realize that would work. LOL, now I can look smarter than I actually am. My original code was going to be:
Code:
ls -ld /root
du -hs /root
for i /home/*
do
ls -ld $i
du -hs $i
done
Yup!!
Remember:
First there was Unix
Then there were various unsuccessful experiments--VMS, DOS, AppleDOS, MacOS, Windows, etc.
Linux is really just a homecoming....
I take exception to the VMS being unsuccessful. It was amazingly robust, and the VAX's were way ahead of their time. I remember back in 1989, having Ethernet interfaces that did channel bonding, full failover on hardware, clustering, etc., on boxes that were less than $50k...which in 1989 was pretty damned cheap. DEC didn't market things well. VMS still lives, too:
I take exception to the VMS being unsuccessful. It was amazingly robust, and the VAX's were way ahead of their time. I remember back in 1989, having Ethernet interfaces that did channel bonding, full failover on hardware, clustering, etc., on boxes that were less than $50k...which in 1989 was pretty damned cheap. DEC didn't market things well. VMS still lives, too:
I must agree whole heartily that VMS is a robust system. And that DEC didn't market well. Ah that sweet 11, I still have some memories that I've been trying to forget for years. I've got some old planes in the LAB just to remember those years. I'm sure if I still had a system and slapped them back in, the memory would be valid still.
Long wire differential channels with multiplex were the norm in the late 70s' & 80s' for most installations. Heck, shared memory was at the forefront with DEC. Then add the SMD (disk) systems and you had a system that could walk the talk.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.