Not able to include wc -l inside expr [message #178891] |
Fri, 23 June 2006 05:41 |
janetwilson
Messages: 48 Registered: June 2006 Location: St.Louis
|
Member |
|
|
Hi,
I'm not able to include wc -l inside expr
I want to display the number of files & directories inside a directory.
ls -l | wc -l
In my unix machine ls -l display a total.
The result of ls -l may look like this
total 28
-rw-rw-r-- 1 oracle oracle 380 Jun 16 17:44 fifth.sh
-rw-rw-r-- 1 oracle oracle 186 Jun 13 16:38 first.sh
-rw-rw-r-- 1 oracle oracle 222 Jun 15 18:43 fourth.sh
drwxrwxr-x 2 oracle oracle 4096 Jun 23 15:39 one
-rw-rw-r-- 1 oracle oracle 2275 Jun 13 17:59 second.sh
-rw-rw-r-- 1 oracle oracle 488 Jun 22 17:04 sixth.sh
-rw-rw-r-- 1 oracle oracle 154 Jun 15 15:21 third.sh
I want to avoid the first line (total 28).
ls -l | wc -l shows 8. actually there are 6 files and one directory. A total of 7.
so i changed my code like
ls -l | expr `wc -l -1`
but it is giving error.
Can you please rectify the error.
Thanks & Regards
Janet Wilson
|
|
|
|
|
Re: Not able to include wc -l inside expr [message #178988 is a reply to message #178897] |
Fri, 23 June 2006 15:05 |
andrew again
Messages: 2577 Registered: March 2000
|
Senior Member |
|
|
hp-ux11>>ls -l
total 0
drwxrwxr-x 2 scott users 96 Jun 23 12:49 dummy_dir
-rw-rw-r-- 1 scott users 0 Jun 23 12:45 file
-rw-rw-r-- 1 scott users 0 Jun 23 12:46 file1
-rw-rw-r-- 1 scott users 0 Jun 23 12:45 file2
-rw-rw-r-- 1 scott users 0 Jun 23 12:46 file3
lrwxrwxr-x 1 scott users 5 Jun 23 12:46 file3_lnk -> file3
hp-ux11>>ls -l | grep ^-
-rw-rw-r-- 1 scott users 0 Jun 23 12:45 file
-rw-rw-r-- 1 scott users 0 Jun 23 12:46 file1
-rw-rw-r-- 1 scott users 0 Jun 23 12:45 file2
-rw-rw-r-- 1 scott users 0 Jun 23 12:46 file3
hp-ux11>>ls -l | grep ^- | wc -l
4
|
|
|
|