LinuxQuestions.org
Register a domain and help support LQ
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices



Reply
 
Search this Thread
Old 07-10-2003, 02:27 PM   #1
odious1
Member
 
Registered: Jun 2003
Location: Virginia, USA
Distribution: Slackware
Posts: 252

Rep: Reputation: 30
search methods


I am trying to locate an empty directory. I have tried locate and find with no luck. Does anyone know of a way to accomplish this?

Thanks
 
Old 07-10-2003, 03:34 PM   #2
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Copy everything in the code section below into a file:
Code:
#!/bin/bash

if [ $1 ] ; then
  if [ -d $1 ] ; then
    search_root=$1
  else
    search_root="/"
  fi
else
  search_root="/"
fi

dir_list=`find ${search_root} -type d`

for directory in "$dir_list" ; do
  file_list=`ls -lA ${directory}`

  if [ -z "${file_list}" ]
    echo "Empty directory: ${directory}"
done
Save the file as empty_dir_search.bash (or whatever you like). Then do this:

chmod u+x empty_dir_search.bash
./empty_dir_search.bash /dir_path


Replace /dir_path with something if you are POSITIVE the empty directory is inside a specific folder. If you know the empty directory is somewhere in /home, then put /home for /dir_path. If you have absolutely no idea where it is, then just leave /dir_path out; don't type anything for it.

Thsi script will print out every empty directory it finds.
 
Old 07-10-2003, 04:15 PM   #3
Tinkster
Moderator
 
Registered: Apr 2002
Location: in a fallen world
Distribution: slackware by choice, others too :} ... android.
Posts: 23,005
Blog Entries: 11

Rep: Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903Reputation: 903
Re: search methods

Quote:
Originally posted by odious1
I am trying to locate an empty directory. I have tried locate and find with no luck. Does anyone know of a way to accomplish this?

Thanks
Code:
find -empty ! -type f
seems to work for me :}

Cheers,
Tink
 
Old 07-10-2003, 04:23 PM   #4
Dark_Helmet
Senior Member
 
Registered: Jan 2003
Posts: 2,786

Rep: Reputation: 369Reputation: 369Reputation: 369Reputation: 369
Why do I always make things more difficult than they need to be?

I was trying to introduce shell scripting... yeah, that's what I was trying to do...
 
Old 07-11-2003, 12:11 AM   #5
MasterC
Guru
 
Registered: Mar 2002
Location: Salt Lake City, UT - USA
Distribution: Gentoo ; LFS ; Kubuntu
Posts: 12,612

Rep: Reputation: 64
Quote:
Originally posted by Dark_Helmet
Why do I always make things more difficult than they need to be?

I was trying to introduce shell scripting... yeah, that's what I was trying to do...
What an excellent introduction it was

Cool
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
search default: search post title only slackie1000 LQ Suggestions & Feedback 4 03-10-2005 08:50 AM
Quick VIM question (unhighlighting search terms after search) lrt2003 Linux - Newbie 5 05-08-2004 06:21 PM
java -- methods -- please help Laptop2250 Programming 2 12-13-2003 01:46 AM
Other install methods? Icon Mandriva 7 11-01-2003 05:14 AM
Logging methods rob_roman23 Linux - General 6 08-01-2002 11:10 AM


All times are GMT -5. The time now is 05:14 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration