How to filter by file type?

QuestionsQuestions8 SkillsProBasic Files OperationsOct, 18 2025
0105

To filter files by type in a directory, you can use the find command or the ls command with specific options. Here are a couple of methods:

Using find

You can use the find command to filter files by type. For example:

  • To find all regular files:

    find . -type f
  • To find all directories:

    find . -type d
  • To find all symbolic links:

    find . -type l

Using ls

If you want to use ls, you can combine it with grep to filter by file extension. For example, to list all .txt files:

ls -l | grep '\.txt$'

This command lists all files and then filters the output to show only those that end with .txt.

Using Shell Globbing

You can also use shell globbing to list files of a specific type directly:

  • To list all .txt files:

    ls *.txt
  • To list all .jpg files:

    ls *.jpg

These methods will help you filter files by type in a directory.

0 Comments

no data
Be the first to share your comment!