linux find command for filenames without extension for unknown extensions
I like using the following command to print file names but it prints them with extensions.
find . -type f -printf '%fn'
In my directory, there are many files with different extensions. I tried adding --ignore='*.*'
both before and after -printf
, but it didn't work.
example; I have files myfile1.txt, myfile2.mp3, etc. I need it prints myfile1, myfile2, etc.
How would I do this?
find filenames
add a comment |
I like using the following command to print file names but it prints them with extensions.
find . -type f -printf '%fn'
In my directory, there are many files with different extensions. I tried adding --ignore='*.*'
both before and after -printf
, but it didn't work.
example; I have files myfile1.txt, myfile2.mp3, etc. I need it prints myfile1, myfile2, etc.
How would I do this?
find filenames
Since you specifically ask aboutfind
I’ll provide this aside in a comment. You can do this fluently with modern native bash:shopt -s globstar; files=(**/*); printf '%sn' "${files[@]%.*}"
— this could have odd behavior if a directory in the path has a.
in it and the files in that path have no.
, but I assume that combination is unlikely.
– kojiro
2 days ago
add a comment |
I like using the following command to print file names but it prints them with extensions.
find . -type f -printf '%fn'
In my directory, there are many files with different extensions. I tried adding --ignore='*.*'
both before and after -printf
, but it didn't work.
example; I have files myfile1.txt, myfile2.mp3, etc. I need it prints myfile1, myfile2, etc.
How would I do this?
find filenames
I like using the following command to print file names but it prints them with extensions.
find . -type f -printf '%fn'
In my directory, there are many files with different extensions. I tried adding --ignore='*.*'
both before and after -printf
, but it didn't work.
example; I have files myfile1.txt, myfile2.mp3, etc. I need it prints myfile1, myfile2, etc.
How would I do this?
find filenames
find filenames
edited 2 days ago
kutlus
asked 2 days ago
kutluskutlus
485
485
Since you specifically ask aboutfind
I’ll provide this aside in a comment. You can do this fluently with modern native bash:shopt -s globstar; files=(**/*); printf '%sn' "${files[@]%.*}"
— this could have odd behavior if a directory in the path has a.
in it and the files in that path have no.
, but I assume that combination is unlikely.
– kojiro
2 days ago
add a comment |
Since you specifically ask aboutfind
I’ll provide this aside in a comment. You can do this fluently with modern native bash:shopt -s globstar; files=(**/*); printf '%sn' "${files[@]%.*}"
— this could have odd behavior if a directory in the path has a.
in it and the files in that path have no.
, but I assume that combination is unlikely.
– kojiro
2 days ago
Since you specifically ask about
find
I’ll provide this aside in a comment. You can do this fluently with modern native bash: shopt -s globstar; files=(**/*); printf '%sn' "${files[@]%.*}"
— this could have odd behavior if a directory in the path has a .
in it and the files in that path have no .
, but I assume that combination is unlikely.– kojiro
2 days ago
Since you specifically ask about
find
I’ll provide this aside in a comment. You can do this fluently with modern native bash: shopt -s globstar; files=(**/*); printf '%sn' "${files[@]%.*}"
— this could have odd behavior if a directory in the path has a .
in it and the files in that path have no .
, but I assume that combination is unlikely.– kojiro
2 days ago
add a comment |
4 Answers
4
active
oldest
votes
If I understand you correctly (I didn't, see second part of the answer), you want to avoid listing filenames that contain a dot character.
This will do that:
find . -type f ! -name '*.*'
The filename globbing pattern *.*
would match any filename containing at least one dot. The preceding !
negates the sense of the match, which means that the pathnames that gets through to the end will be those of files that have no dots in their names. In really ancient shells, you may want to escape the !
as !
(or update your Unix installation). The lone !
won't invoke bash
's history expansion facility.
To print only the filename component of the found pathname, with GNU find
:
find . -type f ! -name '*.*' -printf '%fn'
With standard find
(or GNU find
for that matter):
find . -type f ! -name '*.*' -exec basename {} ;
Before using this in a command substitution in a loop, see "Why is looping over find's output bad practice?".
To list all filenames, and at the same time remove everything after the last dot in the name ("remove the extension"), you may use
find . -type f -exec sh -c '
for pathname do
pathname=$( basename "$pathname" )
printf "%sn" "${pathname%.*}"
done' sh {} +
This would send all found pathnames of all files to a short shell loop. The loop would take each pathname and call basename
on it to extract the filename component of the pathname, and then print the resulting string with everything after the last dot removed.
The parameter expansion ${pathname%.*}
means "remove the shortest string matching .*
(a literal dot followed by arbitrary text) from the end of the value of $pathname
". It would have the effect of removing a filename suffix after the last dot in the filename.
For more info about find ... -exec ... {} +
, see e.g. "Understanding the -exec option of `find`".
Thanks for your help, I have tried all three, but they don't print anything. Am I missing something, on the same terminal, in the same directory find . -type f -printf '%fn' works but as I asked in the question I need them without extensions.
– kutlus
2 days ago
@kutlus In that case, I (and the others) may have misunderstood your question. Do you want to remove everything after the last dot in the filename?
– Kusalananda
2 days ago
I just want the file name, example; some files are myfile1.txt, myfile2.mp3, i want it prints myfile1, myfile2. sorry if my questions wasn`t clear, thanks
– kutlus
2 days ago
@kutlus See updated answer.
– Kusalananda
2 days ago
This worked, many thanks!
– kutlus
2 days ago
|
show 1 more comment
In Linux, there is no such thing as a file extension. A .
in a file name has no significance whatsoever (notwithstanding that a .
as the first character in a filename identifies it as a hidden file).
Also, checking the manual page for find
on my system shows no --ignore
option.
That said, if you want to ignore any files with a .
in their name, you can use find
's -not
operator:
find -type f -not -name '*.*' -print
thanks but this doesn`t print anything.
– kutlus
2 days ago
If this does not print anything, then all files must have a.
in their names.
– DopeGhoti
2 days ago
add a comment |
try
find . -type f ! -name '*.*' -print
where
!
: not (! must be escaped)
name '*.*'
: filename with extension
arg, not fast enough !!
– Archemar
2 days ago
Having to escape!
is why I usually suggest using-not
.
– DopeGhoti
2 days ago
well it work w/o escape, I've been escaping it ever since SunOS 3.X... sight.
– Archemar
2 days ago
thanks but this doesn`t print anything.
– kutlus
2 days ago
In what shell do you need to escape it? It works without escaping in both zsh and bash. Both these shells only interpret a history expansion when the ! is accompanied by another character.
– JoL
2 days ago
add a comment |
As other's have pointed out, "extensions" don't really mean anything to Unix systems. But we can remove them from a listing with a simple sed
command.
e.g.
find * -type f -print | sed 's/.[^.]*$//'
If there are directories and you don't want them to be shown in the listing then
find * -type f -printf "%fn" | sed 's/.[^.]*$//'
For a single directory we can just use ls
instead of find
ls | sed 's/.[^.]*$//'
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%2f496299%2flinux-find-command-for-filenames-without-extension-for-unknown-extensions%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
If I understand you correctly (I didn't, see second part of the answer), you want to avoid listing filenames that contain a dot character.
This will do that:
find . -type f ! -name '*.*'
The filename globbing pattern *.*
would match any filename containing at least one dot. The preceding !
negates the sense of the match, which means that the pathnames that gets through to the end will be those of files that have no dots in their names. In really ancient shells, you may want to escape the !
as !
(or update your Unix installation). The lone !
won't invoke bash
's history expansion facility.
To print only the filename component of the found pathname, with GNU find
:
find . -type f ! -name '*.*' -printf '%fn'
With standard find
(or GNU find
for that matter):
find . -type f ! -name '*.*' -exec basename {} ;
Before using this in a command substitution in a loop, see "Why is looping over find's output bad practice?".
To list all filenames, and at the same time remove everything after the last dot in the name ("remove the extension"), you may use
find . -type f -exec sh -c '
for pathname do
pathname=$( basename "$pathname" )
printf "%sn" "${pathname%.*}"
done' sh {} +
This would send all found pathnames of all files to a short shell loop. The loop would take each pathname and call basename
on it to extract the filename component of the pathname, and then print the resulting string with everything after the last dot removed.
The parameter expansion ${pathname%.*}
means "remove the shortest string matching .*
(a literal dot followed by arbitrary text) from the end of the value of $pathname
". It would have the effect of removing a filename suffix after the last dot in the filename.
For more info about find ... -exec ... {} +
, see e.g. "Understanding the -exec option of `find`".
Thanks for your help, I have tried all three, but they don't print anything. Am I missing something, on the same terminal, in the same directory find . -type f -printf '%fn' works but as I asked in the question I need them without extensions.
– kutlus
2 days ago
@kutlus In that case, I (and the others) may have misunderstood your question. Do you want to remove everything after the last dot in the filename?
– Kusalananda
2 days ago
I just want the file name, example; some files are myfile1.txt, myfile2.mp3, i want it prints myfile1, myfile2. sorry if my questions wasn`t clear, thanks
– kutlus
2 days ago
@kutlus See updated answer.
– Kusalananda
2 days ago
This worked, many thanks!
– kutlus
2 days ago
|
show 1 more comment
If I understand you correctly (I didn't, see second part of the answer), you want to avoid listing filenames that contain a dot character.
This will do that:
find . -type f ! -name '*.*'
The filename globbing pattern *.*
would match any filename containing at least one dot. The preceding !
negates the sense of the match, which means that the pathnames that gets through to the end will be those of files that have no dots in their names. In really ancient shells, you may want to escape the !
as !
(or update your Unix installation). The lone !
won't invoke bash
's history expansion facility.
To print only the filename component of the found pathname, with GNU find
:
find . -type f ! -name '*.*' -printf '%fn'
With standard find
(or GNU find
for that matter):
find . -type f ! -name '*.*' -exec basename {} ;
Before using this in a command substitution in a loop, see "Why is looping over find's output bad practice?".
To list all filenames, and at the same time remove everything after the last dot in the name ("remove the extension"), you may use
find . -type f -exec sh -c '
for pathname do
pathname=$( basename "$pathname" )
printf "%sn" "${pathname%.*}"
done' sh {} +
This would send all found pathnames of all files to a short shell loop. The loop would take each pathname and call basename
on it to extract the filename component of the pathname, and then print the resulting string with everything after the last dot removed.
The parameter expansion ${pathname%.*}
means "remove the shortest string matching .*
(a literal dot followed by arbitrary text) from the end of the value of $pathname
". It would have the effect of removing a filename suffix after the last dot in the filename.
For more info about find ... -exec ... {} +
, see e.g. "Understanding the -exec option of `find`".
Thanks for your help, I have tried all three, but they don't print anything. Am I missing something, on the same terminal, in the same directory find . -type f -printf '%fn' works but as I asked in the question I need them without extensions.
– kutlus
2 days ago
@kutlus In that case, I (and the others) may have misunderstood your question. Do you want to remove everything after the last dot in the filename?
– Kusalananda
2 days ago
I just want the file name, example; some files are myfile1.txt, myfile2.mp3, i want it prints myfile1, myfile2. sorry if my questions wasn`t clear, thanks
– kutlus
2 days ago
@kutlus See updated answer.
– Kusalananda
2 days ago
This worked, many thanks!
– kutlus
2 days ago
|
show 1 more comment
If I understand you correctly (I didn't, see second part of the answer), you want to avoid listing filenames that contain a dot character.
This will do that:
find . -type f ! -name '*.*'
The filename globbing pattern *.*
would match any filename containing at least one dot. The preceding !
negates the sense of the match, which means that the pathnames that gets through to the end will be those of files that have no dots in their names. In really ancient shells, you may want to escape the !
as !
(or update your Unix installation). The lone !
won't invoke bash
's history expansion facility.
To print only the filename component of the found pathname, with GNU find
:
find . -type f ! -name '*.*' -printf '%fn'
With standard find
(or GNU find
for that matter):
find . -type f ! -name '*.*' -exec basename {} ;
Before using this in a command substitution in a loop, see "Why is looping over find's output bad practice?".
To list all filenames, and at the same time remove everything after the last dot in the name ("remove the extension"), you may use
find . -type f -exec sh -c '
for pathname do
pathname=$( basename "$pathname" )
printf "%sn" "${pathname%.*}"
done' sh {} +
This would send all found pathnames of all files to a short shell loop. The loop would take each pathname and call basename
on it to extract the filename component of the pathname, and then print the resulting string with everything after the last dot removed.
The parameter expansion ${pathname%.*}
means "remove the shortest string matching .*
(a literal dot followed by arbitrary text) from the end of the value of $pathname
". It would have the effect of removing a filename suffix after the last dot in the filename.
For more info about find ... -exec ... {} +
, see e.g. "Understanding the -exec option of `find`".
If I understand you correctly (I didn't, see second part of the answer), you want to avoid listing filenames that contain a dot character.
This will do that:
find . -type f ! -name '*.*'
The filename globbing pattern *.*
would match any filename containing at least one dot. The preceding !
negates the sense of the match, which means that the pathnames that gets through to the end will be those of files that have no dots in their names. In really ancient shells, you may want to escape the !
as !
(or update your Unix installation). The lone !
won't invoke bash
's history expansion facility.
To print only the filename component of the found pathname, with GNU find
:
find . -type f ! -name '*.*' -printf '%fn'
With standard find
(or GNU find
for that matter):
find . -type f ! -name '*.*' -exec basename {} ;
Before using this in a command substitution in a loop, see "Why is looping over find's output bad practice?".
To list all filenames, and at the same time remove everything after the last dot in the name ("remove the extension"), you may use
find . -type f -exec sh -c '
for pathname do
pathname=$( basename "$pathname" )
printf "%sn" "${pathname%.*}"
done' sh {} +
This would send all found pathnames of all files to a short shell loop. The loop would take each pathname and call basename
on it to extract the filename component of the pathname, and then print the resulting string with everything after the last dot removed.
The parameter expansion ${pathname%.*}
means "remove the shortest string matching .*
(a literal dot followed by arbitrary text) from the end of the value of $pathname
". It would have the effect of removing a filename suffix after the last dot in the filename.
For more info about find ... -exec ... {} +
, see e.g. "Understanding the -exec option of `find`".
edited 2 days ago
answered 2 days ago
KusalanandaKusalananda
126k16239393
126k16239393
Thanks for your help, I have tried all three, but they don't print anything. Am I missing something, on the same terminal, in the same directory find . -type f -printf '%fn' works but as I asked in the question I need them without extensions.
– kutlus
2 days ago
@kutlus In that case, I (and the others) may have misunderstood your question. Do you want to remove everything after the last dot in the filename?
– Kusalananda
2 days ago
I just want the file name, example; some files are myfile1.txt, myfile2.mp3, i want it prints myfile1, myfile2. sorry if my questions wasn`t clear, thanks
– kutlus
2 days ago
@kutlus See updated answer.
– Kusalananda
2 days ago
This worked, many thanks!
– kutlus
2 days ago
|
show 1 more comment
Thanks for your help, I have tried all three, but they don't print anything. Am I missing something, on the same terminal, in the same directory find . -type f -printf '%fn' works but as I asked in the question I need them without extensions.
– kutlus
2 days ago
@kutlus In that case, I (and the others) may have misunderstood your question. Do you want to remove everything after the last dot in the filename?
– Kusalananda
2 days ago
I just want the file name, example; some files are myfile1.txt, myfile2.mp3, i want it prints myfile1, myfile2. sorry if my questions wasn`t clear, thanks
– kutlus
2 days ago
@kutlus See updated answer.
– Kusalananda
2 days ago
This worked, many thanks!
– kutlus
2 days ago
Thanks for your help, I have tried all three, but they don't print anything. Am I missing something, on the same terminal, in the same directory find . -type f -printf '%fn' works but as I asked in the question I need them without extensions.
– kutlus
2 days ago
Thanks for your help, I have tried all three, but they don't print anything. Am I missing something, on the same terminal, in the same directory find . -type f -printf '%fn' works but as I asked in the question I need them without extensions.
– kutlus
2 days ago
@kutlus In that case, I (and the others) may have misunderstood your question. Do you want to remove everything after the last dot in the filename?
– Kusalananda
2 days ago
@kutlus In that case, I (and the others) may have misunderstood your question. Do you want to remove everything after the last dot in the filename?
– Kusalananda
2 days ago
I just want the file name, example; some files are myfile1.txt, myfile2.mp3, i want it prints myfile1, myfile2. sorry if my questions wasn`t clear, thanks
– kutlus
2 days ago
I just want the file name, example; some files are myfile1.txt, myfile2.mp3, i want it prints myfile1, myfile2. sorry if my questions wasn`t clear, thanks
– kutlus
2 days ago
@kutlus See updated answer.
– Kusalananda
2 days ago
@kutlus See updated answer.
– Kusalananda
2 days ago
This worked, many thanks!
– kutlus
2 days ago
This worked, many thanks!
– kutlus
2 days ago
|
show 1 more comment
In Linux, there is no such thing as a file extension. A .
in a file name has no significance whatsoever (notwithstanding that a .
as the first character in a filename identifies it as a hidden file).
Also, checking the manual page for find
on my system shows no --ignore
option.
That said, if you want to ignore any files with a .
in their name, you can use find
's -not
operator:
find -type f -not -name '*.*' -print
thanks but this doesn`t print anything.
– kutlus
2 days ago
If this does not print anything, then all files must have a.
in their names.
– DopeGhoti
2 days ago
add a comment |
In Linux, there is no such thing as a file extension. A .
in a file name has no significance whatsoever (notwithstanding that a .
as the first character in a filename identifies it as a hidden file).
Also, checking the manual page for find
on my system shows no --ignore
option.
That said, if you want to ignore any files with a .
in their name, you can use find
's -not
operator:
find -type f -not -name '*.*' -print
thanks but this doesn`t print anything.
– kutlus
2 days ago
If this does not print anything, then all files must have a.
in their names.
– DopeGhoti
2 days ago
add a comment |
In Linux, there is no such thing as a file extension. A .
in a file name has no significance whatsoever (notwithstanding that a .
as the first character in a filename identifies it as a hidden file).
Also, checking the manual page for find
on my system shows no --ignore
option.
That said, if you want to ignore any files with a .
in their name, you can use find
's -not
operator:
find -type f -not -name '*.*' -print
In Linux, there is no such thing as a file extension. A .
in a file name has no significance whatsoever (notwithstanding that a .
as the first character in a filename identifies it as a hidden file).
Also, checking the manual page for find
on my system shows no --ignore
option.
That said, if you want to ignore any files with a .
in their name, you can use find
's -not
operator:
find -type f -not -name '*.*' -print
answered 2 days ago
DopeGhotiDopeGhoti
44.4k55684
44.4k55684
thanks but this doesn`t print anything.
– kutlus
2 days ago
If this does not print anything, then all files must have a.
in their names.
– DopeGhoti
2 days ago
add a comment |
thanks but this doesn`t print anything.
– kutlus
2 days ago
If this does not print anything, then all files must have a.
in their names.
– DopeGhoti
2 days ago
thanks but this doesn`t print anything.
– kutlus
2 days ago
thanks but this doesn`t print anything.
– kutlus
2 days ago
If this does not print anything, then all files must have a
.
in their names.– DopeGhoti
2 days ago
If this does not print anything, then all files must have a
.
in their names.– DopeGhoti
2 days ago
add a comment |
try
find . -type f ! -name '*.*' -print
where
!
: not (! must be escaped)
name '*.*'
: filename with extension
arg, not fast enough !!
– Archemar
2 days ago
Having to escape!
is why I usually suggest using-not
.
– DopeGhoti
2 days ago
well it work w/o escape, I've been escaping it ever since SunOS 3.X... sight.
– Archemar
2 days ago
thanks but this doesn`t print anything.
– kutlus
2 days ago
In what shell do you need to escape it? It works without escaping in both zsh and bash. Both these shells only interpret a history expansion when the ! is accompanied by another character.
– JoL
2 days ago
add a comment |
try
find . -type f ! -name '*.*' -print
where
!
: not (! must be escaped)
name '*.*'
: filename with extension
arg, not fast enough !!
– Archemar
2 days ago
Having to escape!
is why I usually suggest using-not
.
– DopeGhoti
2 days ago
well it work w/o escape, I've been escaping it ever since SunOS 3.X... sight.
– Archemar
2 days ago
thanks but this doesn`t print anything.
– kutlus
2 days ago
In what shell do you need to escape it? It works without escaping in both zsh and bash. Both these shells only interpret a history expansion when the ! is accompanied by another character.
– JoL
2 days ago
add a comment |
try
find . -type f ! -name '*.*' -print
where
!
: not (! must be escaped)
name '*.*'
: filename with extension
try
find . -type f ! -name '*.*' -print
where
!
: not (! must be escaped)
name '*.*'
: filename with extension
answered 2 days ago
ArchemarArchemar
19.9k93670
19.9k93670
arg, not fast enough !!
– Archemar
2 days ago
Having to escape!
is why I usually suggest using-not
.
– DopeGhoti
2 days ago
well it work w/o escape, I've been escaping it ever since SunOS 3.X... sight.
– Archemar
2 days ago
thanks but this doesn`t print anything.
– kutlus
2 days ago
In what shell do you need to escape it? It works without escaping in both zsh and bash. Both these shells only interpret a history expansion when the ! is accompanied by another character.
– JoL
2 days ago
add a comment |
arg, not fast enough !!
– Archemar
2 days ago
Having to escape!
is why I usually suggest using-not
.
– DopeGhoti
2 days ago
well it work w/o escape, I've been escaping it ever since SunOS 3.X... sight.
– Archemar
2 days ago
thanks but this doesn`t print anything.
– kutlus
2 days ago
In what shell do you need to escape it? It works without escaping in both zsh and bash. Both these shells only interpret a history expansion when the ! is accompanied by another character.
– JoL
2 days ago
arg, not fast enough !!
– Archemar
2 days ago
arg, not fast enough !!
– Archemar
2 days ago
Having to escape
!
is why I usually suggest using -not
.– DopeGhoti
2 days ago
Having to escape
!
is why I usually suggest using -not
.– DopeGhoti
2 days ago
well it work w/o escape, I've been escaping it ever since SunOS 3.X... sight.
– Archemar
2 days ago
well it work w/o escape, I've been escaping it ever since SunOS 3.X... sight.
– Archemar
2 days ago
thanks but this doesn`t print anything.
– kutlus
2 days ago
thanks but this doesn`t print anything.
– kutlus
2 days ago
In what shell do you need to escape it? It works without escaping in both zsh and bash. Both these shells only interpret a history expansion when the ! is accompanied by another character.
– JoL
2 days ago
In what shell do you need to escape it? It works without escaping in both zsh and bash. Both these shells only interpret a history expansion when the ! is accompanied by another character.
– JoL
2 days ago
add a comment |
As other's have pointed out, "extensions" don't really mean anything to Unix systems. But we can remove them from a listing with a simple sed
command.
e.g.
find * -type f -print | sed 's/.[^.]*$//'
If there are directories and you don't want them to be shown in the listing then
find * -type f -printf "%fn" | sed 's/.[^.]*$//'
For a single directory we can just use ls
instead of find
ls | sed 's/.[^.]*$//'
add a comment |
As other's have pointed out, "extensions" don't really mean anything to Unix systems. But we can remove them from a listing with a simple sed
command.
e.g.
find * -type f -print | sed 's/.[^.]*$//'
If there are directories and you don't want them to be shown in the listing then
find * -type f -printf "%fn" | sed 's/.[^.]*$//'
For a single directory we can just use ls
instead of find
ls | sed 's/.[^.]*$//'
add a comment |
As other's have pointed out, "extensions" don't really mean anything to Unix systems. But we can remove them from a listing with a simple sed
command.
e.g.
find * -type f -print | sed 's/.[^.]*$//'
If there are directories and you don't want them to be shown in the listing then
find * -type f -printf "%fn" | sed 's/.[^.]*$//'
For a single directory we can just use ls
instead of find
ls | sed 's/.[^.]*$//'
As other's have pointed out, "extensions" don't really mean anything to Unix systems. But we can remove them from a listing with a simple sed
command.
e.g.
find * -type f -print | sed 's/.[^.]*$//'
If there are directories and you don't want them to be shown in the listing then
find * -type f -printf "%fn" | sed 's/.[^.]*$//'
For a single directory we can just use ls
instead of find
ls | sed 's/.[^.]*$//'
answered 2 days ago
Stephen HarrisStephen Harris
25.5k24477
25.5k24477
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.
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%2f496299%2flinux-find-command-for-filenames-without-extension-for-unknown-extensions%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
Since you specifically ask about
find
I’ll provide this aside in a comment. You can do this fluently with modern native bash:shopt -s globstar; files=(**/*); printf '%sn' "${files[@]%.*}"
— this could have odd behavior if a directory in the path has a.
in it and the files in that path have no.
, but I assume that combination is unlikely.– kojiro
2 days ago