Dear group. How do I do to, within a scrip, check if a directory I empty or not. Cant find a way to do this in a simple way.
With best regards
Tomas Larsson Sweden
Verus Amicus Est Tamquam Alter Idem
On Tue, 2006-06-27 at 12:03 +0200, Tomas Larsson wrote:
Dear group. How do I do to, within a scrip, check if a directory I empty or not. Cant find a way to do this in a simple way.
DIR_CONTENTS=`ls $DIR` if [ "$DIR_CONTENTS" == "" ] then echo "$DIR is empty" else echo "$DIR contains:" echo $DIR_CONTENTS fi
Cheers, Ben
With best regards
Tomas Larsson Sweden
Verus Amicus Est Tamquam Alter Idem
Ben Stringer wrote:
On Tue, 2006-06-27 at 12:03 +0200, Tomas Larsson wrote:
Dear group. How do I do to, within a scrip, check if a directory I empty or not. Cant find a way to do this in a simple way.
DIR_CONTENTS=`ls $DIR` if [ "$DIR_CONTENTS" == "" ] then echo "$DIR is empty" else echo "$DIR contains:" echo $DIR_CONTENTS fi
I'd use "ls -A $DIR" there rather than "ls $DIR" so as to spot files with names starting with a dot.
Paul.
-----Original Message----- From: fedora-list-bounces@redhat.com [mailto:fedora-list-bounces@redhat.com] On Behalf Of Paul Howarth Sent: Tuesday, June 27, 2006 12:34 PM To: For users of Fedora Core releases Subject: Re: Bash problems?
Ben Stringer wrote:
On Tue, 2006-06-27 at 12:03 +0200, Tomas Larsson wrote:
Dear group. How do I do to, within a scrip, check if a directory I
empty or not.
Cant find a way to do this in a simple way.
DIR_CONTENTS=`ls $DIR` if [ "$DIR_CONTENTS" == "" ] then echo "$DIR is empty" else echo "$DIR contains:" echo $DIR_CONTENTS fi
I'd use "ls -A $DIR" there rather than "ls $DIR" so as to spot files with names starting with a dot.
Paul.
Thanks all, however for some reason 'ls $DIR' didn't work. $(ls $DIR) did the job.
Now, I want to exlude sub-dirs in the ls command?
With best regards
Tomas Larsson Sweden
Verus Amicus Est Tamquam Alter Idem
On Tue, 2006-06-27 at 13:23 +0200, Tomas Larsson wrote:
-----Original Message----- From: fedora-list-bounces@redhat.com [mailto:fedora-list-bounces@redhat.com] On Behalf Of Paul Howarth Sent: Tuesday, June 27, 2006 12:34 PM To: For users of Fedora Core releases Subject: Re: Bash problems?
Ben Stringer wrote:
On Tue, 2006-06-27 at 12:03 +0200, Tomas Larsson wrote:
Dear group. How do I do to, within a scrip, check if a directory I
empty or not.
Cant find a way to do this in a simple way.
DIR_CONTENTS=`ls $DIR` if [ "$DIR_CONTENTS" == "" ] then echo "$DIR is empty" else echo "$DIR contains:" echo $DIR_CONTENTS fi
I'd use "ls -A $DIR" there rather than "ls $DIR" so as to spot files with names starting with a dot.
Yes - nice improvement Paul.
Paul.
Thanks all, however for some reason 'ls $DIR' didn't work. $(ls $DIR) did the job.
You had the ticks the wrong way. But using the round brackets is equivalent.
Now, I want to exlude sub-dirs in the ls command?
Look at using the "find" command with the option -maxdepth 1
Eg.
DIR_CONTENTS=$( find $DIR -maxdepth 1 -type f )
Note that this will _only_ find files, not symlinks, block/char special files, sockets etc. See the find manpage for details on "-type f".
Cheers, Ben
With best regards
Tomas Larsson Sweden
Verus Amicus Est Tamquam Alter Idem
-----Original Message----- From: fedora-list-bounces@redhat.com [mailto:fedora-list-bounces@redhat.com] On Behalf Of Ben Stringer Sent: Tuesday, June 27, 2006 1:43 PM To: For users of Fedora Core releases Subject: RE: Bash problems?
On Tue, 2006-06-27 at 13:23 +0200, Tomas Larsson wrote:
-----Original Message----- From: fedora-list-bounces@redhat.com [mailto:fedora-list-bounces@redhat.com] On Behalf Of Paul Howarth Sent: Tuesday, June 27, 2006 12:34 PM To: For users of Fedora Core releases Subject: Re: Bash problems?
Ben Stringer wrote:
On Tue, 2006-06-27 at 12:03 +0200, Tomas Larsson wrote:
Dear group. How do I do to, within a scrip, check if a directory I
empty or not.
Cant find a way to do this in a simple way.
DIR_CONTENTS=`ls $DIR` if [ "$DIR_CONTENTS" == "" ] then echo "$DIR is empty" else echo "$DIR contains:" echo $DIR_CONTENTS fi
I'd use "ls -A $DIR" there rather than "ls $DIR" so as to
spot files
with names starting with a dot.
Yes - nice improvement Paul.
Paul.
Thanks all, however for some reason 'ls $DIR' didn't work. $(ls $DIR) did the job.
You had the ticks the wrong way. But using the round brackets is equivalent.
Now, I want to exlude sub-dirs in the ls command?
Look at using the "find" command with the option -maxdepth 1
Eg.
DIR_CONTENTS=$( find $DIR -maxdepth 1 -type f )
Note that this will _only_ find files, not symlinks, block/char special files, sockets etc. See the find manpage for details on "-type f".
Cheers, Ben
With best regards
Tomas Larsson Sweden
Verus Amicus Est Tamquam Alter Idem
Thanks, seems to do the job.
With best regards
Tomas Larsson Sweden
Verus Amicus Est Tamquam Alter Idem
Just installed FC6, since my old RH9 box died. It seems to no-way to mount the cd-rom. Getting errormessages that /dev/hda not exist in fstab or mtab.
How do I solve this issue?
With best regards
Tomas Larsson Sweden http://www.tlec.se http://www.ktl.mine.nu http://www.naks.mine.nu for downloads etc. ftp://ftp.servage.net for uploads use "naks" as both password and username. Or you can use the free www.yousendit.com service. http://www.servage.net/?coupon=cust23962 Verus Amicus Est Tamquam Alter Idem
Tomas Larsson wrote:
Just installed FC6, since my old RH9 box died. It seems to no-way to mount the cd-rom. Getting errormessages that /dev/hda not exist in fstab or mtab.
How do I solve this issue?
With best regards
Tomas Larsson Sweden
Depending on how you have your desktop set up, it should ether auto-mount or produce a desktop icon that will let you mount it. If you want to mount it from the command line, try using gnome-mount. In your case, probably:
gnome-mount /dev/hda
Mikkel
-----Original Message----- From: fedora-list-bounces@redhat.com [mailto:fedora-list-bounces@redhat.com] On Behalf Of Mikkel L. Ellertson Sent: Sunday, December 03, 2006 9:46 PM To: For users of Fedora Subject: Re: FC6, CD-Roms, can't mount
Tomas Larsson wrote:
Just installed FC6, since my old RH9 box died. It seems to no-way to mount the cd-rom. Getting errormessages that /dev/hda not exist in fstab or mtab.
How do I solve this issue?
With best regards
Tomas Larsson Sweden
Depending on how you have your desktop set up, it should ether auto-mount or produce a desktop icon that will let you mount it. If you want to mount it from the command line, try using gnome-mount. In your case, probably:
gnome-mount /dev/hda
Mikkel
Do not meddle in the affairs of dragons, for thou art crunchy and taste good with Ketchup!
Only text installed, no graphics. Was trying mount /dev/cdrom
With best regards
Tomas Larsson Sweden http://www.tlec.se http://www.ktl.mine.nu http://www.naks.mine.nu for downloads etc. ftp://ftp.servage.net for uploads use "naks" as both password and username. Or you can use the free www.yousendit.com service. http://www.servage.net/?coupon=cust23962 Verus Amicus Est Tamquam Alter Idem
It seems to me that ISO9660 is missing in the current release, please correct me if I'm wrong. It does not exist in fstab or in /proc/fs.
With best regards
Tomas Larsson Sweden http://www.tlec.se http://www.ktl.mine.nu http://www.naks.mine.nu for downloads etc. ftp://ftp.servage.net for uploads use "naks" as both password and username. Or you can use the free www.yousendit.com service. http://www.servage.net/?coupon=cust23962 Verus Amicus Est Tamquam Alter Idem
-----Original Message----- From: fedora-list-bounces@redhat.com [mailto:fedora-list-bounces@redhat.com] On Behalf Of Tomas Larsson Sent: Sunday, December 03, 2006 9:56 PM To: 'For users of Fedora' Subject: RE: FC6, CD-Roms, can't mount
-----Original Message----- From: fedora-list-bounces@redhat.com [mailto:fedora-list-bounces@redhat.com] On Behalf Of Mikkel L. Ellertson Sent: Sunday, December 03, 2006 9:46 PM To: For users of Fedora Subject: Re: FC6, CD-Roms, can't mount
Tomas Larsson wrote:
Just installed FC6, since my old RH9 box died. It seems to no-way to mount the cd-rom. Getting errormessages that /dev/hda not exist in fstab or mtab.
How do I solve this issue?
With best regards
Tomas Larsson Sweden
Depending on how you have your desktop set up, it should ether auto-mount or produce a desktop icon that will let you mount it. If you want to mount it from the command line, try using gnome-mount. In your case, probably:
gnome-mount /dev/hda
Mikkel
Do not meddle in the affairs of dragons, for thou art crunchy and taste good with Ketchup!
Only text installed, no graphics. Was trying mount /dev/cdrom
With best regards
Tomas Larsson Sweden http://www.tlec.se http://www.ktl.mine.nu http://www.naks.mine.nu for downloads etc. ftp://ftp.servage.net for uploads use "naks" as both password and username. Or you can use the free www.yousendit.com service. http://www.servage.net/?coupon=cust23962 Verus Amicus Est Tamquam Alter Idem
-- fedora-list mailing list fedora-list@redhat.com To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
I finally got it mounted manually. But why, on my FC4 server the cd is automounted, why does it not work under FC6
With best regards
Tomas Larsson Sweden http://www.tlec.se http://www.ktl.mine.nu http://www.naks.mine.nu for downloads etc. ftp://ftp.servage.net for uploads use "naks" as both password and username. Or you can use the free www.yousendit.com service. http://www.servage.net/?coupon=cust23962 Verus Amicus Est Tamquam Alter Idem
-----Original Message----- From: Mikkel L. Ellertson [mailto:mikkel@infinity-ltd.com] Sent: Monday, December 04, 2006 12:12 AM To: tomas@tlec.se; For users of Fedora Subject: Re: FC6, CD-Roms, can't mount
Tomas Larsson wrote:
Only text installed, no graphics. Was trying mount /dev/cdrom
Try gnome-mount /dev/cdrom
On Mon, 2006-12-04 at 02:48 +0100, Tomas Larsson wrote:
I finally got it mounted manually. But why, on my FC4 server the cd is automounted, why does it not work under FC6
In FC4 you had lines in fstab like: /dev/hdc /media/cdrecorder auto pamconsole,exec,noauto,managed 0 0
The managed meant automatic mounting. FC5 and FC6 developers had what they thought was a different but "not necessarily better" idea. Fedora is supposed to be a testbed so different ideas get tried. No lines about cdroms in /etc/fstab. So the mounting behavior is different. ======================================================================= A gourmet who thinks of calories is like a tart that looks at her watch. -- James Beard ======================================================================= Aaron Konstam telephone: (210) 656-0355 e-mail: akonstam@sbcglobal.net
Aaron Konstam wrote:
On Mon, 2006-12-04 at 02:48 +0100, Tomas Larsson wrote:
I finally got it mounted manually. But why, on my FC4 server the cd is automounted, why does it not work under FC6
In FC4 you had lines in fstab like: /dev/hdc /media/cdrecorder auto pamconsole,exec,noauto,managed 0 0
The managed meant automatic mounting. FC5 and FC6 developers had what they thought was a different but "not necessarily better" idea. Fedora is supposed to be a testbed so different ideas get tried. No lines about cdroms in /etc/fstab. So the mounting behavior is different. ======================================================================= A gourmet who thinks of calories is like a tart that looks at her watch.
-- James Beard
Aaron Konstam telephone: (210) 656-0355 e-mail: akonstam@sbcglobal.net
So what's the resolution on this CD/DVD mounting issue. I hope it's not a manual mount of the device. Haven't we gone beyond that yet? Am I missing something?
Loving Fedora...
Doug P
On Fri, 2006-12-08 at 13:11 -0800, Douglas Phillipson wrote:
Aaron Konstam wrote:
On Mon, 2006-12-04 at 02:48 +0100, Tomas Larsson wrote:
I finally got it mounted manually. But why, on my FC4 server the cd is automounted, why does it not work under FC6
In FC4 you had lines in fstab like: /dev/hdc /media/cdrecorder auto pamconsole,exec,noauto,managed 0 0
The managed meant automatic mounting. FC5 and FC6 developers had what they thought was a different but "not necessarily better" idea. Fedora is supposed to be a testbed so different ideas get tried. No lines about cdroms in /etc/fstab. So the mounting behavior is different. ======================================================================= A gourmet who thinks of calories is like a tart that looks at her watch.
-- James Beard
Aaron Konstam telephone: (210) 656-0355 e-mail: akonstam@sbcglobal.net
So what's the resolution on this CD/DVD mounting issue. I hope it's not a manual mount of the device. Haven't we gone beyond that yet? Am I missing something?
I am sorry I missed the main point. In FC6 when you put in a CD it is mounted a CD icon appears on the desktop. What happens next depends on what kind of CD it is. Audios are played, data CD's are opened on the screen in a Nautilus window. In gnome what happens is controlled by the gui in: System -> Preferences-> Removable Drives and Media
On Sun, Dec 03, 2006 at 09:33:37PM +0100, Tomas Larsson wrote:
Just installed FC6, since my old RH9 box died. It seems to no-way to mount the cd-rom. Getting errormessages that /dev/hda not exist in fstab or mtab.
^^^
Are you sure your CD-ROM drive is at /dev/hda? Usually that's a hard drive. I'd try /dev/hdc or hdd. Or an appropriate symlink:
ls /dev/cd*
What, if anything, does /etc/fstab have to say?
Things have changed since RH9. You may need to create a mount point. The new custom is to put it in /media instead of /mnt, so:
mkdir /media/cdrom
then pick an appropriate device to mount, e.g.:
mount /dev/cdrom /media/cdrom
Tomas Larsson wrote:
Just installed FC6, since my old RH9 box died. It seems to no-way to mount the cd-rom. Getting errormessages that /dev/hda not exist in fstab or mtab.
How do I solve this issue?
With best regards
Tangential point, but if you reply to a message to start a new topic people using a threaded view may not see it if it's buried in a thread they're ignoring.
Tomas Larsson wrote:
Thanks all, however for some reason 'ls $DIR' didn't work. $(ls $DIR) did the job.
The reason that 'ls $DIR' did not work is that it was not what was shown in the example, what was shown and does work is:
`ls $DIR`
which uses back ticks, a subtle difference. :-)
Tomas Larsson wrote:
Dear group. How do I do to, within a scrip, check if a directory I empty or not. Cant find a way to do this in a simple way.
With best regards
Tomas Larsson Sweden
Verus Amicus Est Tamquam Alter Idem
I see you got some good answers. For future reference, the "Advanced Bash Scripting Guide" is something you should be familiar with. It will take you from novice to Bash god!
www.tldp.org/LDP/abs/html/
Regards,
John
Tomas Larsson wrote:
Dear group. How do I do to, within a scrip, check if a directory I empty or not. Cant find a way to do this in a simple way.
Try these:
function isempty { test "`find "$1" -prune -empty`"; }
function isemptydir { test "`find "$1" -prune -type d -empty`"; }
The first returns true for either empty files or empty directories; the second returns true only if the given file is an empty directory.
$ mkdir emptydir; touch emptyfile $ if isempty emptydir; then echo 'yes'; else echo 'no'; fi yes $ if isempty emptyfile; then echo 'yes'; else echo 'no'; fi yes $ if isemptydir emptyfile; then echo 'yes'; else echo 'no'; fi no $ if isemptydir emptydir; then echo 'yes'; else echo 'no'; fi yes
Using find to make a direct test is more efficient (and far more efficient for large directories) than listing the contents of a directory just to see if there's anything in it--not that efficiency in shell scripts matters all that much.
Here's some more tests (and some things to watch out for)...
$ if isemptydir /tmp; then echo 'yes'; else echo 'no'; fi no $ if isempty /tmp; then echo 'yes'; else echo 'no'; fi no $ if isempty /lost+found; then echo 'yes'; else echo 'no'; fi find: /lost+found: Permission denied no $ if isempty /usr/tmp; then echo 'yes'; else echo 'no'; fi no $ ls -a /usr/tmp . .. $ if isemptydir /usr/tmp; then echo 'yes'; else echo 'no'; fi no $ ls -l /usr/tmp lrwxrwxrwx 1 root root 10 Jun 8 19:22 /usr/tmp -> ../var/tmp $ if isemptydir /var/tmp; then echo 'yes'; else echo 'no'; fi yes
<Joe