Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
hey all
simple question for you guys but i have spent a good while trying to figure it out
i have an assignment question that i am struggling with.
is it possible with a list query to list all the files that begin with two letters, have an e in the name and end with 1 or more letter
what i have so far is
ls [a-z][a-z]*e**[a-z]
this seems to work except if the filename starts with an e its not showing it in the list
The program ls is getting its input from you via the shell. The shell uses globbing not regular expressions. See "man 7 glob"
You might take a look at find instead if you really need regular expressions. In particular, take a look at the -regex option. find can deal with more than one type of regular expression dialect.
thanks for the replies
i wasnt given a list of filenames, i was told to create them to test the command is working.
I believe I can only use the ls command.
I am also trying to figure out how to add queries using ls
for example how to say the filename contains the letter e AND the first 2 characters are letters.
So far it seems this is not working for me.
What have you tried and what are your test file names?
So, exact question
Create the command that will do the following: List all the files that begin with two letters, have an e in the name and end with 1 or more letter.
I am now trying this
ls [a-z][a-z]*e**[!0-9]
I have created about 10 files. some with no extension and some with .txt
file names = apple cake bake hardest hardest1 apple1 bakes cakes echo
Where I have got to
my command will list the files but echo will not be listed even though it starts with 2 letters and contains an e
also, it doesnt work for the files that have the .txt extensions
Because of the ...*e*... Your pattern will only match filenames where an e exists in then middle which is why echo does not work. I don't know why the .txt extensions do not match without seeing the actual filename.
Not sure what you have learned in class but we are not just going to give you the answer.
Because of the ...*e*... Your pattern will only match filenames where an e exists in then middle which is why echo does not work. I don't know why the .txt extensions do not match without seeing the actual filename.
Not sure what you have learned in class but we are not just going to give you the answer.
All I am looking for is a pointer, i am not expecting the answer. This assignment was after first class. I am wondering if the answer can be achieved with a single ls command ?
What I cant see is how to use an "and" command or if thats even possible as I am struggling to work out how to ask for a file that starts with something, ends with something and also has a specific character somewhere in it....
If the extglob shell option is enabled using the shopt builtin, several extended pattern matching operators are recognized. In the following description, a pattern-list is a list of one or more patterns separated by a ‘|’. Composite patterns may be formed using one or more of the following sub-patterns:
indeed i did. I did one approx 2 hour class in linux so most of this stuff makes absolutely no sense to me "If the extglob shell option is enabled using the shopt builtin"
At this point I am going to quit while I am behind.
But these are not the only forms of wildcards supported by bash. The other forms are referred to as extended globbing and you must enable them before you can use them:
$ shopt -s extglob
Also mentioned in the link in post#8
Quote:
If the extglob shell option is enabled using the shopt builtin
another 2 hours spent on trying to figure out that command
I am not at here - ls | grep “^[a-zA-Z][a-zA-Z]^.*e.*[a-zA-Z]$”
but that will not display any filenames that have the e as the first or second character.... aaaaaaarrrrrrrggggggghhhhhhhh
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.