Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
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.
hey, i am new in the world of linux and i search for some one who can help me to do this :
In the linux file system, there are established directories (folders) such as / etc, / home, ... Create a script that summarizes the contents of a folder, which passed as a parameter to the script: specify how many subdirectories are present, and how many files. Moreover, you also how much space the map packs in total. The script may work for one specified folder, but also for several specified folders. Both absolute and relative pads names can be entered. Make sure the specified folder exists.
Do not post homework assignments verbatim. We're happy to assist if you have specific questions or have hit a stumbling point, however. Let us know what you've already tried and what references you have used (including class notes, books, and searches) and we'll do our best to help. Keep in mind that your instructor might also be an LQ member.
i would like to know if i have to work with ls to get info about the directory or use a more efficient command
Check variations on the ls command. Also see df and du commands for some of the stuff you're asking.
Write a script, I always say, "Whatever you can write in a command line, you can script." So do that, or do some command line attempts, research some of the recommended commands and ask more detailed questions. All that you've brought up thus far can be dealt with using the commands I've mentioned. Or at least I feel so.
Here's a suggestion; since you are new to scripting, why don't you break that excercise down into smaller parts.
For example start out with this:
Write a script that takes the name (and path) of a directory as argument.
If the directory exists, exit with 0 (success), otherwise exit with a value > 0.
I would also suggest you to find a way to implement it, post it and we can discuss it. Probably you won't find the most efficient way at first but we are here to help you to improve your solution.
i have find the way to have a total of every subdirectory in the diretory with:
du -ch --max-depth=1 | wc -l
but now i want to have the total of the files in the directory only. how can i do
thanks hmw.
i will put that in a function.
but now i want to use a case.
when i use my script with one parameter it will give us only the directories in the directory.
but when i add the "-f" it will also give us the files of the directory. i am thinking about the use of BOOLEAN but i am not sure.
hello habitual
your script is to dificult i need something easy as du and find commande to have the number of files and the number of directories in the directory.
for the total number of dir i have that : find -/$1/* -maxdepth 0 -type d | wc -l
for the total number of file i have that : find -/$1/* -maxdepth 1 -type d -exec du -ch {} + | tail -l | wc -l
but for the file it give me more file that i have when i use the commande ls, so i dont understand from where the files come????
i ask me also if i can have a general code with the dir the file and size of the directory and substract from this code each part separately?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.