I am pretty new to UNIX. My client has a requirement where in a directory we have some files with somewhat similar name
like test_XX.txt, test_XY.txt, test_XZ.txt, test_ZZ.txt, test_ZY.txt, test_ZX.txt, test_YY.txt......Out of these files
few files have 0 bytes. Is there a way where we can go ahead and remove those files which start with "test"[as that is the only common string in the file name] and have 0 bytes size. I tried the following commands:
find . -type f -size 0 | xargs rm [It removed all the files irrespective of name with 0 byte size]
Is there a solution for this?
Try:
find ./test* -type f -size 0 -exec ls -l {} \;
if that lists only the files you want then:
find ./test* -type f -size 0 -exec rm {} \;
getting this error:find: 0652-009 There is a missing conjunction
Oppsss try again.. Left out a -
Try:
find ./test* -type f -size 0 -exec ls -l {} \;
if that lists only the files you want then:
find ./test* -type f -size 0 -exec rm {} \;
Ikon ,
Its awesome it worked.
I hv a question for my learning as I have mentioned I am pretty new since i only need to use unix when its really meant.
find ./test* -type f -size 0 -exec rm {} \;
I just dont know the underlined part .......I know the use of * as it is used to get the filename or any name starting with test........but the forward slash / i dont know.
Sorry Ikon,
Thank you so much.
You dont have to have the ./
I just use it for "Current Directory"...
find /path/to/some/files/test* -type f -size 0 -exec rm {} \;
I got u now. Nyways thnx so much.