Help answer threads with 0 replies.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 03-28-2009, 05:35 PM   #1
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, 05:44 PM   #2
Gentoo support team
Registered: May 2008
Location: Lucena, Córdoba (Spain)
Distribution: Gentoo
Posts: 4,083

Rep: Reputation: 404Reputation: 404Reputation: 404Reputation: 404Reputation: 404
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.

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.

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:

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

Original Poster
Rep: Reputation: 0
thank you

It works!!!
Thanks man!!!


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 08:53 AM
Total Numbers James L. Westrich General 3 12-03-2006 05:22 PM
CHMOD directories.sub-directories.files zerojosh Linux - Software 2 11-19-2005 03:22 PM
List total number of directories paraiso Linux - Newbie 5 04-18-2005 04:04 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 12:13 AM.

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