finding 0 byte files in current directory only


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting finding 0 byte files in current directory only
# 1  
Old 07-21-2008
finding 0 byte files in current directory only

Hi Gurus,
I have a directory A, which has some 0 byte files in it.
This directory also has a subdirectory B which also has some 0 byte files in it.

The problem:
I only need to find out the names of the 0 byte files in the directory A.
I'm using the following command
find . -name *.zip -size 0c

This command not only lists the 0 byte files within dorectory A , but also lists the 0 byte files within directory B.

./x001_ameint_BP010F0010_00264_001.zip
./B/x001_ameint_DV010F0065_00264_001.zip

how to get only the 0 byte files in current directory but not in its sub directories.

Please help
thanks
Ram.
# 2  
Old 07-21-2008
You can add the -maxdepth switch to find and set it to 1:

-maxdepth 1

Hope this helps.
# 3  
Old 07-21-2008
Tools use prune if you know the directory, or maxdepth

skip subdirectories the begin with letter B
Code:
find . B* -prune -name *.zip -size 0c

limit to no subdirectories
Code:
find . -maxdepth 1 -name *.zip -size 0c

# 4  
Old 07-21-2008
thanks for the reply...

thanks for the reply...
but here is what i get when i use maxdepth

find . -maxdepth 1 -name *.zip -size 0c
find: bad option -maxdepth
find: path-list predicate-list
# 5  
Old 07-21-2008
If your find version don't support the -maxdepth option or you have many subdirectories to exclude you can do something like:

Code:
ls -l *.zip | awk '$5==0'

# 6  
Old 07-21-2008
Code:
find . -name "*.zip" -size 0c -name "dirB" -prune

# 7  
Old 07-21-2008
-maxdepth is a GNU find option. POSIX find doesn't have it - yet. So a lot of unix boxes do not have it

-prune is good.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Find all files in the current directory excluding hidden files and directories

Find all files in the current directory only excluding hidden directories and files. For the below command, though it's not deleting hidden files.. it is traversing through the hidden directories and listing normal which should be avoided. `find . \( ! -name ".*" -prune \) -mtime +${n_days}... (7 Replies)
Discussion started by: ksailesh1
7 Replies

2. Shell Programming and Scripting

Finding 4 current files having specific File Name pattern

Hi All, I am trying to find 4 latest files inside one folder having following File Name pattern and store them into 4 different variables and then use for processing in my shell script. File name is fixed length. 1) Each file starts with = ABCJmdmfbsjop letters + 7 Digit Number... (6 Replies)
Discussion started by: lancesunny
6 Replies

3. Shell Programming and Scripting

using c programming in unix to delete zero-byte files in a specified directory

we were asked to make a program that deletes all zero-byte files in a psecified directory. we need to use sysytem_calls like: scandir(),chdir(),stat() and remove(). (3 Replies)
Discussion started by: sogetsu009
3 Replies

4. Shell Programming and Scripting

Find files ONLY in current directory

Hello all, I am having a hard type in figuring out how to only gather certain files in the current directory without exploring its subdirectories. I tried: find . -name "*.ksh" -prune this also returns ksh files from lower subdirectories. I also tried find . -ls -name "*.ksh" This also... (8 Replies)
Discussion started by: gio001
8 Replies

5. Shell Programming and Scripting

How to strip ^M at end of each files for all files found in current directory

I am trying to use a loop to strip of the funny character ^M at the end of all lines in each file found in current directory and I have used the following in a script: find . -type f -name '*.txt' | while read file do echo "stripping ^M from ..." ex - "$file" > $tempfile %s/^M//g wq! # mv... (4 Replies)
Discussion started by: bisip99
4 Replies

6. Shell Programming and Scripting

mget * (obtein files from current directory but not the files form sub-directories)

Hello, Using the instruction mget (within ftp) and with "Interactive mode off", I want to get all files from directory (DirAA), but not the files in sub-directories. The files names don't follow any defined rule, so they can be just letters without (.) period Directory structure example: ... (0 Replies)
Discussion started by: Peter321
0 Replies

7. Shell Programming and Scripting

Finding files in current directory when 100,000's files in current directory

Hi All I was wondering what is the most efficient way to find files in the current directory(that may contain 100,000's files), that meets a certain specified file type and of a certain age. I have experimented with the find command in unix but it also searches all sub directories. I have... (2 Replies)
Discussion started by: kewong007
2 Replies

8. Shell Programming and Scripting

Finding files older than the current date and time and renaming and moving

Hi, I have a very urgent requirement here. I have to find all files in the specified directory but not in the sub directories(The directory name is stored in a variable) which are older than the current date as well as current time and rename it as filename_yyyymmddhhmmss.ext and move it into a... (7 Replies)
Discussion started by: ragavhere
7 Replies

9. Shell Programming and Scripting

Check if 2 files are identical byte-to-byte?

In my server migration requirement, I need to compare if one file on old server is exactly the same as the corresponding file on the new server. For diff and comm, the inputs need to be sorted. But I do not want to disturb the content of the file and need to find byte-to-byte match. Please... (4 Replies)
Discussion started by: krishmaths
4 Replies

10. Programming

Finding largest file in current directory?

I was hoping to get some assistance with this C program I am working on. The goal is to find the largest file in the current directory and then display this filename along with the filesize. What I have so far will display all the files in the current directory. But, how do I deal with "grabbing"... (1 Reply)
Discussion started by: AusTex
1 Replies
Login or Register to Ask a Question