How to find files in Ubuntu? [SOLVED]


Written By - Omer Cakmak
Advertisement

Operating systems have both user-created files and the system's own files. Operating system files are placed in a systematic way. For example, the configuration files are in the /etc/ directory and the log files are in the /var/log directory. Files and system files created by the intervention of users can be moved to different places. Therefore, the need to find files arises.

In this article, we will give you information about searching for files on Ubuntu.

Let's talk about methods for searching files both via GUI and terminal.

 

Method-1: Find Files Using Gnome Files

The Gnome Files application is installed on Ubuntu. Although this application is not, a different application exists in the system to show files and directories. Let's find file.

When the Files application is opened, the directory to be searched is selected from the left menu. At the top, the word/character for the file to be searched is entered and the search icon is clicked.

How to find files in Ubuntu? [SOLVED]


To include hidden files in the search, "Show Hidden Files" is opened as described in the image below.

How to find files in Ubuntu? [SOLVED]


To search under a different directory, click "Other Locations" and select the search directory.

How to find files in Ubuntu? [SOLVED]


Then the word/character is entered for the search. When the character starts to be entered, the search starts synchronously.

Advertisement

How to find files in Ubuntu? [SOLVED]

Information about the search and information about the file are displayed on the screen.

 

Method-2: Find Files Using Catfish

The Catfish application is used to search with a graphical interface. For installation the following command should be run in terminal:

foc@ubuntu22desktop:~$ sudo apt install catfish -y

After installation, the application opens from the menu. It has file type, modify time and hidden file search features. Enter the file name to be searched and press enter.

find files

You can see the found files on the screen.

 

Method-3: Find Files Using find command

Find is the most used application to search for files on the command line. Its usage is as follows:

Usage: find [-H] [-L] [-P] [-Olevel] [-D debugopts] [path...] [expression]

Let's show a few examples:

Example-1: To find the files with the name passwd under the /etc directory, the following find command should be written:

foc@ubuntu22desktop:~$ sudo find /etc -name passwd 
/etc/pam.d/passwd
/etc/passwd

Example-2: To find files larger than 30k in the /boot directory:

Advertisement
foc@ubuntu22desktop:~$ sudo find /boot -size 30k
/boot/grub/i386-pc/bsd.mod
/boot/grub/i386-pc/legacycfg.mod
/boot/grub/x86_64-efi/syslinuxcfg.mod

Example-3: To find passwd files with file type under the / directory:

foc@ubuntu22desktop:~$ sudo find / -type f -name passwd
/snap/core20/1738/etc/pam.d/passwd
/snap/core20/1738/etc/passwd
/snap/core20/1738/usr/bin/passwd
/snap/core20/1738/usr/share/bash-completion/completions/passwd
/snap/core20/1738/usr/share/lintian/overrides/passwd
/snap/core20/1738/var/lib/extrausers/passwd
/snap/core20/1587/usr/share/lintian/overrides/passwd
/snap/core20/1587/var/lib/extrausers/passwd
/usr/bin/passwd
/usr/share/bash-completion/completions/passwd
/usr/share/lintian/overrides/passwd
/etc/pam.d/passwd
/etc/passwd

Example-4: To find files with the word "bash" in their filename in your current directory:

foc@ubuntu22desktop:~$ find . -name \*bash\*
./.bash_logout
./.bashrc
./.bash_history

 

Method-4: Find Files Using locate command

Another application you can use to search for files on Ubuntu is locate. If it is not installed, install it with the following command:

foc@ubuntu22desktop:~$ sudo apt install locate -y

Its standard usage is as follows:

Usage: plocate [OPTION]... PATTERN...

Example-1: To find "passwd" files under the /etc/ directory:

foc@ubuntu22desktop:~$ locate /etc/ passwd
/etc/passwd
/etc/passwd-
/etc/pam.d/chpasswd
/etc/pam.d/passwd
/etc/security/opasswd

Example-2: To find files containing the word bash on the system:

Advertisement
foc@ubuntu22desktop:~$ locate -i  *bash
/etc/apparmor.d/abstractions/bash
/snap/core20/1587/etc/apparmor.d/abstractions/bash
/snap/core20/1587/usr/bin/bash
/snap/core20/1587/usr/bin/rbash
/snap/core20/1587/usr/share/doc/bash
/snap/core20/1587/usr/share/lintian/overrides/bash
/snap/core20/1587/usr/share/menu/bash
/snap/core20/1738/etc/apparmor.d/abstractions/bash
/snap/core20/1738/usr/bin/bash
/snap/core20/1738/usr/bin/rbash
/snap/core20/1738/usr/share/doc/bash
/snap/core20/1738/usr/share/lintian/overrides/bash
/snap/core20/1738/usr/share/menu/bash
/usr/bin/bash
/usr/bin/rbash
/usr/share/bash-completion/completions/ibus.bash
/usr/share/doc/bash
/usr/share/doc/bash/RBASH
/usr/share/doc/util-linux/examples/getopt-example.bash
/usr/share/doc/xz-utils/extra/7z2lzma/7z2lzma.bash
/usr/share/lintian/overrides/bash
/usr/share/menu/bash

The locate command uses a database. This database needs to be updated regularly. Run the following command in terminal to update the database:

foc@ubuntu22desktop:~$ sudo updatedb

Database(s) are under the following directory:

foc@ubuntu22desktop:~$ ls /var/lib/plocate/
CACHEDIR.TAG  plocate.db

To use a different database, enter the -d parameter:

foc@ubuntu22desktop:~$ plocate bashrc -d /var/lib/plocate/plocate.db

 

Method-5: Find files using grep command

grep is actually used to search for text within files. However, it lists the files in which the searched word occurs. In this respect, it is a file search command.

The standard usage is:

Usage: grep [OPTION]... PATTERNS [FILE]...

Example-1: To find files that contain bashrc in your current directory:

foc@ubuntu22desktop:~$ grep -ri "bashrc" . 
.profile:    # include .bashrc if it exists
.profile:    if [ -f "$HOME/.bashrc" ]; then
.profile:	. "$HOME/.bashrc"
.bashrc:# ~/.bashrc: executed by bash(1) for non-login shells.
.bashrc:# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
.bashrc:# sources /etc/bash.bashrc).

Example-2: To find out which lines the bashrc statement is in in the found files, the -n parameter is entered:

foc@ubuntu22desktop:~$ grep -ri "bashrc" -n
.profile:13:    # include .bashrc if it exists
.profile:14:    if [ -f "$HOME/.bashrc" ]; then
.profile:15:	. "$HOME/.bashrc"

Example-3: List only the filenames of files that contain bashrc:

foc@ubuntu22desktop:~$ grep -ri "bashrc" -l
.profile
.bashrc

 

Method-6: Find files using ACK command

Although it is not very well known, there is another command you will use in Ubuntu. Install the ACK to the system:

foc@ubuntu22desktop:~$ sudo apt install ack -y

The standard usage is:

Advertisement
Usage: ack [OPTION]... PATTERN [FILES OR DIRECTORIES]

Example-1: Files containing the word bashrc in the directory you are in are displayed together with the line numbers of the file contents:

foc@ubuntu22desktop:~$ ack bashrc
.profile
13:    # include .bashrc if it exists
14:    if [ -f "$HOME/.bashrc" ]; then
15:	. "$HOME/.bashrc"

.bashrc
1:# ~/.bashrc: executed by bash(1) for non-login shells.
109:# this, if it's already enabled in /etc/bash.bashrc and /etc/profile
110:# sources /etc/bash.bashrc).

Example-2: Use the -l parameter to list only files that contain bashrc:

foc@ubuntu22desktop:~$ ack bashrc -l
.profile
.bashrc

Example-3: To find in subdirectories as well:

foc@ubuntu22desktop:~$ ack -r "bash" -l
.bash_logout
.profile
.bashrc

 

What is NEXT?

 

Summary

In this article, we have shown different methods of finding files in Ubuntu. You may have heard of some recently. You may need more details, especially about console commands. You can use the following command to access local manual files:

foc@ubuntu22desktop:~$ man find

Instead of find, you can type the command you want to reach the manual pages.

 

References

stackoverflow.com - How to find all files containing specific text (string) on Linux?
askubuntu.com - Find a file by name using command-line

 

Didn't find what you were looking for? Perform a quick search across GoLinuxCloud

If my articles on GoLinuxCloud has helped you, kindly consider buying me a coffee as a token of appreciation.

Buy GoLinuxCloud a Coffee

For any other feedbacks or questions you can either use the comments section or contact me form.

Thank You for your support!!

Leave a Comment