pwd : ../bin under bin I have a directory called datafiles.

Use meta characters and the ls -lL command (with lower and upper case L) to list all filenames under the datafiles directory that contain a dot . with the letter 'f' or 'u' anywhere after the dot.

I tried: ls -lL datafiles *.*f*u

ls -lL datafiles .[f*u]

Thank you for answering. Unfortunately, none of the solutions worked the way I wanted it.

By clarifying the question, /bin/datafiles/file.backup is the root to the directory. From the /bin directory, the command I used is ls -lL datafiles followed by meta characters.

I'm looking for file.backup that has a dot and followed by f or u, not directly followed by f or u (anywhere after the dot), and not ending by f or u.

  • Why do you think this is the syntax? man ls will tell you it takes only a list of files, not a directory then a filename pattern (a.k.a. glob). – Mikel Sep 13 '14 at 0:40
  • Just use John1024's answer but give the correct path: ls -lL datafiles/*.*[fu]*. – terdon Sep 13 '14 at 1:07

This looks for files in the data directory that contain a dot followed by f or u but not ending in f or u:

ls -lL datafiles/*.*[fu]*[^fu]

Answer to version 1 of this question

You wrote "f or u". To write that in a glob, use [fu]. To also insist that the f or u be preceded by a dot, try:

ls -lL .*[fu]* *.*[fu]*

The first glob above, .*[fu]*, expands to files that start with a dot (which means that they are normally 'hidden'). The second, *.*[fu]*, expands to files that have a dot somewhere in the name but do not begin with dot.

The hidden files generally serve as configuration files for various programs. If you don't want to see them, and one usually doesn't, then omit the first glob and use simply:

ls -lL *.*[fu]*

More on globs

  • *.*f*u expands to a file name that contains a dot followed (not necessarily immediately) by an f and ends with a u. In other words, this glob requires that both f and u be present in the filename and that they appear in the order f then u.

    Normally, * means zero or more of any character. As a special case, the above does not match files that start with a dot because such files are, by convention, "hidden."

  • .[f*u] expands to a file name that consists of a dot immediately followed by one of the characters f, *, or u (and nothing else after that). Because the star is inside the square brackets, it loses its usual meaning of zero or more characters and becomes a literal *.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.