LinuxQuestions.org
Visit Jeremy's Blog.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 08-19-2015, 11:48 AM   #1
redone-22
LQ Newbie
 
Registered: Aug 2015
Posts: 11

Rep: Reputation: Disabled
Smile Linux scripting


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.

thanks
 
Old 08-19-2015, 12:03 PM   #2
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Hi and welcome!

Please read the LQ rules:
http://www.linuxquestions.org/linux/rules.html

Quote:
Originally Posted by LinuxQuestions
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.
Best regards,
HMW
 
Old 08-19-2015, 12:06 PM   #3
redone-22
LQ Newbie
 
Registered: Aug 2015
Posts: 11

Original Poster
Rep: Reputation: Disabled
it's not a homework. that is just an exercise.
 
Old 08-19-2015, 12:10 PM   #4
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
Originally Posted by redone-22 View Post
it's not a homework. that is just an exercise.
Ok. Then what have you done this far?

Also, check out: http://tldp.org/LDP/abs/html/

And there are tons of information about scripting online.

Nobody is going to write that script for you, but some (like me) would be glad to help with a specific question.

Best regards,
HMW
 
Old 08-19-2015, 12:11 PM   #5
redone-22
LQ Newbie
 
Registered: Aug 2015
Posts: 11

Original Poster
Rep: Reputation: Disabled
i would like to know if i have to work with ls to get info about the directory or use a more efficient command

Last edited by redone-22; 08-19-2015 at 12:19 PM.
 
Old 08-19-2015, 01:35 PM   #6
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,842
Blog Entries: 13

Rep: Reputation: 4894Reputation: 4894Reputation: 4894Reputation: 4894Reputation: 4894Reputation: 4894Reputation: 4894Reputation: 4894Reputation: 4894Reputation: 4894Reputation: 4894
Quote:
Originally Posted by redone-22 View Post
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.
 
Old 08-19-2015, 01:57 PM   #7
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
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.
 
Old 08-19-2015, 02:25 PM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,108

Rep: Reputation: 7138Reputation: 7138Reputation: 7138Reputation: 7138Reputation: 7138Reputation: 7138Reputation: 7138Reputation: 7138Reputation: 7138Reputation: 7138Reputation: 7138
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.
 
Old 08-19-2015, 04:37 PM   #9
redone-22
LQ Newbie
 
Registered: Aug 2015
Posts: 11

Original Poster
Rep: Reputation: Disabled
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

Last edited by redone-22; 08-19-2015 at 04:53 PM.
 
Old 08-20-2015, 03:20 AM   #10
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
Originally Posted by redone-22 View Post
but now i want to have the total of the files in the directory only. how can i do
Try this:
Code:
find . -maxdepth 1 -type f -exec du -ch {} + | tail  -1
Best regards,
HMW
 
Old 08-20-2015, 05:51 AM   #11
redone-22
LQ Newbie
 
Registered: Aug 2015
Posts: 11

Original Poster
Rep: Reputation: Disabled
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.

Last edited by redone-22; 08-20-2015 at 06:15 AM.
 
Old 08-20-2015, 07:52 AM   #12
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
How about something like this output?
Code:
4K	./Desktop
300K	./Pycode
14.4M	./svn
29.2M	./work
51M	./Bin
163.2M	./Pictures
9.4G	./Documents
10.1G	./VboxVMs
25.4G	./Downloads
Total: 43.3G
jj@my-kungfu ~ $ cd Pictures/
jj@my-kungfu ~/Pictures $ /home/jj/Bin/bdu.sh
4K	./arch.gif
4K	./bash.jpg
4K	./bash.png
4K	./dork_32x32.jpg
4K	./dork_32x32.png
4K	./dork_64x64.jpg
4K	./dork.jpg
4K	./Geeko_head_simple.png
4K	./iCloud_thumbnail.jpg
4K	./lizard2.png
4K	./me.png
4K	./slackware.jpg
4K	./terminal.jpg
4K	./yad.png
8K	./Bsd_daemon.jpg
8K	./favicon.ico
8K	./LittleJohn2.jpg
8K	./PythonIcon80x80.png
8K	./todofavicon.ico
16K	./dork.png
20K	./supergh0d.jpg
24K	./shonuff.jpg
24K	./That
28K	./Mozilla_Thunderbird_logo.png
36K	./00_hoXU4st_QRq6.jpg
36K	./space.gif
44K	./geeko-button-bling.svg
48K	./crypto.jpg
52K	./dork_256x256.png
60K	./Untitled.jpg
64K	./blackcat.jpg
84K	./unix-linux-1280x1024.jpg
92K	./todotxt_logo_2011.png
104K	./cityoflights.jpg
104K	./fantasia-original.jpg
124K	./Thunder
156K	./space.jpg
184K	./lavoult.png
184K	./vim_background.png
200K	./make_it_stop.png
204K	./Cool-Minions-HD-Wallpaper-8-For-Desktop-Background.jpg
208K	./Debian
208K	./zakim_bridge2.JPG
220K	./Cool-Minions-HD-Wallpaper-20-For-Desktop-Background.jpg
244K	./opensuse1600_1200.jpg
316K	./infinity_world-HD.jpg
352K	./IMG_0701.jpg
364K	./Katy-Perry-Dark_Horse-WideWallpapersHD.jpg
388K	./FireDragon.jpg
396K	./IMG_7030.jpg
492K	./dr_evil.jpg
552K	./BS_Awesomeness.jpg
568K	./screenshots
652K	./Workspace
656K	./Workspace
660K	./1.jpg
768K	./gcar.jpg
828K	./FluxCapacitor.jpg
2.1M	./2.slackware.jpg
2.4M	./The_Tidal_Influences.jpg
2.4M	./slack
2.5M	./June
2.9M	./059.JPG
3.2M	./b-ball.bmp
3.8M	./Wallbase
6.4M	./wallpaper_ratchet_deadlocked_01_1600.bmp
46.3M	./wallpapers
90M	./Recovered
Total: 163.2M
The script must be run in the directory you want the listing for.
 
Old 08-20-2015, 08:31 AM   #13
redone-22
LQ Newbie
 
Registered: Aug 2015
Posts: 11

Original Poster
Rep: Reputation: Disabled
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?

Last edited by redone-22; 08-20-2015 at 08:41 AM.
 
Old 08-20-2015, 08:47 AM   #14
HMW
Member
 
Registered: Aug 2013
Location: Sweden
Distribution: Debian, Arch, Red Hat, CentOS
Posts: 773
Blog Entries: 3

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Quote:
Originally Posted by redone-22 View Post
for the total number of file i have that : find -/$1/* -maxdepth 1 -type d -exec du -ch {} + | tail -l | wc -l
Wait, just wait a minute... have you tried this command:
Code:
find -/$1/* -maxdepth 1 -type d -exec du -ch {} + | tail -l | wc -l
If so, what happened, exactly, when you did?

Best regards,
HMW
 
Old 08-20-2015, 09:37 AM   #15
redone-22
LQ Newbie
 
Registered: Aug 2015
Posts: 11

Original Poster
Rep: Reputation: Disabled
it gives me 4
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Shell Scripting Part I: Getting started with bash scripting LXer Syndicated Linux News 0 04-29-2015 09:03 AM
LXer: Scripting the Linux desktop, Part 2: Scripting Nautilus LXer Syndicated Linux News 0 02-17-2011 05:02 AM
teaching shell scripting: cool scripting examples? fax8 Linux - General 1 04-20-2006 05:29 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 03:43 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration