LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This 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


Reply
  Search this Thread
Old 01-07-2015, 01:47 AM   #1
deidei112
LQ Newbie
 
Registered: Jan 2015
Posts: 6

Rep: Reputation: Disabled
linux wildcards LS command need help


i cant find the answer for this please help me

question:
List files that has letter ' r ' to ' t ' in the middle.
 
Old 01-07-2015, 02:10 AM   #2
jdkaye
LQ Guru
 
Registered: Dec 2008
Location: Westgate-on-Sea, Kent, UK
Distribution: Debian Testing Amd64
Posts: 5,464

Rep: Reputation: Disabled
Why would you want to do this? Is this a homework question? You do know how to find the files which have the letter 'r' in the middle, correct? That would be a start to answering the question.
jdk
 
Old 01-07-2015, 02:19 AM   #3
deidei112
LQ Newbie
 
Registered: Jan 2015
Posts: 6

Original Poster
Rep: Reputation: Disabled
yes ughh i cant find the answer i know its simple but its hard i have no proper resources for this
 
Old 01-07-2015, 03:02 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.8, Centos 5.10
Posts: 17,240

Rep: Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324Reputation: 2324
what have you tried so far; we prefer to help you rather than just give you the answer.
 
Old 01-07-2015, 03:05 AM   #5
deidei112
LQ Newbie
 
Registered: Jan 2015
Posts: 6

Original Poster
Rep: Reputation: Disabled
ls [a-q] [r-t] [u-z] i tried to trial and error this code but i cant make r to t
 
Old 01-07-2015, 03:20 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,246

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
I would have more questions than answers:

- Does it only have to have one of the letters r-t
- Are all the files only 3 characters long
- If all 3 letters are to be represented, is the order important
- If all 3 letters are to be represented, may other characters be between them
- Does the middle imply exactly, ie. 'ore' or could it be 'reverse' or are we implying simply not at the start or end
- Does 'list files' also imply that no directories or other types should be listed

As you can see, the current question is quite ambiguous
 
Old 01-07-2015, 03:20 AM   #7
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 3,876
Blog Entries: 1

Rep: Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998
The question is a little ill-defined...

Quote:
List files that has letter ' r ' to ' t ' in the middle
...so you may need to get some clarification before submitting your answer.

But if you take it to mean all files that include one or more of the letters 'r' to 't' between one or more leading and one or more trailing letters, then let's see how to do that...

Do you know how to match 'any' characters in a filename? If not, look up 'wildcard' and 'globbing'. But I'll give you a hint that '*' will match all filenames with one or more characters (not beginning with '.', ignore that for now).

You already seem to know how to express ranges of characters such as [r-t].

So think about how you would match anything followed by 'r' to 't' followed by anything.
 
Old 01-07-2015, 03:27 AM   #8
deidei112
LQ Newbie
 
Registered: Jan 2015
Posts: 6

Original Poster
Rep: Reputation: Disabled
I just want to see the list of all files that has either letter r,s and t in the middle of the file name
 
Old 01-07-2015, 03:32 AM   #9
astrogeek
Moderator
 
Registered: Oct 2008
Distribution: Slackware [64]-X.{0|1|2|37|-current} ::12<=X<=14, FreeBSD_10{.0|.1|.2}
Posts: 3,876
Blog Entries: 1

Rep: Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998Reputation: 1998
Quote:
Originally Posted by deidei112 View Post
I just want to see the list of all files that has either letter r,s and t in the middle of the file name
Can you clearly define "middle" for us?

Case sensitive?

Are all filenames the same length? If so, how long?

Would 'rst' be a valid matched filename?

My point is to have you think more clearly about the problem so that you can think as clearly about the solution.
 
Old 01-07-2015, 03:35 AM   #10
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 805

Rep: Reputation: 186Reputation: 186
By middle do you mean after the first character in the name and before the last character in the name?

If there are 9 file with the following names, which do you want listed?
ranger
arranger
stump
thump
trump
babies
tabby
rest
rust

Think of this and once you have clarity on what you need, the solution should be easy enough.

OK
 
Old 01-07-2015, 03:37 AM   #11
deidei112
LQ Newbie
 
Registered: Jan 2015
Posts: 6

Original Poster
Rep: Reputation: Disabled
hmm.. i think i just needto see the list of file names that has r,s,t in the middle of the file name like for example the word "ARM" we can see that the middle letter of the word is R .and also its in any length

Last edited by deidei112; 01-07-2015 at 03:38 AM. Reason: forgot to put a explanation
 
Old 01-07-2015, 03:42 AM   #12
deidei112
LQ Newbie
 
Registered: Jan 2015
Posts: 6

Original Poster
Rep: Reputation: Disabled
hi anantha i want to see the word arranger
 
Old 01-07-2015, 07:04 AM   #13
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,246

Rep: Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684Reputation: 2684
'arranger' ... cool ... why?

Looking at the list provided I would have thought maybe more than just that one word.
 
Old 01-08-2015, 05:34 AM   #14
AnanthaP
Member
 
Registered: Jul 2004
Location: Chennai, India
Distribution: UBUNTU 5.10 since Jul-18,2006 on Intel 820 DC
Posts: 805

Rep: Reputation: 186Reputation: 186
Dei
Quote:
hi anantha i want to see the word arranger
Do you expect me do your homework?

I said think about and articulate loudly why you want the word arranger and you will be able to write a bash logic for it.

OK
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Using wildcards in a sed command Lokelo Linux - Newbie 17 11-23-2011 09:25 PM
confused about usage of quotes and wildcards in linux joham34 Programming 15 03-07-2011 05:18 AM
Wildcards dazdaz Linux - Newbie 3 01-23-2005 06:33 AM
wildcards with the "rename" command mattn Linux - General 3 05-13-2004 08:43 PM
ls command line, color and wildcards ioio85 Linux - Newbie 1 05-13-2004 06:01 AM


All times are GMT -5. The time now is 11:01 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration