Being a computer user, we all work with different types of files quite often.
However, at times, there is such a large number of files on our computer system that it gets nearly impossible to keep the names of all those files at your fingertips.
At times, you even tend to forget if a certain file exists on your system or not.
In these situations, we try to look for the different ways in which we can find files in our system.
Here at LinuxAPT, as part of our Server Management Services, we regularly help our Customers to perform Debian related queries.
In this context, we shall look into methods to find files in a Debian 10 system.
To begin, we will be creating a sample text file for demonstrating all the methods that are listed below. A text file in Debian 10 can be created with the following command:
$ sudo nano TextFile.txt
Here, you can replace 'TextFile' with any name of your preference.
Running the above-mentioned command will also open the newly created file with the nano editor. Here, you can type in any random text.
This text is not that important since we are just going to use this file for demonstration. Our sample text file with some random content such as:
Sample Text File
After creating this file, now we will use the three different methods below to find this file in Debian 10.
The "whereis" command in Debian 10 is essentially used to trace the exact path of any specified file.
However, this command can also be used indirectly to find a file in Debian 10 because this command will display the paths of only those files that actually exist in your system.
Therefore, to find our sample text file named TextFile.txt, we will run the following command:
$ whereis TextFile.txt
Since we have created our sample text file in the Debian 10 Home directory, therefore, you will be able to see a colon after the file name in the output of this command.
However, if your sample file or any other file that you are trying to locate resides in some other directory, then the above-mentioned command will display its exact path.
The "find" command in Debian 10 is extremely versatile in terms of the options that can be used in conjunction with this command to find files as per our requirements.
If a file you are looking for actually exists in your system, then the "find" command will return its name.
Otherwise, it will not display any output.
The "find" command in its simplest form is used as follows where we are trying to check whether the text file named TextFile.txt exists in our Debian 10 system or not.
$ find TextFile.txt
Finally, there is a GUI based method too with which you can easily search for any specific file if you do not want to use the Debian 10 terminal.
i. To use the GUI of a Debian 10 system to search for files on it, you simply have to go to its file manager by looking for its icon on the Debian 10 taskbar.
ii. Once you are there in the Debian 10 file manager, you need to click on the search icon.
This will allow you to type in the name of the file you are looking for in the appeared search bar.
iii. We have simply typed "TextFile" in that search bar and our Debian 10 system has displayed our file TextFile.txt.
In the very same manner, you can look for any desired file in Debian 10 using its GUI.
This will also confirm if a certain file exists on your system in the first place or not.
This article covers the different methods of finding files in Debian 10.
To find a file in Debian:
Use the Locate command
1. Debian and Ubuntu sudo apt-get install locate.
2. CentOS yum install locate.
3. Prepare locate command for first use. To update the mlocate.db database before first use, run: sudo updatedb.
To use locate, open a terminal and type locate followed by the file name you are looking for.
To locate a file in Linux:
1. find . - name thisfile.txt. If you need to know how to find a file in Linux called thisfile.
2. find /home -name *.jpg. Look for all . jpg files in the /home and directories below it.
3. find . - type f -empty. Look for an empty file inside the current directory.
4. find /home -user randomperson-mtime 6 -iname ".db".
To find packages in Debian:
You can also search for a package using the aptitude Ncurses user interface.
1. Type 'aptitude' in the terminal and the following interface will be displayed in the window.
2. To search for a package, press '/' and then type the package name into the search bar.
How to use grep to find a file?
The grep command searches through the file, looking for matches to the pattern specified.
To use it type grep , then the pattern we're searching for and finally the name of the file (or files) we're searching in.
The output is the three lines in the file that contain the letters 'not'.
To list files in Linux:
The easiest way to list files by name is simply to list them using the ls command. Listing files by name (alphanumeric order) is, after all, the default.
You can choose the ls (no details) or ls -l (lots of details) to determine your view.
Which command have more searching options to search a file in file system in Linux?
Grep is a Linux / Unix command-line tool used to search for a string of characters in a specified file. The text search pattern is called a regular expression.
When it finds a match, it prints the line with the result.
The grep command is handy when searching through large log files.
grep is a command-line utility for searching plain-text data sets for lines that match a regular expression.
Its name comes from the ed command g/re/p (globally search for a regular expression and print matching lines), which has the same effect.
To grep recursively in a directory:
To recursively search for a pattern, invoke grep with the -r option (or --recursive ). When this option is used grep will search through all files in the specified directory, skipping the symlinks that are encountered recursively.