PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > writing a program to list files
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

writing a program to list files

Réponse
 
LinkBack Outils de la discussion
Vieux 05/12/2006, 16h43   #1
laredotornado@zipmail.com
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut writing a program to list files

Hello,

I'm running Fedora Core 5 Linux. I was wondering how I would write a
shell script, that given a directory name, prints out all the child
files, including those in sub-directories. So, for example, if I had a
root directory, "base", with two files "a.txt", "b.txt", and one
sub-directory "basesub", which contained one file, "basesub/c.txt", I
would like my shell script to print out

> sh myscript.sh basedir


a.txt
b.txt
basesub/c.txt

How can this be done?

Thanks, - Dave

  Réponse avec citation
Vieux 05/12/2006, 16h54   #2
Janis Papanagnou
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: writing a program to list files

laredotornado@zipmail.com wrote:
> Hello,
>
> I'm running Fedora Core 5 Linux. I was wondering how I would write a
> shell script, that given a directory name, prints out all the child
> files, including those in sub-directories. So, for example, if I had a
> root directory, "base", with two files "a.txt", "b.txt", and one
> sub-directory "basesub", which contained one file, "basesub/c.txt", I
> would like my shell script to print out
>
>
>>sh myscript.sh basedir

>
>
> a.txt
> b.txt
> basesub/c.txt
>
> How can this be done?


Would this be sufficient for your requirements...?

find basedir -type f -print

The '-print' might be optional on your system.

Janis


>
> Thanks, - Dave
>

  Réponse avec citation
Vieux 05/12/2006, 16h57   #3
Stephane CHAZELAS
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: writing a program to list files

2006-12-5, 08:43(-08), laredotornado@zipmail.com:
> Hello,
>
> I'm running Fedora Core 5 Linux. I was wondering how I would write a
> shell script, that given a directory name, prints out all the child
> files, including those in sub-directories. So, for example, if I had a
> root directory, "base", with two files "a.txt", "b.txt", and one
> sub-directory "basesub", which contained one file, "basesub/c.txt", I
> would like my shell script to print out
>
>> sh myscript.sh basedir

>
> a.txt
> b.txt
> basesub/c.txt
>
> How can this be done?

[...]

#! /path/to/your/unix/sh -
status=0
for dir do
(
cd -P -- "$dir" &&
exec find . ! -type d -print | sed 's,^\./,,'
) || status=$?
done
exit "$status"


--
Stéphane
  Réponse avec citation
Vieux 05/12/2006, 17h01   #4
Glenn Jackman
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: writing a program to list files

At 2006-12-05 11:43AM, "laredotornado@zipmail.com" wrote:
> Hello,
>
> I'm running Fedora Core 5 Linux. I was wondering how I would write a
> shell script, that given a directory name, prints out all the child
> files, including those in sub-directories. So, for example, if I had a
> root directory, "base", with two files "a.txt", "b.txt", and one
> sub-directory "basesub", which contained one file, "basesub/c.txt", I
> would like my shell script to print out
>
> > sh myscript.sh basedir

>
> a.txt
> b.txt
> basesub/c.txt
>
> How can this be done?


cd $basedir
find . -type f

--
Glenn Jackman
Ulterior Designer
  Réponse avec citation
Vieux 05/12/2006, 23h33   #5
Theo v. Werkhoven
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: writing a program to list files

The carbonbased lifeform laredotornado@zipmail.com inspired
comp.unix.shell with:
> Hello,
>
> I'm running Fedora Core 5 Linux. I was wondering how I would write a
> shell script, that given a directory name, prints out all the child
> files, including those in sub-directories. So, for example, if I had a
> root directory, "base", with two files "a.txt", "b.txt", and one
> sub-directory "basesub", which contained one file, "basesub/c.txt", I
> would like my shell script to print out
>
>> sh myscript.sh basedir

>
> a.txt
> b.txt
> basesub/c.txt
>
> How can this be done?


#v+
cd $basedir
tree --noreport -fiF .| cut -c3-|egrep -v ".*\/$"
cd - >/dev/null
#v-

Theo
--
theo at van-werkhoven.nl ICQ:277217131 SuSE Linux
linuxcounter.org: 99872 Jabber:muadib at jabber.xs4all.nl AMD XP3000+ 1024MB
"ik _heb_ niets tegen Microsoft, ik heb iets tegen
de uitwassen *van* Microsoft"
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h33.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,10164 seconds with 13 queries