Using find, how to classify like ls -F ? (directories with a trailing slash)
I use find
to get a list of files, then I grep it to do a path matching :
$ find pc* | grep -i arthur
pc6/arthurv/untitled-2.py
pc6/arthurv/untitled-3.py
pc6/arthur.py
pc9/Arthur 4C
pc9/Arthur 4C/untitled-1.py
pc9/Arthur 4C/untitled-2.py
I would like to do like in ls -F
and append a /
for each directory.
Alternatively, how do I get find to show all directories matching case insensitive arthur
?
bash grep find
add a comment |
I use find
to get a list of files, then I grep it to do a path matching :
$ find pc* | grep -i arthur
pc6/arthurv/untitled-2.py
pc6/arthurv/untitled-3.py
pc6/arthur.py
pc9/Arthur 4C
pc9/Arthur 4C/untitled-1.py
pc9/Arthur 4C/untitled-2.py
I would like to do like in ls -F
and append a /
for each directory.
Alternatively, how do I get find to show all directories matching case insensitive arthur
?
bash grep find
Related: How to use wc and piping to find how many files and directories are in a certain directory?
– Stéphane Chazelas
Dec 19 '18 at 9:06
add a comment |
I use find
to get a list of files, then I grep it to do a path matching :
$ find pc* | grep -i arthur
pc6/arthurv/untitled-2.py
pc6/arthurv/untitled-3.py
pc6/arthur.py
pc9/Arthur 4C
pc9/Arthur 4C/untitled-1.py
pc9/Arthur 4C/untitled-2.py
I would like to do like in ls -F
and append a /
for each directory.
Alternatively, how do I get find to show all directories matching case insensitive arthur
?
bash grep find
I use find
to get a list of files, then I grep it to do a path matching :
$ find pc* | grep -i arthur
pc6/arthurv/untitled-2.py
pc6/arthurv/untitled-3.py
pc6/arthur.py
pc9/Arthur 4C
pc9/Arthur 4C/untitled-1.py
pc9/Arthur 4C/untitled-2.py
I would like to do like in ls -F
and append a /
for each directory.
Alternatively, how do I get find to show all directories matching case insensitive arthur
?
bash grep find
bash grep find
asked Dec 19 '18 at 8:27
Robert Vanden Eynde
155
155
Related: How to use wc and piping to find how many files and directories are in a certain directory?
– Stéphane Chazelas
Dec 19 '18 at 9:06
add a comment |
Related: How to use wc and piping to find how many files and directories are in a certain directory?
– Stéphane Chazelas
Dec 19 '18 at 9:06
Related: How to use wc and piping to find how many files and directories are in a certain directory?
– Stéphane Chazelas
Dec 19 '18 at 9:06
Related: How to use wc and piping to find how many files and directories are in a certain directory?
– Stéphane Chazelas
Dec 19 '18 at 9:06
add a comment |
2 Answers
2
active
oldest
votes
You can use disjunctions in find
expressions to implement conditional processing; with GNU find
:
find pc* -type d -printf "%p/n" -o -print
will find everything in paths starting with the files and directories matching “pc*”, and print their names, followed by a “/” if they’re directories.
The way this works is as follows:
pc*
specifies the paths to start from;
-type d
matches directories;
-printf "%p/n"
prints the path to the currently-processed file, followed by “/” and a newline; because it follows-type d
, it is only executed if-type d
matched (there’s an implicit conjunction);
-o
introduces a disjunction: the expression following it will be evaluated if the expression preceding it did not match (and the expression preceding it is-type d -printf "%p/n"
here, because conjunctions have higher precedence than disjunctions);
-print
prints the path to the currently-processed file.
Showing all directories matching case-insensitive “arthur” can be done using other find
expressions:
find . -type d -iname "*arthur*"
Exactly what I was looking for, however I understand easily the second code and the third but not the first one, I would put it last and explain more in details.
– Robert Vanden Eynde
Dec 19 '18 at 8:53
You removerd the versionfind pc* ( -type d -printf "%p/n" ) -o ( ! -type d -print )
, just curious about what the parenthesis and the!
meant ? :)
– Robert Vanden Eynde
Dec 22 '18 at 21:13
1
The parentheses group expressions, and!
negates an expression. So( -type d -printf "%p/n" ) -o ( ! -type d -print )
tellsfind
to consider-type d -printf "%p/n"
on the one hand, and! -type d -print
on the other; and! -type d
matches anything which isn’t a directory.
– Stephen Kitt
Dec 22 '18 at 21:25
add a comment |
find
has a huge amount of options and details. Another variant is to use printf with %y
$ find . -printf "%p:%yn"
./dir:d
./file:f
where %y
adds a "d" or a "f" just like ls -l
$ find . -printf "%p%yn" | sed 's!d$!/! ; s!f$!!'
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f489857%2fusing-find-how-to-classify-like-ls-f-directories-with-a-trailing-slash%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use disjunctions in find
expressions to implement conditional processing; with GNU find
:
find pc* -type d -printf "%p/n" -o -print
will find everything in paths starting with the files and directories matching “pc*”, and print their names, followed by a “/” if they’re directories.
The way this works is as follows:
pc*
specifies the paths to start from;
-type d
matches directories;
-printf "%p/n"
prints the path to the currently-processed file, followed by “/” and a newline; because it follows-type d
, it is only executed if-type d
matched (there’s an implicit conjunction);
-o
introduces a disjunction: the expression following it will be evaluated if the expression preceding it did not match (and the expression preceding it is-type d -printf "%p/n"
here, because conjunctions have higher precedence than disjunctions);
-print
prints the path to the currently-processed file.
Showing all directories matching case-insensitive “arthur” can be done using other find
expressions:
find . -type d -iname "*arthur*"
Exactly what I was looking for, however I understand easily the second code and the third but not the first one, I would put it last and explain more in details.
– Robert Vanden Eynde
Dec 19 '18 at 8:53
You removerd the versionfind pc* ( -type d -printf "%p/n" ) -o ( ! -type d -print )
, just curious about what the parenthesis and the!
meant ? :)
– Robert Vanden Eynde
Dec 22 '18 at 21:13
1
The parentheses group expressions, and!
negates an expression. So( -type d -printf "%p/n" ) -o ( ! -type d -print )
tellsfind
to consider-type d -printf "%p/n"
on the one hand, and! -type d -print
on the other; and! -type d
matches anything which isn’t a directory.
– Stephen Kitt
Dec 22 '18 at 21:25
add a comment |
You can use disjunctions in find
expressions to implement conditional processing; with GNU find
:
find pc* -type d -printf "%p/n" -o -print
will find everything in paths starting with the files and directories matching “pc*”, and print their names, followed by a “/” if they’re directories.
The way this works is as follows:
pc*
specifies the paths to start from;
-type d
matches directories;
-printf "%p/n"
prints the path to the currently-processed file, followed by “/” and a newline; because it follows-type d
, it is only executed if-type d
matched (there’s an implicit conjunction);
-o
introduces a disjunction: the expression following it will be evaluated if the expression preceding it did not match (and the expression preceding it is-type d -printf "%p/n"
here, because conjunctions have higher precedence than disjunctions);
-print
prints the path to the currently-processed file.
Showing all directories matching case-insensitive “arthur” can be done using other find
expressions:
find . -type d -iname "*arthur*"
Exactly what I was looking for, however I understand easily the second code and the third but not the first one, I would put it last and explain more in details.
– Robert Vanden Eynde
Dec 19 '18 at 8:53
You removerd the versionfind pc* ( -type d -printf "%p/n" ) -o ( ! -type d -print )
, just curious about what the parenthesis and the!
meant ? :)
– Robert Vanden Eynde
Dec 22 '18 at 21:13
1
The parentheses group expressions, and!
negates an expression. So( -type d -printf "%p/n" ) -o ( ! -type d -print )
tellsfind
to consider-type d -printf "%p/n"
on the one hand, and! -type d -print
on the other; and! -type d
matches anything which isn’t a directory.
– Stephen Kitt
Dec 22 '18 at 21:25
add a comment |
You can use disjunctions in find
expressions to implement conditional processing; with GNU find
:
find pc* -type d -printf "%p/n" -o -print
will find everything in paths starting with the files and directories matching “pc*”, and print their names, followed by a “/” if they’re directories.
The way this works is as follows:
pc*
specifies the paths to start from;
-type d
matches directories;
-printf "%p/n"
prints the path to the currently-processed file, followed by “/” and a newline; because it follows-type d
, it is only executed if-type d
matched (there’s an implicit conjunction);
-o
introduces a disjunction: the expression following it will be evaluated if the expression preceding it did not match (and the expression preceding it is-type d -printf "%p/n"
here, because conjunctions have higher precedence than disjunctions);
-print
prints the path to the currently-processed file.
Showing all directories matching case-insensitive “arthur” can be done using other find
expressions:
find . -type d -iname "*arthur*"
You can use disjunctions in find
expressions to implement conditional processing; with GNU find
:
find pc* -type d -printf "%p/n" -o -print
will find everything in paths starting with the files and directories matching “pc*”, and print their names, followed by a “/” if they’re directories.
The way this works is as follows:
pc*
specifies the paths to start from;
-type d
matches directories;
-printf "%p/n"
prints the path to the currently-processed file, followed by “/” and a newline; because it follows-type d
, it is only executed if-type d
matched (there’s an implicit conjunction);
-o
introduces a disjunction: the expression following it will be evaluated if the expression preceding it did not match (and the expression preceding it is-type d -printf "%p/n"
here, because conjunctions have higher precedence than disjunctions);
-print
prints the path to the currently-processed file.
Showing all directories matching case-insensitive “arthur” can be done using other find
expressions:
find . -type d -iname "*arthur*"
edited Dec 19 '18 at 9:03
answered Dec 19 '18 at 8:31
Stephen Kitt
164k24365444
164k24365444
Exactly what I was looking for, however I understand easily the second code and the third but not the first one, I would put it last and explain more in details.
– Robert Vanden Eynde
Dec 19 '18 at 8:53
You removerd the versionfind pc* ( -type d -printf "%p/n" ) -o ( ! -type d -print )
, just curious about what the parenthesis and the!
meant ? :)
– Robert Vanden Eynde
Dec 22 '18 at 21:13
1
The parentheses group expressions, and!
negates an expression. So( -type d -printf "%p/n" ) -o ( ! -type d -print )
tellsfind
to consider-type d -printf "%p/n"
on the one hand, and! -type d -print
on the other; and! -type d
matches anything which isn’t a directory.
– Stephen Kitt
Dec 22 '18 at 21:25
add a comment |
Exactly what I was looking for, however I understand easily the second code and the third but not the first one, I would put it last and explain more in details.
– Robert Vanden Eynde
Dec 19 '18 at 8:53
You removerd the versionfind pc* ( -type d -printf "%p/n" ) -o ( ! -type d -print )
, just curious about what the parenthesis and the!
meant ? :)
– Robert Vanden Eynde
Dec 22 '18 at 21:13
1
The parentheses group expressions, and!
negates an expression. So( -type d -printf "%p/n" ) -o ( ! -type d -print )
tellsfind
to consider-type d -printf "%p/n"
on the one hand, and! -type d -print
on the other; and! -type d
matches anything which isn’t a directory.
– Stephen Kitt
Dec 22 '18 at 21:25
Exactly what I was looking for, however I understand easily the second code and the third but not the first one, I would put it last and explain more in details.
– Robert Vanden Eynde
Dec 19 '18 at 8:53
Exactly what I was looking for, however I understand easily the second code and the third but not the first one, I would put it last and explain more in details.
– Robert Vanden Eynde
Dec 19 '18 at 8:53
You removerd the version
find pc* ( -type d -printf "%p/n" ) -o ( ! -type d -print )
, just curious about what the parenthesis and the !
meant ? :)– Robert Vanden Eynde
Dec 22 '18 at 21:13
You removerd the version
find pc* ( -type d -printf "%p/n" ) -o ( ! -type d -print )
, just curious about what the parenthesis and the !
meant ? :)– Robert Vanden Eynde
Dec 22 '18 at 21:13
1
1
The parentheses group expressions, and
!
negates an expression. So ( -type d -printf "%p/n" ) -o ( ! -type d -print )
tells find
to consider -type d -printf "%p/n"
on the one hand, and ! -type d -print
on the other; and ! -type d
matches anything which isn’t a directory.– Stephen Kitt
Dec 22 '18 at 21:25
The parentheses group expressions, and
!
negates an expression. So ( -type d -printf "%p/n" ) -o ( ! -type d -print )
tells find
to consider -type d -printf "%p/n"
on the one hand, and ! -type d -print
on the other; and ! -type d
matches anything which isn’t a directory.– Stephen Kitt
Dec 22 '18 at 21:25
add a comment |
find
has a huge amount of options and details. Another variant is to use printf with %y
$ find . -printf "%p:%yn"
./dir:d
./file:f
where %y
adds a "d" or a "f" just like ls -l
$ find . -printf "%p%yn" | sed 's!d$!/! ; s!f$!!'
add a comment |
find
has a huge amount of options and details. Another variant is to use printf with %y
$ find . -printf "%p:%yn"
./dir:d
./file:f
where %y
adds a "d" or a "f" just like ls -l
$ find . -printf "%p%yn" | sed 's!d$!/! ; s!f$!!'
add a comment |
find
has a huge amount of options and details. Another variant is to use printf with %y
$ find . -printf "%p:%yn"
./dir:d
./file:f
where %y
adds a "d" or a "f" just like ls -l
$ find . -printf "%p%yn" | sed 's!d$!/! ; s!f$!!'
find
has a huge amount of options and details. Another variant is to use printf with %y
$ find . -printf "%p:%yn"
./dir:d
./file:f
where %y
adds a "d" or a "f" just like ls -l
$ find . -printf "%p%yn" | sed 's!d$!/! ; s!f$!!'
answered Dec 19 '18 at 9:05
JJoao
7,1041928
7,1041928
add a comment |
add a comment |
Thanks for contributing an answer to Unix & Linux Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
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
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f489857%2fusing-find-how-to-classify-like-ls-f-directories-with-a-trailing-slash%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
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
Required, but never shown
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
Required, but never shown
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
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Related: How to use wc and piping to find how many files and directories are in a certain directory?
– Stéphane Chazelas
Dec 19 '18 at 9:06