JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM >

Searching for files recursively in Linux

Author:JIYIK Last Updated:2025/04/20 Views:

In this Linux article, we will learn how to find files recursively in Linux. We will also see how to search files recursively in subdirectories in Linux systems.

We will use different Linux commands in many ways. We will learn them one by one.

treeIn Linux, our directories have subdirectories and files, so when we want to find a file, it is best to use a recursive method. We use the command to recursively find files in Linux .

The easiest way to view a list of files and subdirectories in a directory is to use the command in Linux tree. This command lists the files in a directory and generates a file listing.

When we use treethe command without providing any arguments, it will only list the files in the current directory. When treea directory argument is provided with the command, it will list all the files and subdirectories found in each round.

When the listing of files and subdirectories is complete, treethe command returns the total number of files and subdirectories listed in the particular directory. We will see this in more detail in our examples.

Before using treethe command, you have to install it using this command in the Linux terminal.

$ sudo apt install tree

With the command program installed tree, we can now use it to recursively find files and subdirectories.

$ tree -a

When we use the above command in Linux, it will display all the files and subdirectories and print the total number of files and subdirectories in our Linux operating system.

Use the tree command with the -a option

Output of the command:

Use tree -a to recursively return all files and subdirectories

As shown in the above figure, tree -athe command displays all files and subdirectories and returns the total number of files and subdirectories.

Now, if we want to find files recursively in a particular directory, we use the following command.

$ tree Desktop

In the above command, we have given a single treeargument with i.e. Desktopin this case, Desktopis the directory we have specified, in which we want to recursively find files.

Running the above command in the terminal will display all the files and subdirectories under the Desktop directory.

Using tree command with parameters - Desktop directory

Output of the command:

Use the tree command to display all files and subdirectories on the desktop

As we can see, tree Desktopthe command displays all the files and subdirectories in the Desktop directory and returns the total number of files and subdirectories as shown in the above figure.

treeWe hope this article helped you learn how to recursively find files and subdirectories in Linux using command.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Git list remote branches

Publish Date:2025/04/20 Views:54 Category:OPERATING SYSTEM

This article will show you how to list remote repositories from your local branch. A remote repository is a project hosted on a server, such as Github/Gitlab. git remote Allows us to use short names (aliases) to execute commands instead of

Update the repository remotely by setting

Publish Date:2025/04/20 Views:120 Category:OPERATING SYSTEM

In this tutorial, we will discuss how to set up the central repository as a remote for our local repository so that our branch is updated whenever the central repository changes. We should always perform this step before making edits to our

Rename Git repository

Publish Date:2025/04/20 Views:100 Category:OPERATING SYSTEM

In this article, we will discuss renaming Git repositories. We can explain this in different ways. It can rename the displayed name, the repository on GitHub, or the folder of the repository. We will discuss these and go through the steps w

Creating tags in a Git repository

Publish Date:2025/04/20 Views:117 Category:OPERATING SYSTEM

In this tutorial, we will discuss how to create tags in a Git repository. Creating tags in a Git repository In Git, we may want to mark certain commits or specific points in the history of the project repository. To do this, we can use the

Push Git tags to remote repositories

Publish Date:2025/04/20 Views:177 Category:OPERATING SYSTEM

If you create a git tag locally, your intention must be to share your changes with your team for easy tracking. Commit is one of the common operations to share changes. But another sharing and tracking idea added to it is Git Tags. This art

Ignore untracked files in Git

Publish Date:2025/04/20 Views:162 Category:OPERATING SYSTEM

This article will discuss two methods that can be used to ignore untracked files in a Git repository. If there are multiple untracked files and folders in your local repository, running the git status command will output many lines. Let’s

Ignore everything except certain files in Git

Publish Date:2025/04/20 Views:151 Category:OPERATING SYSTEM

This article outlines the steps to make Git ignore all but a few files in a Git repository. The .gitignore file is a useful Git utility that allows us to tell Git which files to track and which files not to track. If you want your .gitignor

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial