LS Command – How to List Files Without Directories and Filter by Name

filenamesls

I have a directory called uploads. It contains a bunch of files, plus a few subdirectories which in turn contain files.

Is there a way I can (in one step) do the following:

  1. List ONLY the files in the root uploads directory — I do not want to see the subfolder names or their contents;

    and

  2. Do NOT list any files that start with t_

I know about the -d flag, but it doesn't get me quite what I want.

Best Answer

This sounds like a job for find.

  • Use -maxdepth to only return the current directory, not recursivly search inside subfolders
  • Use -type f to only return files and not directories or device nodes or whatever else
  • Use a combination if -not and -name to avoid the files with names you don't want

It might come together like this:

find /path/to/uploads -maxdepth 1 -type f -not -name 't_*'
Related Question