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.
-bash-3.2$ ls
123 23232 3455
-bash-3.2$ pwd
/home/xkinved/scripts/find
I was trying to list all these files by using the find command with regex option. But i failed, i am doing this as a part of learning "find with regex".
Quote:
-bash-3.2$ find . -type f -regex ^[1-3]*
-bash-3.2$ find . -type f -regex ^[1-3]*$
The above command returned nothing. Help me please.
I tried the above and didnt work. Infact i tried the following too,
find . -type f -regex \(^[1-3]*$\)
find . -type f -regex "\(^[1-3]*$\)"
Somewhere i read, "/\*" portion meant the starting of the expression and "\*/" meant the ending of the expression, but i failed in all
these cases. I tried with all other regextypes too.
So when you read the man page on -regex, did you read it carefully?
Code:
-regex pattern
File name matches regular expression pattern. This is a match on the whole path, not a search. For example, to match a file named `./fubar3', you can use the regular expression
`.*bar.' or `.*b.*3', but not `f.*r3'. The regular expressions understood by find are by default Emacs Regular Expressions, but this can be changed with the -regextype option.
This will not work: '^[1-3].... That is because the found file(s) always start with ./ It is followed by the a file name or directory depending on where the file is located.
If you are standing inside the directory with the files (I do believe that is: /home/xkinved/scripts/find), this would work:
Code:
find . -type f -regex '\./[1-3].*'
It looks for patterns starting with a dot (\.), followed by a forward slash (/) followed by 1, 2 or 3 ([1-3]) followed by any character (.*).
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.