How To Find A File In Ubuntu Terminal
One typical upshot when working with computers is that you tin't find the files you've saved somewhere. Many GUI programs let you to search for files while working under Linux, contained of distribution. Even so, in some situations, you will only accept access to the command line terminal, peculiarly if you manage servers or use SSH to access the organization. If you can't detect your files, y'all must use command-line programs on Linux to wait for them.
This tutorial will show you how to utilize the Final, which is the command-line program in Ubuntu OS, to notice files. On the shell, at that place are three well-known ways for searching for files:
- Discover files using Find command
- Using Locate command to find files
- Using Grep control to search in files
Find and Locate commands are used to search for the files in the system while grep is used to search file based in the text that it contains. Find is a slower method just contains several search weather while Locate does non include equally many conditions merely is much faster than the Find.
Let us get started with the procedure. Nosotros volition employ Ubuntu xx.04 LTS for describing the procedure mentioned in this article.
Method i: Using Find control
Observe is a highly flexible command used to search files based on a diversity of conditions. Information technology is a very helpful tool when searching a file for which y'all do not remember the name of the file. Using the Find command you lot can search based on file and folder name, cosmos date, modification date, and permissions. You can combine these multiple conditions in a one Find command. Information technology is a very powerful but slower search tool.
The general syntax of the control is:
$ find /path/to/file/ -iname filename
Search files in a specific directory
Y'all can use the Find command to search for all files in a specific directory. The full general syntax would be:
$ find /path/to/file/
For instance, to discover all the files nether the /home/tin/Downloads/ directory, launch the Terminal by pressing Ctrl+Alt+T and then run the following control in Last:
$ find /domicile/tin/Downloads/
Search files in the current directory
To search for files in a current directory, use
$ find .
To search for a file named e.g "softwares" under current directory, use the following command in Terminal:
$ detect . -iname Softwares
Search using a wildcard
You can also utilise the wildcard characters to observe the files that friction match the query. The full general syntax would be:
$ discover /path/to/file/ -iname filename*
For instance to search files that start with the give-and-take "cent", run the following command in Terminal:
$ find /abode/tin/ -iname cent*
Search for empty files
Y'all tin can also search for empty files using the Observe command. The full general syntax would be:
$ notice /path/to/file/ -iname -empty
For instance to observe empty files under the /dwelling/tin directory, run the following control in Terminal:
$ notice /dwelling house/tin/ -empty
Search based on date and time
Using Notice control, yous can also search for files depending upon when they were admission or modified. In that location are types of time you can use to search files:
- mtime (Modification time): when the file's content was modified last fourth dimension.
- atime (Access time): when the file was accessed last time.
- ctime (Change time): when the file attributes were modified concluding time.
For instance, to search for files in a electric current directory that were modified less than 2 days ago, run the following command in Terminal:
$ notice . -mtime -2
To search for files that were accessed less than ii days ago, run the post-obit command in Terminal:
$ find . –atime -2
To search for files that were changed less than 2 days ago, run the following command in Terminal:
$ find . –ctime -two
Search based on file size
For instance, to search file whose size is larger than 5MB size, nosotros tin can use the following command in Terminal:
$ detect . –size +5M\
Search based on file permissions
It is used to detect files with specific permission. The general syntax would exist:
$ find /path/to/file/ -blazon -perm mode
Where:
Type parameter includes d or f value that are used for specifying type of the file. d for directories and f for files only.
mode can be either with numeric permission (e.m 777, 655.. etc) or symbolic permission (e.g u=x, a=r+10).
For instance, to search for a file with the permission of 644, we can use the following command in Last:
$ find . –blazon f –perm 644
Method 2: Using Locate command
At that place is another command Locate that tin can be used to search files in Linux. It does not take as many search conditions equally the Find utility offers but it is much better and faster than the Detect utility. The reason behind is the background process that really runs in your system and searches and stores new files in its ain database. Unlike Find command, information technology does not search your local hard disk for files and directories merely instead, it searches them in its own database. Its database should be regularly updated for the search utility to work.
Installing Locate
Locate is not installed by default in the Linux Os. You volition need to manually install it. Press Ctrl+Alt+T to launch the Terminal and then type the following command equally sudo to install the Locate utility:
$ sudo apt-get install locate
One time the installation is completed, you lot can apply the Locate utility right abroad.
The general syntax of the command is:
$ locate –i filename
Where -i is used to ignore example distinctions.
Searching for a file
For instance, to search for a filename "centos", use the following control in Concluding:
$ locate –i centos
It will search for all the files that include the string "centos" in their filenames.
Search for Multiple files
You lot tin can too search for multiple file names simultaneously. For instance, utilise the following command in Terminal to search for 2 files "sdn.txt" and "centos":
$ locate –i sdn.txt centos
Search using Wildcard
You tin also use the wildcard character to observe the files that match the query. For example to search for all the files that ends in ".iso", use the following command in Terminal:
$ locate –i *.iso
Update locate database
Locate control relies on its database to work, then information technology needs to be updated regularly. Run the following command in Concluding to update the Locate utility database:
$ sudo updatedb
Method three: Using Grep command
Although Grep is not for directly searching files in your system, instead information technology is used to search text. Nevertheless, you can apply it to display the names of files that contain the particular string of characters that matches your search query. To search for a string, y'all must enclose it in double quotes.
The general Syntax of the command is:
$ grep [options] [design] [/path/to/file]
where [options] parameter contains generic options to command the search and [design] contains string that we desire to search.
If yous are looking for a file that contains a word, which yous suspect might be in your any specific directory, you tin can search for it using the above command syntax in Terminal.
For instance, to search for a file that contains the word "tintin" and we recollect that file might be in our Downloads folder, nosotros can use the post-obit command to locate that file.
$ grep -r –i "tintin" /dwelling house/tin/Downloads
Where
-i is used to ignore case distinctions
–r is used to search for the specified directory recursively
Search for Multiple words
You can also search for multiple strings simultaneously. You have to use backslash "\" and pipe sign "|" characters amongst your strings.
For instance to search for two strings "tintin" and "ping", we can use the post-obit command in Terminal:
$ grep –r –I "tintin\|ping" /home/tin/Downloads
So, that was the brief overview of how yous can search for files using the command line in Ubuntu. In this article, nosotros have seen three useful command line methods to search for files. You can choose any 1 of these methods depending upon the search speed and atmospheric condition.
Source: https://vitux.com/how-to-find-files-on-the-ubuntu-command-line/
Posted by: bailesbuteatelf38.blogspot.com
0 Response to "How To Find A File In Ubuntu Terminal"
Post a Comment