find . * -exec ll ; -> with just one result instead of four

Multi tool use
Clash Royale CLAN TAG#URR8PPP
up vote
2
down vote
favorite
I'd like to use find command to search all files in one directory:
find . * -exec ll ;
Result shows four (!) results per file:
file123
./test/file123
file123
test/file123
Is it possible to show just the second result ./test/file123
using find-out-of-the-box-command (so without using things like | grep '^./'
)?
I'm using latest version of HP/UX.
find exec hp-ux
add a comment |Â
up vote
2
down vote
favorite
I'd like to use find command to search all files in one directory:
find . * -exec ll ;
Result shows four (!) results per file:
file123
./test/file123
file123
test/file123
Is it possible to show just the second result ./test/file123
using find-out-of-the-box-command (so without using things like | grep '^./'
)?
I'm using latest version of HP/UX.
find exec hp-ux
2
Where do you have this command from? just usefind .
- or just -ll
. The difference is thatfind
will find files recursively. Also note. Don't usell
in scripts!ll
is just an alias (In Ubuntu it meansls -alFh
). This is not portable in any ways.
– RoVo
Sep 10 at 9:10
add a comment |Â
up vote
2
down vote
favorite
up vote
2
down vote
favorite
I'd like to use find command to search all files in one directory:
find . * -exec ll ;
Result shows four (!) results per file:
file123
./test/file123
file123
test/file123
Is it possible to show just the second result ./test/file123
using find-out-of-the-box-command (so without using things like | grep '^./'
)?
I'm using latest version of HP/UX.
find exec hp-ux
I'd like to use find command to search all files in one directory:
find . * -exec ll ;
Result shows four (!) results per file:
file123
./test/file123
file123
test/file123
Is it possible to show just the second result ./test/file123
using find-out-of-the-box-command (so without using things like | grep '^./'
)?
I'm using latest version of HP/UX.
find exec hp-ux
find exec hp-ux
edited Sep 10 at 12:28
Rui F Ribeiro
36.7k1271117
36.7k1271117
asked Sep 10 at 9:00
MyUserName
111
111
2
Where do you have this command from? just usefind .
- or just -ll
. The difference is thatfind
will find files recursively. Also note. Don't usell
in scripts!ll
is just an alias (In Ubuntu it meansls -alFh
). This is not portable in any ways.
– RoVo
Sep 10 at 9:10
add a comment |Â
2
Where do you have this command from? just usefind .
- or just -ll
. The difference is thatfind
will find files recursively. Also note. Don't usell
in scripts!ll
is just an alias (In Ubuntu it meansls -alFh
). This is not portable in any ways.
– RoVo
Sep 10 at 9:10
2
2
Where do you have this command from? just use
find .
- or just - ll
. The difference is that find
will find files recursively. Also note. Don't use ll
in scripts! ll
is just an alias (In Ubuntu it means ls -alFh
). This is not portable in any ways.– RoVo
Sep 10 at 9:10
Where do you have this command from? just use
find .
- or just - ll
. The difference is that find
will find files recursively. Also note. Don't use ll
in scripts! ll
is just an alias (In Ubuntu it means ls -alFh
). This is not portable in any ways.– RoVo
Sep 10 at 9:10
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
5
down vote
find . * -exec ll ;
Passes .
, and the list of non-hidden files in the current directory (expanded from *
by the shell), including the test
subdirectory (and if any of those files started with -
or if there was a file called !
or (
, )
... that would cause find
to report a syntax error).
So you're telling find
to look for files recursively in .
, but also in test
. So find
will find test
twice and also test/file123
twice.
ll
which I suppose is a script that does ls -l
is a tool to list details of files or for files of type directory, the details of all the files in that directory (unless you pass the -d
option).
So ll
will be called with ./test
and test
as arguments in which cases if will list the details of the files in its content (including test/file
).
And it will be called with ./test/file123
and test/file123
.
Here, you'd want:
find . -exec ls -ld +
(using +
means that more than one file will be passed as arguments to ls
which is more efficient and also lets ls
sort that list of files).
Your find
may even support a -ls
predicate which behaves a bit list ls -lsid
:
find . -ls
I never usefind .
myself because this is redundant. find will always search in the current directory if the directory is unspecified.
– Fox
Sep 10 at 13:48
2
@Fox, that's a GNU extension. Manyfind
implementations (including the original one as probably found on the OP's HPUX) require at least one file. The POSIXfind
specification does as well.
– Stéphane Chazelas
Sep 10 at 13:54
Thank you! I learned something. :)
– Fox
Sep 10 at 14:07
add a comment |Â
up vote
5
down vote
You are getting four lines of output because you you ask find
to search the current directory (.
) as well as everything that *
expands to.
For the current directory, find
will proceed to invoke ll
on the things that it finds, which will be the current directory, the test
directory and the file in the test
directory. This lists file123
twice.
It will then search everything that *
expands to, which will be the test
directory. Now it will use ll
on test
again and on the file within. This lists your file twice again.
Instead, if you're looking for a regular file, use -type f
. And you don't have to use ll
(or ls
) to get the results from find
as it will list the found pathnames by default. Also, just give find
the current directory (or test
) as the search path:
find . -type f
If you know that you are looking for a file with the exact name file123
:
find . -type f -name 'file123'
If you want ls -l
-like output rather than a pathname:
find . -type f -name 'file123' -ls
If you want to limit the results to files within those top-level directories, like "test", you might consider using the-maxdepth
and-mindepth
option as well. In this case:-mindepth 2
and-maxdepth 2
.
– Todd Walton
Sep 10 at 15:32
@ToddWalton, that's a GNU extension, now supported by a few other implementations but I doubt HPUX's is one of those. See also the better-depth 2
with NetBSDfind
. See delete folders older than 1 day for instance for a POSIX equivalent
– Stéphane Chazelas
Sep 10 at 18:00
add a comment |Â
up vote
0
down vote
Please note that find
will search recursively in all the directories.
Find will return not only files, but also directories!
If you want to list all files within the test directory, all you need is the following command:find test/ -type f
Also, I don't know what you are trying to achieve, but check your find
manpage... You are using -exec ll ;
and I suspect there's probably a find
option that will do what you need (filter files by size, modification date, etc.)
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
5
down vote
find . * -exec ll ;
Passes .
, and the list of non-hidden files in the current directory (expanded from *
by the shell), including the test
subdirectory (and if any of those files started with -
or if there was a file called !
or (
, )
... that would cause find
to report a syntax error).
So you're telling find
to look for files recursively in .
, but also in test
. So find
will find test
twice and also test/file123
twice.
ll
which I suppose is a script that does ls -l
is a tool to list details of files or for files of type directory, the details of all the files in that directory (unless you pass the -d
option).
So ll
will be called with ./test
and test
as arguments in which cases if will list the details of the files in its content (including test/file
).
And it will be called with ./test/file123
and test/file123
.
Here, you'd want:
find . -exec ls -ld +
(using +
means that more than one file will be passed as arguments to ls
which is more efficient and also lets ls
sort that list of files).
Your find
may even support a -ls
predicate which behaves a bit list ls -lsid
:
find . -ls
I never usefind .
myself because this is redundant. find will always search in the current directory if the directory is unspecified.
– Fox
Sep 10 at 13:48
2
@Fox, that's a GNU extension. Manyfind
implementations (including the original one as probably found on the OP's HPUX) require at least one file. The POSIXfind
specification does as well.
– Stéphane Chazelas
Sep 10 at 13:54
Thank you! I learned something. :)
– Fox
Sep 10 at 14:07
add a comment |Â
up vote
5
down vote
find . * -exec ll ;
Passes .
, and the list of non-hidden files in the current directory (expanded from *
by the shell), including the test
subdirectory (and if any of those files started with -
or if there was a file called !
or (
, )
... that would cause find
to report a syntax error).
So you're telling find
to look for files recursively in .
, but also in test
. So find
will find test
twice and also test/file123
twice.
ll
which I suppose is a script that does ls -l
is a tool to list details of files or for files of type directory, the details of all the files in that directory (unless you pass the -d
option).
So ll
will be called with ./test
and test
as arguments in which cases if will list the details of the files in its content (including test/file
).
And it will be called with ./test/file123
and test/file123
.
Here, you'd want:
find . -exec ls -ld +
(using +
means that more than one file will be passed as arguments to ls
which is more efficient and also lets ls
sort that list of files).
Your find
may even support a -ls
predicate which behaves a bit list ls -lsid
:
find . -ls
I never usefind .
myself because this is redundant. find will always search in the current directory if the directory is unspecified.
– Fox
Sep 10 at 13:48
2
@Fox, that's a GNU extension. Manyfind
implementations (including the original one as probably found on the OP's HPUX) require at least one file. The POSIXfind
specification does as well.
– Stéphane Chazelas
Sep 10 at 13:54
Thank you! I learned something. :)
– Fox
Sep 10 at 14:07
add a comment |Â
up vote
5
down vote
up vote
5
down vote
find . * -exec ll ;
Passes .
, and the list of non-hidden files in the current directory (expanded from *
by the shell), including the test
subdirectory (and if any of those files started with -
or if there was a file called !
or (
, )
... that would cause find
to report a syntax error).
So you're telling find
to look for files recursively in .
, but also in test
. So find
will find test
twice and also test/file123
twice.
ll
which I suppose is a script that does ls -l
is a tool to list details of files or for files of type directory, the details of all the files in that directory (unless you pass the -d
option).
So ll
will be called with ./test
and test
as arguments in which cases if will list the details of the files in its content (including test/file
).
And it will be called with ./test/file123
and test/file123
.
Here, you'd want:
find . -exec ls -ld +
(using +
means that more than one file will be passed as arguments to ls
which is more efficient and also lets ls
sort that list of files).
Your find
may even support a -ls
predicate which behaves a bit list ls -lsid
:
find . -ls
find . * -exec ll ;
Passes .
, and the list of non-hidden files in the current directory (expanded from *
by the shell), including the test
subdirectory (and if any of those files started with -
or if there was a file called !
or (
, )
... that would cause find
to report a syntax error).
So you're telling find
to look for files recursively in .
, but also in test
. So find
will find test
twice and also test/file123
twice.
ll
which I suppose is a script that does ls -l
is a tool to list details of files or for files of type directory, the details of all the files in that directory (unless you pass the -d
option).
So ll
will be called with ./test
and test
as arguments in which cases if will list the details of the files in its content (including test/file
).
And it will be called with ./test/file123
and test/file123
.
Here, you'd want:
find . -exec ls -ld +
(using +
means that more than one file will be passed as arguments to ls
which is more efficient and also lets ls
sort that list of files).
Your find
may even support a -ls
predicate which behaves a bit list ls -lsid
:
find . -ls
answered Sep 10 at 9:13


Stéphane Chazelas
285k53525864
285k53525864
I never usefind .
myself because this is redundant. find will always search in the current directory if the directory is unspecified.
– Fox
Sep 10 at 13:48
2
@Fox, that's a GNU extension. Manyfind
implementations (including the original one as probably found on the OP's HPUX) require at least one file. The POSIXfind
specification does as well.
– Stéphane Chazelas
Sep 10 at 13:54
Thank you! I learned something. :)
– Fox
Sep 10 at 14:07
add a comment |Â
I never usefind .
myself because this is redundant. find will always search in the current directory if the directory is unspecified.
– Fox
Sep 10 at 13:48
2
@Fox, that's a GNU extension. Manyfind
implementations (including the original one as probably found on the OP's HPUX) require at least one file. The POSIXfind
specification does as well.
– Stéphane Chazelas
Sep 10 at 13:54
Thank you! I learned something. :)
– Fox
Sep 10 at 14:07
I never use
find .
myself because this is redundant. find will always search in the current directory if the directory is unspecified.– Fox
Sep 10 at 13:48
I never use
find .
myself because this is redundant. find will always search in the current directory if the directory is unspecified.– Fox
Sep 10 at 13:48
2
2
@Fox, that's a GNU extension. Many
find
implementations (including the original one as probably found on the OP's HPUX) require at least one file. The POSIX find
specification does as well.– Stéphane Chazelas
Sep 10 at 13:54
@Fox, that's a GNU extension. Many
find
implementations (including the original one as probably found on the OP's HPUX) require at least one file. The POSIX find
specification does as well.– Stéphane Chazelas
Sep 10 at 13:54
Thank you! I learned something. :)
– Fox
Sep 10 at 14:07
Thank you! I learned something. :)
– Fox
Sep 10 at 14:07
add a comment |Â
up vote
5
down vote
You are getting four lines of output because you you ask find
to search the current directory (.
) as well as everything that *
expands to.
For the current directory, find
will proceed to invoke ll
on the things that it finds, which will be the current directory, the test
directory and the file in the test
directory. This lists file123
twice.
It will then search everything that *
expands to, which will be the test
directory. Now it will use ll
on test
again and on the file within. This lists your file twice again.
Instead, if you're looking for a regular file, use -type f
. And you don't have to use ll
(or ls
) to get the results from find
as it will list the found pathnames by default. Also, just give find
the current directory (or test
) as the search path:
find . -type f
If you know that you are looking for a file with the exact name file123
:
find . -type f -name 'file123'
If you want ls -l
-like output rather than a pathname:
find . -type f -name 'file123' -ls
If you want to limit the results to files within those top-level directories, like "test", you might consider using the-maxdepth
and-mindepth
option as well. In this case:-mindepth 2
and-maxdepth 2
.
– Todd Walton
Sep 10 at 15:32
@ToddWalton, that's a GNU extension, now supported by a few other implementations but I doubt HPUX's is one of those. See also the better-depth 2
with NetBSDfind
. See delete folders older than 1 day for instance for a POSIX equivalent
– Stéphane Chazelas
Sep 10 at 18:00
add a comment |Â
up vote
5
down vote
You are getting four lines of output because you you ask find
to search the current directory (.
) as well as everything that *
expands to.
For the current directory, find
will proceed to invoke ll
on the things that it finds, which will be the current directory, the test
directory and the file in the test
directory. This lists file123
twice.
It will then search everything that *
expands to, which will be the test
directory. Now it will use ll
on test
again and on the file within. This lists your file twice again.
Instead, if you're looking for a regular file, use -type f
. And you don't have to use ll
(or ls
) to get the results from find
as it will list the found pathnames by default. Also, just give find
the current directory (or test
) as the search path:
find . -type f
If you know that you are looking for a file with the exact name file123
:
find . -type f -name 'file123'
If you want ls -l
-like output rather than a pathname:
find . -type f -name 'file123' -ls
If you want to limit the results to files within those top-level directories, like "test", you might consider using the-maxdepth
and-mindepth
option as well. In this case:-mindepth 2
and-maxdepth 2
.
– Todd Walton
Sep 10 at 15:32
@ToddWalton, that's a GNU extension, now supported by a few other implementations but I doubt HPUX's is one of those. See also the better-depth 2
with NetBSDfind
. See delete folders older than 1 day for instance for a POSIX equivalent
– Stéphane Chazelas
Sep 10 at 18:00
add a comment |Â
up vote
5
down vote
up vote
5
down vote
You are getting four lines of output because you you ask find
to search the current directory (.
) as well as everything that *
expands to.
For the current directory, find
will proceed to invoke ll
on the things that it finds, which will be the current directory, the test
directory and the file in the test
directory. This lists file123
twice.
It will then search everything that *
expands to, which will be the test
directory. Now it will use ll
on test
again and on the file within. This lists your file twice again.
Instead, if you're looking for a regular file, use -type f
. And you don't have to use ll
(or ls
) to get the results from find
as it will list the found pathnames by default. Also, just give find
the current directory (or test
) as the search path:
find . -type f
If you know that you are looking for a file with the exact name file123
:
find . -type f -name 'file123'
If you want ls -l
-like output rather than a pathname:
find . -type f -name 'file123' -ls
You are getting four lines of output because you you ask find
to search the current directory (.
) as well as everything that *
expands to.
For the current directory, find
will proceed to invoke ll
on the things that it finds, which will be the current directory, the test
directory and the file in the test
directory. This lists file123
twice.
It will then search everything that *
expands to, which will be the test
directory. Now it will use ll
on test
again and on the file within. This lists your file twice again.
Instead, if you're looking for a regular file, use -type f
. And you don't have to use ll
(or ls
) to get the results from find
as it will list the found pathnames by default. Also, just give find
the current directory (or test
) as the search path:
find . -type f
If you know that you are looking for a file with the exact name file123
:
find . -type f -name 'file123'
If you want ls -l
-like output rather than a pathname:
find . -type f -name 'file123' -ls
edited Sep 10 at 11:46
answered Sep 10 at 9:10


Kusalananda
107k14209329
107k14209329
If you want to limit the results to files within those top-level directories, like "test", you might consider using the-maxdepth
and-mindepth
option as well. In this case:-mindepth 2
and-maxdepth 2
.
– Todd Walton
Sep 10 at 15:32
@ToddWalton, that's a GNU extension, now supported by a few other implementations but I doubt HPUX's is one of those. See also the better-depth 2
with NetBSDfind
. See delete folders older than 1 day for instance for a POSIX equivalent
– Stéphane Chazelas
Sep 10 at 18:00
add a comment |Â
If you want to limit the results to files within those top-level directories, like "test", you might consider using the-maxdepth
and-mindepth
option as well. In this case:-mindepth 2
and-maxdepth 2
.
– Todd Walton
Sep 10 at 15:32
@ToddWalton, that's a GNU extension, now supported by a few other implementations but I doubt HPUX's is one of those. See also the better-depth 2
with NetBSDfind
. See delete folders older than 1 day for instance for a POSIX equivalent
– Stéphane Chazelas
Sep 10 at 18:00
If you want to limit the results to files within those top-level directories, like "test", you might consider using the
-maxdepth
and -mindepth
option as well. In this case: -mindepth 2
and -maxdepth 2
.– Todd Walton
Sep 10 at 15:32
If you want to limit the results to files within those top-level directories, like "test", you might consider using the
-maxdepth
and -mindepth
option as well. In this case: -mindepth 2
and -maxdepth 2
.– Todd Walton
Sep 10 at 15:32
@ToddWalton, that's a GNU extension, now supported by a few other implementations but I doubt HPUX's is one of those. See also the better
-depth 2
with NetBSD find
. See delete folders older than 1 day for instance for a POSIX equivalent– Stéphane Chazelas
Sep 10 at 18:00
@ToddWalton, that's a GNU extension, now supported by a few other implementations but I doubt HPUX's is one of those. See also the better
-depth 2
with NetBSD find
. See delete folders older than 1 day for instance for a POSIX equivalent– Stéphane Chazelas
Sep 10 at 18:00
add a comment |Â
up vote
0
down vote
Please note that find
will search recursively in all the directories.
Find will return not only files, but also directories!
If you want to list all files within the test directory, all you need is the following command:find test/ -type f
Also, I don't know what you are trying to achieve, but check your find
manpage... You are using -exec ll ;
and I suspect there's probably a find
option that will do what you need (filter files by size, modification date, etc.)
add a comment |Â
up vote
0
down vote
Please note that find
will search recursively in all the directories.
Find will return not only files, but also directories!
If you want to list all files within the test directory, all you need is the following command:find test/ -type f
Also, I don't know what you are trying to achieve, but check your find
manpage... You are using -exec ll ;
and I suspect there's probably a find
option that will do what you need (filter files by size, modification date, etc.)
add a comment |Â
up vote
0
down vote
up vote
0
down vote
Please note that find
will search recursively in all the directories.
Find will return not only files, but also directories!
If you want to list all files within the test directory, all you need is the following command:find test/ -type f
Also, I don't know what you are trying to achieve, but check your find
manpage... You are using -exec ll ;
and I suspect there's probably a find
option that will do what you need (filter files by size, modification date, etc.)
Please note that find
will search recursively in all the directories.
Find will return not only files, but also directories!
If you want to list all files within the test directory, all you need is the following command:find test/ -type f
Also, I don't know what you are trying to achieve, but check your find
manpage... You are using -exec ll ;
and I suspect there's probably a find
option that will do what you need (filter files by size, modification date, etc.)
answered Sep 10 at 9:44
pi0tr
1202
1202
add a comment |Â
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f467988%2ffind-exec-ll-with-just-one-result-instead-of-four%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
2
Where do you have this command from? just use
find .
- or just -ll
. The difference is thatfind
will find files recursively. Also note. Don't usell
in scripts!ll
is just an alias (In Ubuntu it meansls -alFh
). This is not portable in any ways.– RoVo
Sep 10 at 9:10