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
.txtfiles:ls *.txt -
To list all
.jpgfiles:ls *.jpg
These methods will help you filter files by type in a directory.
