Welcome to Linux Knowledge Base and Tutorial
"The place where you learn linux"
The ONE Campaign to make poverty history

 Create an AccountHome | Submit News | Your Account  

Tutorial Menu
Linux Tutorial Home
Table of Contents

· Introduction to Operating Systems
· Linux Basics
· Working with the System
· Shells and Utilities
· Editing Files
· Basic Administration
· The Operating System
· The X Windowing System
· The Computer Itself
· Networking
· System Monitoring
· Solving Problems
· Security
· Installing and Upgrading
· Linux and Windows

Glossary
MoreInfo
Man Pages
Linux Topics
Test Your Knowledge

Site Menu
Site Map
FAQ
Copyright Info
Terms of Use
Privacy Info
Disclaimer
WorkBoard
Thanks
Donations
Advertising
Masthead / Impressum
Your Account

Communication
Feedback
Forums
Private Messages
Recommend Us
Surveys

Features
HOWTOs
News
News Archive
NukeSentinel
Reviews
Submit News
Topics
User Articles
Web Links

Google
Google


The Web
linux-tutorial.info

Who's Online
There are currently, 241 guest(s) and 1 member(s) that are online.

You are an Anonymous user. You can register for free by clicking here

  
Linux Knowledge Base and Tutorial: Forums



Linux Tutorial :: View topic - Shell script
 Forum FAQForum FAQ   SearchSearch   UsergroupsUsergroups   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Shell script

 
Post new topic   Reply to topic    Linux Tutorial Forum Index -> How To
View previous topic :: View next topic  
Author Message
shanie
Newbie


Joined: Jan 02, 2010
Posts: 5

PostPosted: Wed Jan 27, 2010 12:17 am    Post subject: Shell script Reply with quote

I am working on my first shell script and i need som help please
I have a folder that i am sharing between my linux server and my windows computer at home with samba.

I want that folder not to take up more than 120 gb of my disk space.

Can anyone help me on the way how do i accomplish this by a shell script.

This is my script so far

#!/bin/bash

echo "The disk space of the directory blabla"
du -h /home/shane/blabla*

What i realise when i excecutes the script is, that it shows me the file size name of every files in that directory.
Can someone tell me how do i just get the total disk space that is used, i don't want to see whats in the directory only
the disc space that is used so far..?

Thanks Very Happy
Back to top
View user's profile Send private message
ffreeloader
Master


Joined: Aug 10, 2005
Posts: 561

PostPosted: Wed Jan 27, 2010 11:54 am    Post subject: Re: Shell script Reply with quote

shanie wrote:
I am working on my first shell script and i need som help please
I have a folder that i am sharing between my linux server and my windows computer at home with samba.

I want that folder not to take up more than 120 gb of my disk space.

Can anyone help me on the way how do i accomplish this by a shell script.

This is my script so far

#!/bin/bash

echo "The disk space of the directory blabla"
du -h /home/shane/blabla*

What i realise when i excecutes the script is, that it shows me the file size name of every files in that directory.
Can someone tell me how do i just get the total disk space that is used, i don't want to see whats in the directory only
the disc space that is used so far..?

Thanks Very Happy


The easiest way to do that is to pipe the output of du into tail. Like this: du -h /home/shane/blabla | tail -1

If you don't know what/where the pipe symbol is on the keyboard it's Shift \. To find out more about how to use tail read the man page for it. Learning to pipe output from one command into another is very useful.
Back to top
View user's profile Send private message
shanie
Newbie


Joined: Jan 02, 2010
Posts: 5

PostPosted: Wed Jan 27, 2010 7:19 pm    Post subject: Reply with quote

Thanks alot Smile
Back to top
View user's profile Send private message
shanie
Newbie


Joined: Jan 02, 2010
Posts: 5

PostPosted: Wed Jan 27, 2010 11:14 pm    Post subject: Reply with quote

I have a folder that i am sharing between my linux server and my windows computer at home with samba.

I want that folder not to take up more than 120 gb of my disk space.

How do i accomplish this, i have read a little about disk quotas, is there another way?
Back to top
View user's profile Send private message
jimmo
Administrator


Joined: Jul 27, 2002
Posts: 264
Location: Untersiemau, Germany

PostPosted: Thu Jan 28, 2010 11:35 am    Post subject: Reply with quote

If you wanted the system to manage the 120 GB limit you might want to look quotas. Simply type "man quota" and that should get you started.
Back to top
View user's profile Send private message
jimmo
Administrator


Joined: Jul 27, 2002
Posts: 264
Location: Untersiemau, Germany

PostPosted: Thu Jan 28, 2010 11:39 am    Post subject: Re: Shell script Reply with quote

shanie wrote:

echo "The disk space of the directory blabla"
du -h /home/shane/blabla*

What i realise when i excecutes the script is, that it shows me the file size name of every files in that directory.


Try:
du -sh _directory_name_

-s = sum

(ffreeloader's suggestion is still a great trick to know when you just need the last line of output.)
Back to top
View user's profile Send private message
ffreeloader
Master


Joined: Aug 10, 2005
Posts: 561

PostPosted: Tue Feb 02, 2010 10:43 pm    Post subject: Re: Shell script Reply with quote

jimmo wrote:
shanie wrote:

echo "The disk space of the directory blabla"
du -h /home/shane/blabla*

What i realise when i excecutes the script is, that it shows me the file size name of every files in that directory.


Try:
du -sh _directory_name_

-s = sum

(ffreeloader's suggestion is still a great trick to know when you just need the last line of output.)


The last line of the output of du is the sum of all files in the specified directory.
Back to top
View user's profile Send private message
jimmo
Administrator


Joined: Jul 27, 2002
Posts: 264
Location: Untersiemau, Germany

PostPosted: Wed Feb 03, 2010 8:19 am    Post subject: Reply with quote

That's one of the things that has enthralled me with UNIX and then later Linux. There are so many different ways to achieve the same goal.
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Linux Tutorial Forum Index -> How To All times are GMT
Page 1 of 1

 

Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

Powered by phpBB © 2001-2007 phpBB Group
  
How often do you use the WebLinks?

More than once a day
Once a day
A few times a week
Once a week
Once a month
Rarely
Never



Results
Polls

Votes: 447
Comments: 0

Login
Nickname

Password

Security Code
Security Code
Type Security Code


Don't have an account yet? You can create one. As a registered user you have some advantages like theme manager, comments configuration and post comments with your name.

Help if you can!


Amazon Wish List
My Amazon.com Wish List

Did You Know?
You can get all the latest Site and Linux news by checking out our news page.


Friends



Help us cut cost by not downloading the whole site!
Use of automated download sofware ("harvesters") such as wget, httrack, etc. causes the site to quickly exceed its bandwidth limitation and therefore is expressedly prohibited. For more details on this, take a look here

Tell a Friend About Us

Bookmark and Share



Web site powered by PHP-Nuke

Is this information useful? At the very least you can help by spreading the word to your favorite newsgroups, mailing lists and forums.
All logos and trademarks in this site are property of their respective owner. The comments are property of their posters. Articles are the property of their respective owners. Unless otherwise stated in the body of the article, article content © 1994-2010 by James Mohr. All rights reserved. The stylized page/paper, as well as the terms "The Linux Tutorial", "The Linux Server Tutorial", "The Linux Knowledge Base and Tutorial" and "The place where you learn Linux" are service marks of James Mohr. All rights reserved.
The Linux Knowledge Base and Tutorial may contain links to sites on the Internet, which are owned and operated by third parties. The Linux Tutorial is not responsible for the content of any such third-party site. By viewing/utilizing this web site, you have agreed to our disclaimer, terms of use and privacy policy. Use of automated download sofware ("harvesters") such as wget, httrack, etc. causes the site to quickly exceed its bandwidth limitation and are therefore expressedly prohibited. For more details on this, take a look here

PHP-Nuke Copyright © 2004 by Francisco Burzi. This is free software, and you may redistribute it under the GPL. PHP-Nuke comes with absolutely no warranty, for details, see the license.
Page Generation: 0.12 Seconds