Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
find al contrario [risolto]
View unanswered posts
View posts from last 24 hours
View posts from last 7 days

 
Reply to topic    Gentoo Forums Forum Index Forum italiano (Italian)
View previous topic :: View next topic  
Author Message
Marculin
Guru
Guru


Joined: 24 Feb 2004
Posts: 376

PostPosted: Mon Sep 06, 2004 7:11 pm    Post subject: find al contrario [risolto] Reply with quote

Scusate lo strano topic ma non sapevo come intitolarlo...
In pratica vorrei fare una ricerca all'interno di una cartella (e relative sottocartelle) in cui mi dica che ci sono i seguenti file che non hanno l'estensione indicata...

Quindi tipo "cerca *.txt" e se nella cartella ci sono dei file .wav me li elenchi....grazie per l'aiuto!
_________________
Non capisco perchè continuavo ad avere cosi paura della shell.....è cosi bella :)


Last edited by Marculin on Thu Sep 09, 2004 11:52 am; edited 1 time in total
Back to top
View user's profile Send private message
-Crash-
n00b
n00b


Joined: 29 Jun 2004
Posts: 35
Location: Italy, Milano

PostPosted: Mon Sep 06, 2004 7:55 pm    Post subject: Reply with quote

Quote:
Quindi tipo "cerca *.txt" e se nella cartella ci sono dei file .wav me li elenchi...


non mi e' molto chiaro..ma cercare direttamente nella cartella xyz per *.wav?
_________________
Raddoppia lo spazio sul tuo hard disk, cancella Windows!
Back to top
View user's profile Send private message
kaosone
Guru
Guru


Joined: 01 Feb 2004
Posts: 446

PostPosted: Mon Sep 06, 2004 8:00 pm    Post subject: Reply with quote

ls -R *.txt > /tmp/filetxt && ls -R > /tmp/altri && diff /tmp/filetxt /tmp/altri
Back to top
View user's profile Send private message
xchris
Advocate
Advocate


Joined: 10 Jul 2003
Posts: 2824

PostPosted: Mon Sep 06, 2004 8:08 pm    Post subject: Reply with quote

find /tuadir | grep -v ".mp3$"

un po' alla brutta :)

ciao
_________________
while True:Gentoo()
Back to top
View user's profile Send private message
lopio
Veteran
Veteran


Joined: 22 Dec 2003
Posts: 1161
Location: savona, Italy

PostPosted: Mon Sep 06, 2004 8:08 pm    Post subject: Reply with quote

forse conviene listare i file con ls (con qualche parametro magari) ed escludere le estensioni con grep
Code:

ls | grep -v  *.txt
Back to top
View user's profile Send private message
FonderiaDigitale
Veteran
Veteran


Joined: 06 Nov 2003
Posts: 1710
Location: Rome, Italy

PostPosted: Mon Sep 06, 2004 9:56 pm    Post subject: Reply with quote

tie, ho bashato per te.
lo si pone in ~/.bashrc
e lo si usa a codesta maniera, accodando quante directory e estensioni di file vuoi anche in ordine sparso, tipo:
Code:
inversematch /tmp mp3 wav /var txt ~

Code:

#!/bin/bash

inversematch()
{
local dir ext id ie prunelist
dir=()
ext=()
while [ $1 ]
do
      if [ -d $1 ]
      then
         id=${#dir[*]}
          dir[${id}]=$1
       else
          ie=${#ext[*]}
          ext[${ie}]=$1
       fi
       shift
done

if [ -z "${ext[*]}" ] || [ -z "${dir[*]}" ]
then
   echo "missing parameters"
   return 1
fi
for d in ${dir[*]}
do
   for e in ${ext[*]}
   do
      prunelist="${prunelist} -o -iname \*.${e} -prune"
   done
   find ${d} -maxdepth 1 -xdev -name \* ${prunelist}|sort
done
}


:roll:
_________________
Come disse un amico, i sistemisti sono un po' come gli artigiani per l'informatica :)
Back to top
View user's profile Send private message
Marculin
Guru
Guru


Joined: 24 Feb 2004
Posts: 376

PostPosted: Mon Sep 06, 2004 10:02 pm    Post subject: Reply with quote

@l'avevo anche pensata come kaosone ma la soluzione di lopio è molto sbrigativa e semplice ;)

@Fonderia grazie...ora me lo provo...ho visto che l'hai aggiunto mentre facevo il reply :p
_________________
Non capisco perchè continuavo ad avere cosi paura della shell.....è cosi bella :)
Back to top
View user's profile Send private message
Marculin
Guru
Guru


Joined: 24 Feb 2004
Posts: 376

PostPosted: Mon Sep 06, 2004 10:10 pm    Post subject: Reply with quote

@fonderia...mi sa che ci sono problemi....o ho ciccato la sintassi o mi fa un semplice "ls"
io dò
Code:

inversematch /dir mp3

e lui mi fa un semplice ls di tutti i file nella dir :(
_________________
Non capisco perchè continuavo ad avere cosi paura della shell.....è cosi bella :)
Back to top
View user's profile Send private message
FonderiaDigitale
Veteran
Veteran


Joined: 06 Nov 2003
Posts: 1710
Location: Rome, Italy

PostPosted: Mon Sep 06, 2004 10:12 pm    Post subject: Reply with quote

se sei nella stessa shell, ovvero non hai riaperto una nuova:
Code:
source ~/.bashrc

_________________
Come disse un amico, i sistemisti sono un po' come gli artigiani per l'informatica :)
Back to top
View user's profile Send private message
Marculin
Guru
Guru


Joined: 24 Feb 2004
Posts: 376

PostPosted: Mon Sep 06, 2004 10:15 pm    Post subject: Reply with quote

no no l'ho riaperta ovviamente....a te va?

EDIT:
Code:

inversematch prova/ mp3
prova/
prova/a.txt
prova/b.mp3
prova/g.mp3
prova/g.txt

oppure
Code:

inversematch /home/marco/prova/ mp3
/home/marco/prova/
/home/marco/prova/a.txt
/home/marco/prova/b.mp3
/home/marco/prova/g.mp3
/home/marco/prova/g.txt

_________________
Non capisco perchè continuavo ad avere cosi paura della shell.....è cosi bella :)


Last edited by Marculin on Mon Sep 06, 2004 10:18 pm; edited 1 time in total
Back to top
View user's profile Send private message
FonderiaDigitale
Veteran
Veteran


Joined: 06 Nov 2003
Posts: 1710
Location: Rome, Italy

PostPosted: Mon Sep 06, 2004 10:17 pm    Post subject: Reply with quote

nello script non c'e' neanche menzione a ls.. piuttosto a find.
quindi come faccia a uscirti un ls proprio non lo so.
_________________
Come disse un amico, i sistemisti sono un po' come gli artigiani per l'informatica :)
Back to top
View user's profile Send private message
xchris
Advocate
Advocate


Joined: 10 Jul 2003
Posts: 2824

PostPosted: Mon Sep 06, 2004 10:21 pm    Post subject: Reply with quote

un find senza argomenti riporta la dir corrente e le sottodir.
come un ls ma con il percorso relativo.
ciao
_________________
while True:Gentoo()
Back to top
View user's profile Send private message
Marculin
Guru
Guru


Joined: 24 Feb 2004
Posts: 376

PostPosted: Mon Sep 06, 2004 10:24 pm    Post subject: Reply with quote

xchris ha ragione....

@fonderia lo script probabilmente non capisce i parametri passati come estensioni
_________________
Non capisco perchè continuavo ad avere cosi paura della shell.....è cosi bella :)
Back to top
View user's profile Send private message
FonderiaDigitale
Veteran
Veteran


Joined: 06 Nov 2003
Posts: 1710
Location: Rome, Italy

PostPosted: Mon Sep 06, 2004 10:24 pm    Post subject: Reply with quote

gli argomenti ci dovrebbero essere e cmq c'e' un check a monte..
_________________
Come disse un amico, i sistemisti sono un po' come gli artigiani per l'informatica :)
Back to top
View user's profile Send private message
Marculin
Guru
Guru


Joined: 24 Feb 2004
Posts: 376

PostPosted: Mon Sep 06, 2004 10:34 pm    Post subject: Reply with quote

bo...proprio non mi va.....mi fa il find senza argomenti!
_________________
Non capisco perchè continuavo ad avere cosi paura della shell.....è cosi bella :)
Back to top
View user's profile Send private message
FonderiaDigitale
Veteran
Veteran


Joined: 06 Nov 2003
Posts: 1710
Location: Rome, Italy

PostPosted: Mon Sep 06, 2004 10:59 pm    Post subject: Reply with quote

devo avere fatto un errore stupido sulla sintassi del find.
prova questo
Code:
#!/bin/bash

inversematch()
{
local dir ext dim id ie d e prunelist
dir=()
ext=()
while [ $1 ]
do
      if [ -d $1 ]
      then
         id=${#dir[*]}
          dir[${id}]=$1
       else
          ie=${#ext[*]}
          ext[${ie}]=$1
       fi
       shift
done
if [ ${#ext[*]} -lt 1 ] || [ ${#dir[*]} -lt 1 ]
then
   echo "missing parameters"
   return 1
fi
for d in ${dir[*]}
do
   dim=${#ext[*]}
   if [ ${dim} -eq 1 ]
   then
      find ${d} -maxdepth 1 -xdev ! -name \*.${ext[*]}|sort
   else
      for ((a=0;a<dim;a++))
      do
         e=${ext[${a}]}
         if [ ${a} -eq 0 ]
         then
            prunelist="-iname \*.${e} -prune"
         else
            prunelist="${prunelist} -o -iname \*.${e} -prune"
         fi
      done
      find ${d} -maxdepth 1 -xdev ${prunelist} -o -name \* -print|sort

   fi
done
}

_________________
Come disse un amico, i sistemisti sono un po' come gli artigiani per l'informatica :)
Back to top
View user's profile Send private message
pascalbrax
Apprentice
Apprentice


Joined: 21 Jan 2004
Posts: 280
Location: 127.0.0.1

PostPosted: Tue Sep 07, 2004 6:56 am    Post subject: Reply with quote

ci provo anche io a partecipare a questo "contest" improvvisato, sono solo un principiante in confronto a voi, ma voglio provare a dare un piccolo contributo :D

unfind
Code:
#!/bin/bash
#
# pascal brax ;)

TOOL="ls -lh"
#TOOL="find"

if [ $1 ]; then
        $TOOL | grep -v $1
else
        printf "USAGE:\nunfind pattern\n"
fi


basta modificare il TOOL nelle prime righe per usare ls o find
_________________
"One World, One web, One program" - Microsoft Promo ad.
"Ein Volk, Ein Reich, Ein Führer" - Adolf Hitler
Back to top
View user's profile Send private message
randomaze
Bodhisattva
Bodhisattva


Joined: 21 Oct 2003
Posts: 9985

PostPosted: Tue Sep 07, 2004 8:39 am    Post subject: Reply with quote

Code:
find . -not -name "*.mp3"


:roll:
_________________
Ciao da me!
Back to top
View user's profile Send private message
xchris
Advocate
Advocate


Joined: 10 Jul 2003
Posts: 2824

PostPosted: Tue Sep 07, 2004 8:43 am    Post subject: Reply with quote

mittico :D
_________________
while True:Gentoo()
Back to top
View user's profile Send private message
pascalbrax
Apprentice
Apprentice


Joined: 21 Jan 2004
Posts: 280
Location: 127.0.0.1

PostPosted: Tue Sep 07, 2004 9:06 am    Post subject: Reply with quote

Code:
alias unfind=find -not -name

toh! :P
_________________
"One World, One web, One program" - Microsoft Promo ad.
"Ein Volk, Ein Reich, Ein Führer" - Adolf Hitler
Back to top
View user's profile Send private message
Marculin
Guru
Guru


Joined: 24 Feb 2004
Posts: 376

PostPosted: Thu Sep 09, 2004 11:52 am    Post subject: Reply with quote

Grazie....proverò ancora quello di fonderia visto che si è sbattuto ma randomaze ha trovato il miglior metodo credo ;) grazie a tutti..
_________________
Non capisco perchè continuavo ad avere cosi paura della shell.....è cosi bella :)
Back to top
View user's profile Send private message
FonderiaDigitale
Veteran
Veteran


Joined: 06 Nov 2003
Posts: 1710
Location: Rome, Italy

PostPosted: Thu Sep 09, 2004 11:59 am    Post subject: Reply with quote

in realta' il mio e' esattamente quello che fa quello di randomaze, per N pacchetti e per N pattern :)
_________________
Come disse un amico, i sistemisti sono un po' come gli artigiani per l'informatica :)
Back to top
View user's profile Send private message
Marculin
Guru
Guru


Joined: 24 Feb 2004
Posts: 376

PostPosted: Thu Sep 09, 2004 12:00 pm    Post subject: Reply with quote

Ancora una cosa: è possibile escludere i nomi delle sottocartelle dall'elenco che mi esce con
Code:
find . -not -name "*.mp3"
?
Nel man del find non l'ho trovato..grazie
_________________
Non capisco perchè continuavo ad avere cosi paura della shell.....è cosi bella :)
Back to top
View user's profile Send private message
Marculin
Guru
Guru


Joined: 24 Feb 2004
Posts: 376

PostPosted: Thu Sep 09, 2004 12:10 pm    Post subject: Reply with quote

bastava aggiungere
Code:
-not -type d
come da man :?
_________________
Non capisco perchè continuavo ad avere cosi paura della shell.....è cosi bella :)
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Forum italiano (Italian) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum