Use the FIND command non-recursively
Solved
Hello,
does anyone know how to use the find command without descending into the directory tree?
does anyone know how to use the find command without descending into the directory tree?
7 answers
-
ModeratorYou use the option -maxdepth
find . -name '*.c' -maxdepth 1 -type f
--> all the files in the current directory.
Johan
Gates vous a donné les fenêtres.
GNU nous a donné toute la maison. -
I bring up the subject from his grave in case someone comes across it during a search.
In fact, there is a solution with prune:
find . \( -type d ! -name . -prune \) -o -type f -print
1) We indicate that directories that are not called "." are not traversed
2) We request the display of files-
-
-
And otherwise, under AIX, you just need to use the ls command without filters (the limitation of ls only appears with filters).
So ls -1 | grep TOTO to filter all files in the current directory that contain "TOTO"
or ls -1 | awk '/^TOTO.*$/' to filter all files in the current directory that start with TOTO (etc...)
=> no recursion
to delete (example with all files starting with TOTO:
ls -1 | awk '/^TOTO.*$/{system("rm -f " $0)}' -
-
-
-
ben fais un man find pour plus d'infos su la commande find de linux.
find dossier_ds_lequel_tu_cherches -name nom_du_fichier_a_chercher
Bahan
Close the world.||.txen eht nepO -
Hello
I have the same question but for AIX/Solaris/etc, that is to say not Linux!
-[min/max]depth does not exist.
Personally, I think it's impossible, but someone might have another opinion? -
oh, with some | and ls we should be able to make it, right?
-
No, no, we can or we can't, but we must know that it only works under Linux, that's it.
In principle, we should close this subject and consider it resolved. -
For AIX/Solaris/etc you can use -prune
(I just saw that the answer has already been given..)