Printing empty subdirs before delete


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Printing empty subdirs before delete
# 8  
Old 01-12-2012
Code:
 
count=$(ls -lR | grep -c "total 0")
echo $count
[ "$count" -eq "0" ] && echo "There are no empty dirs in this dir" || echo $count
#To Print the Empty directory
ls -lR | nawk '/^\./{f=$1}/^total 0/{print f}'

# 9  
Old 01-12-2012
Thanks itkamaraj
This is working fine at command prompt but when i write it inside script I am getting
syntax error at line 1: `count=$' unexpected error

Quote:
Originally Posted by itkamaraj
Code:
 
count=$(ls -lR | grep -c "total 0")
echo $count
[ "$count" -eq "0" ] && echo "There are no empty dirs in this dir" || echo $count
#To Print the Empty directory
ls -lR | nawk '/^\./{f=$1}/^total 0/{print f}'

# 10  
Old 01-13-2012
try with

Code:
count=`ls -lR | grep -c "total 0"`

# 11  
Old 01-13-2012
i) This is storing ls -lR | grep -c "total 0" in $count ...and not the number of empty dirs...
ii)
ls -lR | nawk '/^\./{f=$1}/^total 0/{print f}'
displays those dirs also which has empty files ..is there anyway to exclude those.

Quote:
Originally Posted by itkamaraj
try with

Code:
count=`ls -lR | grep -c "total 0"`

# 12  
Old 01-13-2012
what is mean by ?

This is storing ls -lR | grep -c "total 0" in $count ...and not the number of empty dirs...


---------- Post updated at 09:59 AM ---------- Previous update was at 09:50 AM ----------

Use back ticks, see the posting carefully Smilie

Code:
 
count=`ls -lR | grep -c "total 0"`

# 13  
Old 01-13-2012
Sorry for confusion it is working fine...only thing it counts those dirs also which has empty files ..is there anyway to exclude those dir from the total count..
Quote:
Originally Posted by itkamaraj
what is mean by ?

This is storing ls -lR | grep -c "total 0" in $count ...and not the number of empty dirs...
# 14  
Old 01-13-2012
try this..

Code:
 
find . -type d | while read d; do [ $(( $(ls -a1 $d | wc -l) >= 3 )) == 0 ] && echo $d; done | wc -l

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 for Dummies Questions & Answers

How to delete some empty folders?

I have an amount of folders and I want to delete only the empty ones. But I have more than 200 empty folders, so I would preffer do not delete one by one... I know it is possible, but I don't know how. I've tried with the size, using 'du' command, and saving the result in a file. After that, I made... (3 Replies)
Discussion started by: saitsug
3 Replies

3. UNIX for Advanced & Expert Users

Delete empty directories recursively - HP-UX

Hi, I want to delete all empty directories in a long directore tree structure. I want to use that from a script that will run on HP-UX 11. My definition of empty directory is that there is no regular file under it and directly beneath it. To elaborate, I have below directories. /app/dev/java... (14 Replies)
Discussion started by: asutoshch
14 Replies

4. Shell Programming and Scripting

Script to delete empty files

I'm trying to write a shell script to files of zero length in a specified directory, but I keep getting errors. Would anybody be kind enough to look it over for issues? Thanks a bunch in advance. #!/bin/sh if then if then find $1 -type f -size 0 -print|xargs rm exit 0... (1 Reply)
Discussion started by: ScriptingIssues
1 Replies

5. Shell Programming and Scripting

delete lines with empty second column

hi, I'd like to ask you if you can help me with such surely easy thing - I have some data and need to plot them. I have txt of data in two columns, tab separated, but some second columns are empty. like 1```` 2 1.2`` 3```` 2 4.44` 5````` 6.1```1 how can I erase all the lines... (2 Replies)
Discussion started by: bsco
2 Replies

6. UNIX for Dummies Questions & Answers

Help required on printing the line if third field is not a empty space

Hi Experts, I want to print the lines whose third field in non-empty/blank space. i.e. INPUT FILE/B] dcdccghjrry0yd cont dcdccttrk820529 cont rdekedfsSCr dcdccttrdky2d0y cont rdekedfsSC2 ... (3 Replies)
Discussion started by: krao
3 Replies

7. UNIX for Advanced & Expert Users

How to delete empty lines

abc# abc#this is a test abc#this is a test to delete abc# xyz# xyz#this is a test two xyz# In the above example '#' is common. How to do delete the emply lines. In specific to observe the output as: abc#this is a test abc#this is a test to delete xyz#this is a test two . . . . (5 Replies)
Discussion started by: Aejaz
5 Replies

8. Shell Programming and Scripting

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... (2 Replies)
Discussion started by: Script40
2 Replies

9. Shell Programming and Scripting

delete multiple empty lines

Hi, I need to delete the lines with empty name. What is the best way to do it? Thanks a lot for your help! EMID MMDDYY HOURS JOB EMNAME 0241 051605 11.40 52062 someone 0520 051605 10.63 52062 0520 051605 10.66 52062 0520 051605 10.65 52062 (3 Replies)
Discussion started by: whatisthis
3 Replies

10. Shell Programming and Scripting

printing an empty line in a file (perl)

I know this must be really easy, but i can't get it to work I've got a perl script, with a file. I want to print an empty line, and the following doesn't seem to work: print nameoffile "\n" thanks for your help!! (3 Replies)
Discussion started by: kfad
3 Replies
Login or Register to Ask a Question