S
S
SOTVM2017-10-24 13:26:57
linux
SOTVM, 2017-10-24 13:26:57

List of files without extensions but at the same time display hidden files (so that the dot remains)?

Here today someone asked the question: "
How to display file names without extensions, but at the same time display hidden files (so that the dot remains)? " Any questions? I also wondered how this can be solved, but even though it’s simple, but quickly it didn’t work either to write code or google the answer. I’ve been familiar with linux | bash for a long time (I’m just learning) Enough lyrics, let’s get to the question: ls - a will give a listing of directories with hidden files, but how to exclude directories from this list? with regexp I don’t understand anything at all (I did it in notepad++ in a minute) I tried ls -a | awk '/(^.+?)(\..+$) /{print $1}'


this solves it in notepad++, but how to translate it into the linux console?
59ef12b2931eb258454997.png
PS
in this case, everything that comes after the last / right dot in the file name is considered an extension, of
course, excluding files starting with a dot.
PS
1) solution:
find -maxdepth 1 -type f -printf "%f\n" | sed -r 's/^(.+)\.[^.]+$/\1/'

Answer the question

In order to leave comments, you need to log in

3 answer(s)
S
Saboteur, 2017-10-24
@sotvm

Why is everything so complicated for you.
Output everything without extension, but with dots
Remove directories
Another option is to ignore files where there is a dot not at the beginning of the file.
ls -FA --ignore='?*.*' | grep -v "/"

G
goshanchik_kot, 2018-11-07
@goshanchik_kot

Can you find out what exactly the function does?

sed -r 's/^(.+)\.[^.]+$/\1/'
?
otherwise I’m new to this Linux of yours, I understood the part with find-printf, but it doesn’t reach :(

S
SOTVM, 2017-10-25
@sotvm

Thank you, I seem to have read the man, but somehow it "passed by the checkout" ls -FA | grep -v "/"
now I will know/use,
and with extensions --ignore='*.???' - alas, not a universal option,
because. it can be any number of characters.
but this will be just right ㋛
ls -FA | grep -v "/" | sed -r 's/^(.+)\.[^.]+$/\1/'

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question