LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 03-28-2009, 06:35 PM   #1
Michael235
LQ Newbie
 
Registered: Mar 2009
Posts: 2

Rep: Reputation: 0
Question subtract total numbers of files from 2 directories


Hello, I am storing the number in a file but the problem is that I don't know how to do the calculation from those two directories.

here is my program:

echo "enter first directory name"
read dir1

echo "enter second directory name"
read dir2

ls $dir1 | wc -l > r
ls $dir2 | wc -l > t

cat r
cat t

#let y=r+t I had error in this part I'm stuck here
#echo y

sorry for my poor english...
 
Old 03-28-2009, 06:44 PM   #2
i92guboj
Gentoo support team
 
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,074

Rep: Reputation: 386Reputation: 386Reputation: 386Reputation: 386
Quote:
Originally Posted by Michael235 View Post
ls "$dir1" | wc -l > r
ls "$dir2" | wc -l > t
Use quotations, otherwise you are going to have a bad time if the directory has spaces in its name.

Quote:
cat r
cat t

#let y=r+t I had error in this part I'm stuck here
#echo y
Is there any reason why you use files to store the numbers? If there's one, then you will need to inline the cat's so they are expanded in the same formula, like this.

Code:
let y=$(cat r)+$(cat t)
But, what I'd do is to store the numbers in variables instead, so my version of the program would be more like this:

Code:
r=$(ls dir1 | wc -l)
t=$(ls dir2 | wc -l)
let y=$r+$t
 
Old 03-28-2009, 06:49 PM   #3
Michael235
LQ Newbie
 
Registered: Mar 2009
Posts: 2

Original Poster
Rep: Reputation: 0
thank you

It works!!!
Thanks man!!!
 
  


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
Copying files and sub-directories of a directory except the directories named ".abc" sri1025 Linux - General 2 08-24-2010 09:53 AM
Total Numbers James L. Westrich General 3 12-03-2006 06:22 PM
CHMOD directories.sub-directories.files zerojosh Linux - Software 2 11-19-2005 04:22 PM
List total number of directories paraiso Linux - Newbie 5 04-18-2005 05:04 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 07:48 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration