1

I recently took a midterm in my Linux class and this one command is bothering me because I thought I had it right.

My question is how would I go about finding all files and folders that start with either an uppercase or lowercase R?

3
  • In a particular directory? or recursively? do you just want to list them - or do something to the matching files? Mar 2, 2018 at 17:23
  • This is what the instructions are: "Find all files and folders in the midterm folder that start with an R (upper and lowercase). A few steps before this, we had to make a directory structure. Here is the what I had for that..:Mkdir –p ~/midterm/linux/{desktops/{GNOME,KDE,LXDE,Xfce},distros/,players/{Andrew\ Tanenbaum,Linus\ Torvald,Richard\ Stallman}}
    – John_R
    Mar 2, 2018 at 17:25
  • Please edit that information into your question Mar 2, 2018 at 17:28

2 Answers 2

2

Assuming you want to search from the root of the file system located at / then I would suggest running the find command such as this

find / -iname "r*"

The command work as followed:

  • find - the search command
  • / - Search root down (including all sub directories starting at root)
  • -iname - Mean run a case insensitive search
  • r* - The r is the letter and the * is a wild card which mean anything starting with r

You could also add an -ls at the end to get a listing of the results. If you don't add an ls you just get the path to the result.

Is this what you are after?

3
  • Close, the instructions that were given to us were find it in the midterm folder. I am not really sure, this whole Linux class is so confusing.
    – John_R
    Mar 2, 2018 at 17:28
  • Okay my apologizes, swap the / for the path to the folder you want to search. Also add the escape as mentioned by the other commenter's.. Mar 2, 2018 at 17:33
  • @PerlDuck is this what I needed to do? find / -iname "r*" Mar 2, 2018 at 17:35
0

Read man find and man 7 regex, then do something like:

find / \( -type d -o -type f \) -iname 'r*'
1
  • Don't -name and -iname use shell globs? directing the OP to the regex manpage is likely to sow confusion Mar 2, 2018 at 17:29

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .