Delete an empty file from dir.


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Delete an empty file from dir.
# 1  
Old 04-02-2008
Delete an empty file from dir.

Hi,

I have an dir which has 50K file, some of them are empty. I want to delete the empty file from the dir. I am planning to use the following command.

ls -l | grep " 0 " | awk '{print $9}'

I can copy this to an file and then how do I use this file to delete the empty files.... Any help will be appreciated.Smilie

Thanks.
# 2  
Old 04-02-2008
You can do something like this with find:

Code:
find . -size 0 -exec rm -f {} \;

To be shure you get the correct files you can ls those files first with:

Code:
find . -size 0 -exec ls -l {} \;

Regards
# 3  
Old 04-02-2008
Thanks it worked.Smilie
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Delete everything after empty line in file

Hello, I am trying to remove everything coming after empty line under ubuntu14.04. How may I do it? file: aaa 020390 bb00id3 c03wisi 209dl x092sia 0290s I expect: aaa 020390 bb00id3 c03wisi (3 Replies)
Discussion started by: baris35
3 Replies

2. UNIX Desktop Questions & Answers

How to delete dir and sub dir

Guys, can you tell me how to delete directory and sub directory with files in them, for example: /system/upgrade/title/sub/var/vito/ I would like to delete 'title' and everything under it. Every sub dir contains files which need to be deleted as well. Thanks (1 Reply)
Discussion started by: DallasT
1 Replies

3. Shell Programming and Scripting

Delete the last empty/blank line of the text file

Hi All, I have a file.txt which seems like having three lines. wc -l file.txt 3 file.txt In fact, once it is open in text editor, this file has four lines where the last line is empty. how can i delete this last empty line of the file.txt? I tried the codes below so far but they... (6 Replies)
Discussion started by: senayasma
6 Replies

4. UNIX for Dummies Questions & Answers

How to list all files in dir and sub-dir's recursively along with file size?

I am very new to unix as well as shell scripting. I have to write a script for the following requirement. In have to list all the files in directory and its sub directories along with file path and size of the file Please help me in this regard and many thanks in advance. (3 Replies)
Discussion started by: nmakkena
3 Replies

5. Shell Programming and Scripting

How to delete all leading empty lines in a file?

How to delete all leading empty lines in a file? $>cat input.txt test Test $> output file should be test Test $> (14 Replies)
Discussion started by: johnveslin
14 Replies

6. Shell Programming and Scripting

A script to find dir, delete files in, and then del dir?

Hello!! I have directories from 2008, with files in them. I want to create a script that will find the directoried from 2008 (example directory: drwxr-xr-x 2 isplan users 1024 Nov 21 2008 FILES_112108), delete the files within those directories and then delete the directories... (3 Replies)
Discussion started by: bigben1220
3 Replies

7. Shell Programming and Scripting

How to make sure dir is really empty

Hi, I have this piece of shell script: #!/bin/ksh x=data1 x=data1 x=data1 for i in 1 2 3 do cp x $IN_DIR done PerformNextTask $IN_DIR is already designed to automatically pick up x and send x to other directory $OK_DIR. $IN_DIR will be empty once all x goes to $OK_DIR.... (2 Replies)
Discussion started by: luna_soleil
2 Replies

8. Shell Programming and Scripting

empty the dir

i have dir called stock1. it has some 2000 files How to remove/empty the dir in one shot? i tried this command,but its not working rmdir stock1/* stock1/.* (4 Replies)
Discussion started by: ali560045
4 Replies

9. UNIX for Dummies Questions & Answers

want to remove " in a file and delete empty spaces

I have to remove character " in file which occurs at every line and have to delete empty spaces. Please help (2 Replies)
Discussion started by: vikram2008
2 Replies

10. UNIX for Dummies Questions & Answers

Based on the permision in the dir can i delete the file

All, I am having a directory as drwxrwsr-x 3 intermec intermec 10240 Jan 8 09:07 intermec inside the directory . the files are like cd -rw-r----- 1 intrmc01 intermec 5226 Dec 2 15:03 AST07356.txt -rw-r----- 1 intrmc01 intermec 5025 Dec 2 12:51... (4 Replies)
Discussion started by: arunkumar_mca
4 Replies
Login or Register to Ask a Question