Exclude hidden files when searching with Unix/Linux find?
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
What options do I need to use with find
to exclude hidden files?
linux command-line unix find
add a comment |
What options do I need to use with find
to exclude hidden files?
linux command-line unix find
4
Aside: the reason there isn't some special support for this task is that the only thing special about files named with a leading '.' is that there are not listed byls
unless specifically requested: they are completely ordinary files in every respect, its just thatls
lets you ignore them by default.
– dmckee
Jun 16 '10 at 0:32
1
Question: do you want to hide something like.hidden/visible.txt
?
– Keith Thompson
Oct 13 '11 at 0:20
add a comment |
What options do I need to use with find
to exclude hidden files?
linux command-line unix find
What options do I need to use with find
to exclude hidden files?
linux command-line unix find
linux command-line unix find
edited Nov 19 '18 at 1:43
Steven Penny
1
1
asked Jun 15 '10 at 21:19
therefromheretherefromhere
5,09993342
5,09993342
4
Aside: the reason there isn't some special support for this task is that the only thing special about files named with a leading '.' is that there are not listed byls
unless specifically requested: they are completely ordinary files in every respect, its just thatls
lets you ignore them by default.
– dmckee
Jun 16 '10 at 0:32
1
Question: do you want to hide something like.hidden/visible.txt
?
– Keith Thompson
Oct 13 '11 at 0:20
add a comment |
4
Aside: the reason there isn't some special support for this task is that the only thing special about files named with a leading '.' is that there are not listed byls
unless specifically requested: they are completely ordinary files in every respect, its just thatls
lets you ignore them by default.
– dmckee
Jun 16 '10 at 0:32
1
Question: do you want to hide something like.hidden/visible.txt
?
– Keith Thompson
Oct 13 '11 at 0:20
4
4
Aside: the reason there isn't some special support for this task is that the only thing special about files named with a leading '.' is that there are not listed by
ls
unless specifically requested: they are completely ordinary files in every respect, its just that ls
lets you ignore them by default.– dmckee
Jun 16 '10 at 0:32
Aside: the reason there isn't some special support for this task is that the only thing special about files named with a leading '.' is that there are not listed by
ls
unless specifically requested: they are completely ordinary files in every respect, its just that ls
lets you ignore them by default.– dmckee
Jun 16 '10 at 0:32
1
1
Question: do you want to hide something like
.hidden/visible.txt
?– Keith Thompson
Oct 13 '11 at 0:20
Question: do you want to hide something like
.hidden/visible.txt
?– Keith Thompson
Oct 13 '11 at 0:20
add a comment |
8 Answers
8
active
oldest
votes
I found this here:
find . ( ! -regex '.*/..*' ) -type f -name "whatever"
Why not just( ! -name '.*' )
?
– grawity
Jun 16 '10 at 15:15
@grawity I just found that, I don't know entirely how it works. Would yours not only hide hidden files, but hidden directories and all their sub-content and hidden files in subfolders?
– Jarvin
Jun 16 '10 at 16:05
5
No, it wouldn't :/ But( ! -path '*/.*' )
would.
– grawity
Jun 16 '10 at 16:38
@grawity Ya, I guess I made an assumption about what the OP wanted... Your -name solution is probably the closest to what they were asking for.
– Jarvin
Jun 16 '10 at 18:07
@grawity&Dan: Isn't it ( !-path '^.*' ) ?? your solutions will ignore any file that has a '.' anywhere in the file name like a.exe, b.out etc....
– Software Mechanic
Jun 30 '11 at 8:27
|
show 3 more comments
This doesn't answer your question, but for the task of finding non-hidden files I like to let find find all the files then filter with grep.
find . -type f | grep -v '/.'
Similar to your approach but perhaps a bit simpler.
This was the only one of the one liners that worked for me.
– entpnerd
Aug 8 '16 at 9:06
add a comment |
It seems negation glob pattern is not well known. So you can use:
find . -name "[!.]*"
add a comment |
Try the following find
usage:
find . -type f -not -path '*/.*'
Which would ignore all the hidden files (files and directories starting with a dot).
add a comment |
I wrote a script called findnh
which I believe handles certain edge cases better than the answers to this question that I've been able to find on the web.
#!/bin/bash
declare -a paths
while [ $# -ne 0 ]; do
case "$1" in -*) break ;; esac
paths+=("$1")
shift
done
find "${paths[@]}" ( -name . -o -name .. -o ! ( -name '.*' -prune ) ) "$@"
For example, you can find non-hidden files and directories inside of an explicitly-specified hidden directory with a command like findnh ~/.hiddendir/
, which will show ~/.hiddendir/file
but not ~/.hiddendir/.superhiddenfile
.
1
Nice bit of coding. Except, when I tryfindnh ~/.hiddendir/
, I get nothing. Other than that, how is this different from! -path '*/.*'
andfind … | grep -v '/.'
?
– G-Man
Oct 22 '14 at 16:42
add a comment |
If you aims is to find
and grep
, ripgrep
does exclude hidden files by default, e.g.
rg --files
--files
Print each file that would be searched without actually performing the search.
add a comment |
fd
Use fd
, a simple, much faster and user-friendly alternative to find
. By default, it:
- Ignores hidden directories and files, by default.
- Ignores patterns from your
.gitignore
, by default.
Check the Benchmark analysis.
add a comment |
To find hidden files:
find -name '[.]*'
To find visible files:
find -name '[!.]*'
It is that simple.
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "3"
};
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: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
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%2fsuperuser.com%2fquestions%2f152958%2fexclude-hidden-files-when-searching-with-unix-linux-find%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
8 Answers
8
active
oldest
votes
8 Answers
8
active
oldest
votes
active
oldest
votes
active
oldest
votes
I found this here:
find . ( ! -regex '.*/..*' ) -type f -name "whatever"
Why not just( ! -name '.*' )
?
– grawity
Jun 16 '10 at 15:15
@grawity I just found that, I don't know entirely how it works. Would yours not only hide hidden files, but hidden directories and all their sub-content and hidden files in subfolders?
– Jarvin
Jun 16 '10 at 16:05
5
No, it wouldn't :/ But( ! -path '*/.*' )
would.
– grawity
Jun 16 '10 at 16:38
@grawity Ya, I guess I made an assumption about what the OP wanted... Your -name solution is probably the closest to what they were asking for.
– Jarvin
Jun 16 '10 at 18:07
@grawity&Dan: Isn't it ( !-path '^.*' ) ?? your solutions will ignore any file that has a '.' anywhere in the file name like a.exe, b.out etc....
– Software Mechanic
Jun 30 '11 at 8:27
|
show 3 more comments
I found this here:
find . ( ! -regex '.*/..*' ) -type f -name "whatever"
Why not just( ! -name '.*' )
?
– grawity
Jun 16 '10 at 15:15
@grawity I just found that, I don't know entirely how it works. Would yours not only hide hidden files, but hidden directories and all their sub-content and hidden files in subfolders?
– Jarvin
Jun 16 '10 at 16:05
5
No, it wouldn't :/ But( ! -path '*/.*' )
would.
– grawity
Jun 16 '10 at 16:38
@grawity Ya, I guess I made an assumption about what the OP wanted... Your -name solution is probably the closest to what they were asking for.
– Jarvin
Jun 16 '10 at 18:07
@grawity&Dan: Isn't it ( !-path '^.*' ) ?? your solutions will ignore any file that has a '.' anywhere in the file name like a.exe, b.out etc....
– Software Mechanic
Jun 30 '11 at 8:27
|
show 3 more comments
I found this here:
find . ( ! -regex '.*/..*' ) -type f -name "whatever"
I found this here:
find . ( ! -regex '.*/..*' ) -type f -name "whatever"
answered Jun 15 '10 at 21:23
JarvinJarvin
5,90554062
5,90554062
Why not just( ! -name '.*' )
?
– grawity
Jun 16 '10 at 15:15
@grawity I just found that, I don't know entirely how it works. Would yours not only hide hidden files, but hidden directories and all their sub-content and hidden files in subfolders?
– Jarvin
Jun 16 '10 at 16:05
5
No, it wouldn't :/ But( ! -path '*/.*' )
would.
– grawity
Jun 16 '10 at 16:38
@grawity Ya, I guess I made an assumption about what the OP wanted... Your -name solution is probably the closest to what they were asking for.
– Jarvin
Jun 16 '10 at 18:07
@grawity&Dan: Isn't it ( !-path '^.*' ) ?? your solutions will ignore any file that has a '.' anywhere in the file name like a.exe, b.out etc....
– Software Mechanic
Jun 30 '11 at 8:27
|
show 3 more comments
Why not just( ! -name '.*' )
?
– grawity
Jun 16 '10 at 15:15
@grawity I just found that, I don't know entirely how it works. Would yours not only hide hidden files, but hidden directories and all their sub-content and hidden files in subfolders?
– Jarvin
Jun 16 '10 at 16:05
5
No, it wouldn't :/ But( ! -path '*/.*' )
would.
– grawity
Jun 16 '10 at 16:38
@grawity Ya, I guess I made an assumption about what the OP wanted... Your -name solution is probably the closest to what they were asking for.
– Jarvin
Jun 16 '10 at 18:07
@grawity&Dan: Isn't it ( !-path '^.*' ) ?? your solutions will ignore any file that has a '.' anywhere in the file name like a.exe, b.out etc....
– Software Mechanic
Jun 30 '11 at 8:27
Why not just
( ! -name '.*' )
?– grawity
Jun 16 '10 at 15:15
Why not just
( ! -name '.*' )
?– grawity
Jun 16 '10 at 15:15
@grawity I just found that, I don't know entirely how it works. Would yours not only hide hidden files, but hidden directories and all their sub-content and hidden files in subfolders?
– Jarvin
Jun 16 '10 at 16:05
@grawity I just found that, I don't know entirely how it works. Would yours not only hide hidden files, but hidden directories and all their sub-content and hidden files in subfolders?
– Jarvin
Jun 16 '10 at 16:05
5
5
No, it wouldn't :/ But
( ! -path '*/.*' )
would.– grawity
Jun 16 '10 at 16:38
No, it wouldn't :/ But
( ! -path '*/.*' )
would.– grawity
Jun 16 '10 at 16:38
@grawity Ya, I guess I made an assumption about what the OP wanted... Your -name solution is probably the closest to what they were asking for.
– Jarvin
Jun 16 '10 at 18:07
@grawity Ya, I guess I made an assumption about what the OP wanted... Your -name solution is probably the closest to what they were asking for.
– Jarvin
Jun 16 '10 at 18:07
@grawity&Dan: Isn't it ( !-path '^.*' ) ?? your solutions will ignore any file that has a '.' anywhere in the file name like a.exe, b.out etc....
– Software Mechanic
Jun 30 '11 at 8:27
@grawity&Dan: Isn't it ( !-path '^.*' ) ?? your solutions will ignore any file that has a '.' anywhere in the file name like a.exe, b.out etc....
– Software Mechanic
Jun 30 '11 at 8:27
|
show 3 more comments
This doesn't answer your question, but for the task of finding non-hidden files I like to let find find all the files then filter with grep.
find . -type f | grep -v '/.'
Similar to your approach but perhaps a bit simpler.
This was the only one of the one liners that worked for me.
– entpnerd
Aug 8 '16 at 9:06
add a comment |
This doesn't answer your question, but for the task of finding non-hidden files I like to let find find all the files then filter with grep.
find . -type f | grep -v '/.'
Similar to your approach but perhaps a bit simpler.
This was the only one of the one liners that worked for me.
– entpnerd
Aug 8 '16 at 9:06
add a comment |
This doesn't answer your question, but for the task of finding non-hidden files I like to let find find all the files then filter with grep.
find . -type f | grep -v '/.'
Similar to your approach but perhaps a bit simpler.
This doesn't answer your question, but for the task of finding non-hidden files I like to let find find all the files then filter with grep.
find . -type f | grep -v '/.'
Similar to your approach but perhaps a bit simpler.
answered Dec 13 '11 at 21:41
Simon ChiangSimon Chiang
22922
22922
This was the only one of the one liners that worked for me.
– entpnerd
Aug 8 '16 at 9:06
add a comment |
This was the only one of the one liners that worked for me.
– entpnerd
Aug 8 '16 at 9:06
This was the only one of the one liners that worked for me.
– entpnerd
Aug 8 '16 at 9:06
This was the only one of the one liners that worked for me.
– entpnerd
Aug 8 '16 at 9:06
add a comment |
It seems negation glob pattern is not well known. So you can use:
find . -name "[!.]*"
add a comment |
It seems negation glob pattern is not well known. So you can use:
find . -name "[!.]*"
add a comment |
It seems negation glob pattern is not well known. So you can use:
find . -name "[!.]*"
It seems negation glob pattern is not well known. So you can use:
find . -name "[!.]*"
edited Nov 12 '15 at 15:17
answered Nov 12 '15 at 8:15
reddotreddot
24426
24426
add a comment |
add a comment |
Try the following find
usage:
find . -type f -not -path '*/.*'
Which would ignore all the hidden files (files and directories starting with a dot).
add a comment |
Try the following find
usage:
find . -type f -not -path '*/.*'
Which would ignore all the hidden files (files and directories starting with a dot).
add a comment |
Try the following find
usage:
find . -type f -not -path '*/.*'
Which would ignore all the hidden files (files and directories starting with a dot).
Try the following find
usage:
find . -type f -not -path '*/.*'
Which would ignore all the hidden files (files and directories starting with a dot).
answered Apr 20 '15 at 9:38
kenorbkenorb
11.7k1580118
11.7k1580118
add a comment |
add a comment |
I wrote a script called findnh
which I believe handles certain edge cases better than the answers to this question that I've been able to find on the web.
#!/bin/bash
declare -a paths
while [ $# -ne 0 ]; do
case "$1" in -*) break ;; esac
paths+=("$1")
shift
done
find "${paths[@]}" ( -name . -o -name .. -o ! ( -name '.*' -prune ) ) "$@"
For example, you can find non-hidden files and directories inside of an explicitly-specified hidden directory with a command like findnh ~/.hiddendir/
, which will show ~/.hiddendir/file
but not ~/.hiddendir/.superhiddenfile
.
1
Nice bit of coding. Except, when I tryfindnh ~/.hiddendir/
, I get nothing. Other than that, how is this different from! -path '*/.*'
andfind … | grep -v '/.'
?
– G-Man
Oct 22 '14 at 16:42
add a comment |
I wrote a script called findnh
which I believe handles certain edge cases better than the answers to this question that I've been able to find on the web.
#!/bin/bash
declare -a paths
while [ $# -ne 0 ]; do
case "$1" in -*) break ;; esac
paths+=("$1")
shift
done
find "${paths[@]}" ( -name . -o -name .. -o ! ( -name '.*' -prune ) ) "$@"
For example, you can find non-hidden files and directories inside of an explicitly-specified hidden directory with a command like findnh ~/.hiddendir/
, which will show ~/.hiddendir/file
but not ~/.hiddendir/.superhiddenfile
.
1
Nice bit of coding. Except, when I tryfindnh ~/.hiddendir/
, I get nothing. Other than that, how is this different from! -path '*/.*'
andfind … | grep -v '/.'
?
– G-Man
Oct 22 '14 at 16:42
add a comment |
I wrote a script called findnh
which I believe handles certain edge cases better than the answers to this question that I've been able to find on the web.
#!/bin/bash
declare -a paths
while [ $# -ne 0 ]; do
case "$1" in -*) break ;; esac
paths+=("$1")
shift
done
find "${paths[@]}" ( -name . -o -name .. -o ! ( -name '.*' -prune ) ) "$@"
For example, you can find non-hidden files and directories inside of an explicitly-specified hidden directory with a command like findnh ~/.hiddendir/
, which will show ~/.hiddendir/file
but not ~/.hiddendir/.superhiddenfile
.
I wrote a script called findnh
which I believe handles certain edge cases better than the answers to this question that I've been able to find on the web.
#!/bin/bash
declare -a paths
while [ $# -ne 0 ]; do
case "$1" in -*) break ;; esac
paths+=("$1")
shift
done
find "${paths[@]}" ( -name . -o -name .. -o ! ( -name '.*' -prune ) ) "$@"
For example, you can find non-hidden files and directories inside of an explicitly-specified hidden directory with a command like findnh ~/.hiddendir/
, which will show ~/.hiddendir/file
but not ~/.hiddendir/.superhiddenfile
.
edited Oct 22 '14 at 15:59
answered Oct 22 '14 at 15:49
Kurt GlastetterKurt Glastetter
192
192
1
Nice bit of coding. Except, when I tryfindnh ~/.hiddendir/
, I get nothing. Other than that, how is this different from! -path '*/.*'
andfind … | grep -v '/.'
?
– G-Man
Oct 22 '14 at 16:42
add a comment |
1
Nice bit of coding. Except, when I tryfindnh ~/.hiddendir/
, I get nothing. Other than that, how is this different from! -path '*/.*'
andfind … | grep -v '/.'
?
– G-Man
Oct 22 '14 at 16:42
1
1
Nice bit of coding. Except, when I try
findnh ~/.hiddendir/
, I get nothing. Other than that, how is this different from ! -path '*/.*'
and find … | grep -v '/.'
?– G-Man
Oct 22 '14 at 16:42
Nice bit of coding. Except, when I try
findnh ~/.hiddendir/
, I get nothing. Other than that, how is this different from ! -path '*/.*'
and find … | grep -v '/.'
?– G-Man
Oct 22 '14 at 16:42
add a comment |
If you aims is to find
and grep
, ripgrep
does exclude hidden files by default, e.g.
rg --files
--files
Print each file that would be searched without actually performing the search.
add a comment |
If you aims is to find
and grep
, ripgrep
does exclude hidden files by default, e.g.
rg --files
--files
Print each file that would be searched without actually performing the search.
add a comment |
If you aims is to find
and grep
, ripgrep
does exclude hidden files by default, e.g.
rg --files
--files
Print each file that would be searched without actually performing the search.
If you aims is to find
and grep
, ripgrep
does exclude hidden files by default, e.g.
rg --files
--files
Print each file that would be searched without actually performing the search.
answered May 3 '18 at 13:38
kenorbkenorb
11.7k1580118
11.7k1580118
add a comment |
add a comment |
fd
Use fd
, a simple, much faster and user-friendly alternative to find
. By default, it:
- Ignores hidden directories and files, by default.
- Ignores patterns from your
.gitignore
, by default.
Check the Benchmark analysis.
add a comment |
fd
Use fd
, a simple, much faster and user-friendly alternative to find
. By default, it:
- Ignores hidden directories and files, by default.
- Ignores patterns from your
.gitignore
, by default.
Check the Benchmark analysis.
add a comment |
fd
Use fd
, a simple, much faster and user-friendly alternative to find
. By default, it:
- Ignores hidden directories and files, by default.
- Ignores patterns from your
.gitignore
, by default.
Check the Benchmark analysis.
fd
Use fd
, a simple, much faster and user-friendly alternative to find
. By default, it:
- Ignores hidden directories and files, by default.
- Ignores patterns from your
.gitignore
, by default.
Check the Benchmark analysis.
answered May 3 '18 at 13:41
kenorbkenorb
11.7k1580118
11.7k1580118
add a comment |
add a comment |
To find hidden files:
find -name '[.]*'
To find visible files:
find -name '[!.]*'
It is that simple.
add a comment |
To find hidden files:
find -name '[.]*'
To find visible files:
find -name '[!.]*'
It is that simple.
add a comment |
To find hidden files:
find -name '[.]*'
To find visible files:
find -name '[!.]*'
It is that simple.
To find hidden files:
find -name '[.]*'
To find visible files:
find -name '[!.]*'
It is that simple.
answered Feb 10 at 14:01
CarminCarmin
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Super User!
- 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%2fsuperuser.com%2fquestions%2f152958%2fexclude-hidden-files-when-searching-with-unix-linux-find%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
4
Aside: the reason there isn't some special support for this task is that the only thing special about files named with a leading '.' is that there are not listed by
ls
unless specifically requested: they are completely ordinary files in every respect, its just thatls
lets you ignore them by default.– dmckee
Jun 16 '10 at 0:32
1
Question: do you want to hide something like
.hidden/visible.txt
?– Keith Thompson
Oct 13 '11 at 0:20