1846636 Members
1631 Online
110256 Solutions
New Discussion

Re: Files Count

 
SOLVED
Go to solution
Cliff Lim Kok Hwee
Regular Advisor

Files Count

Gd Day Forum,

I will be performing a filesystem copy to another filesystem using the cp -Rhp option.

I need to verify that the resultant filesystem does not miss out any files.

I run the command ls -al |grep ^d |wc -l for directory count
I run the command ls -al |grep ^- |wc -l for file count
I will run the command ls to grep for
b Block special file
c Character special file
d Directory
l Symbolic link
n Network special file
p Fifo (also called a "named pipe") special file
s Socket
- Ordinary file

Just wondering is there any other better way to perform the file count from the top directory level rather then cd to each directory and perform the ls command mentioned above?

thanks n regards/cliff
10 REPLIES 10
Franky_1
Respected Contributor
Solution

Re: Files Count

Hi,

what about "ls -lR|wc -l" in the top level directory ?
Will give you a summary all over

Simple, but effective :-)

Regards

Franky
Don't worry be happy
Eric Antunes
Honored Contributor

Re: Files Count

Hi Cliff,

cp command warns you for each file it misses! Do it like this:

cp -Rhp ... |more
Each and every day is a good day to learn.
Pete Randall
Outstanding Contributor

Re: Files Count

You could try running "find /dirname |wc -l" in each of the directories. That will count everything - directories, files, etc - and the totals should match.


Pete

Pete
Muthukumar_5
Honored Contributor

Re: Files Count

We can simulate ls operation with find command,

find -name "*"

"*" -- will give all files,

So try as,

OLDFSDIR> cd ; find . -name "*" > /tmp/oldfs.log

NEWFSDIR> cd ; find . -name "*" > /tmp/newfs.log

Check the difference with diff command as,

diff /tmp/oldfs.log /tmp/newfs.log


It will it easily.

More you can use -type on find command too as,

find . -type f -name "*"

f is regular file,

see more on find command for -type option. as
f regular file
b Block special file
c Character special file
d Directory
l Symbolic link
n Network special file
p Fifo (also called a "named pipe") special file
s Socket

HTH.
- Muthu
Easy to suggest when don't know about the problem!
hein coulier
Frequent Advisor

Re: Files Count

find . -exec ll -d {} \; |cut -c1|sort|uniq -c
Tom Danzig
Honored Contributor

Re: Files Count

I would do ls -lR at the top level directory as suggested and output to a temp file. This command could take quite a while depending on the file system and if you need to do multiple pattern mathes (i.e. for files, dirs, etc), you can do it on the temp file which would be much faster and less system intensive.

Franky_1
Respected Contributor

Re: Files Count

Hi,

if someone could help you, please don't forget to assign points

Regards

Franky
Don't worry be happy
RAC_1
Honored Contributor

Re: Files Count

While with options of ls you may get the count for no. of files, dirs, links, socket file etc., how about using dd for copying the file system.

This would ensure that everything is copied to the destination and perms will be same as that of the source. Also you have option of using a larger block size and copy it fast.

dd if=/dev/vgxx/lvolx of=/dev/vgyy/lvoly bs=1024k

Anil
There is no substitute to HARDWORK
Jose Mosquera
Honored Contributor

Re: Files Count

Hi,

Pls try checking the cp's command return code, i.e:

cp -Rp ...
STATUS=$?
if [ "$STATUS" = "0" ]
then
echo "Command concluded successfully"
else
echo "Command concluded with errors"
fi

Rgds.
Cliff Lim Kok Hwee
Regular Advisor

Re: Files Count

Thanks for all the responses guys...

I think ls -lR |wc -l works well.

cheers/cliff