banner



How To Find The Directory In Linux

Most people use a graphical file director to notice files in Linux, such as Nautilus in Gnome, Dolphin in KDE, and Thunar in Xfce. However, there are several ways to employ the command line to find files in Linux, no matter what desktop manager you lot use.

Using the Find Command

The "discover" command allows you to search for files for which you know the approximate filenames. The simplest form of the command searches for files in the current directory and recursively through its subdirectories that friction match the supplied search criteria. You can search for files by name, owner, group, type, permissions, appointment, and other criteria.

Typing the following command at the prompt lists all files plant in the electric current directory.

discover .

The dot afterward "discover" indicates the current directory.

To notice files that match a specific blueprint, use the -proper name argument. You lot tin use filename metacharacters (such as * ), but you should either put an escape character ( \ ) in front end of each of them or enclose them in quotes.

For case, if we want to find all the files that start with "pro" in the Documents directory, nosotros would use the cd Documents/ command to alter to the Documents directory, and so type the post-obit command:

find . -name pro\*

All files in the electric current directory starting with "pro" are listed.

NOTE: The find control defaults to being case sensitive. If you want the search for a word or phrase to be case insensitive, employ the -iname option with the find control. It is the case insensitive version of the -proper noun command.

If find doesn't locate any files matching your criteria, it produces no output.

The find command has a lot of options bachelor for refining the search. For more information about the observe control, run human being find in a Concluding window and printing Enter.

Using the Locate Command

The locate command is faster than the find command considering it uses a previously congenital database, whereas the notice command searches in the real system, through all the bodily directories and files. The locate control returns a list of all path names containing the specified group of characters.

The database is updated periodically from cron, merely you can besides update it yourself at any fourth dimension and then y'all can obtain up-to-the-minute results. To do this, type the following command at the prompt:

sudo updatedb

Enter your password when prompted.

The basic form of the locate control finds all the files on the file system, starting at the root, that contain all or whatever role of the search criteria.

locate mydata

For case, the above command found two files containing "mydata" and one file containing "data."

If you desire to find all files or directories that incorporate exactly and simply your search criteria, use the -b option with the locate control, as follows.

locate -b '\mydata'

The backslash in the above command is a globbing character, which provides a way of expanding wildcard characters in a not-specific file name into a set of specific filenames. A wildcard is a symbol that tin can be replaced past ane or more than characters when the expression is evaluated. The about common wildcard symbols are the question mark ( ? ), which stands for a single character and the asterisk ( * ), which stands for a contiguous string of characters. In the to a higher place case, the backslash disables the implicit replacement of "mydata" past "*mydata*" so you stop upwards with just results containing "mydata."

The mlocate command is a new implementation of locate. Information technology indexes the entire file system, only the search results but include files to which the current user has access. When you update the mlocate database, it keeps timestamp information in the database. This allows mlocate to know if the contents of a directory changed without reading the contents again and makes updates to the database faster and less demanding on your hard bulldoze.

When you install mlocate, the /usr/bin/locate binary file changes to point to mlocate. To install mlocate, if it's not already included in your Linux distribution, type the post-obit control at the prompt.

sudo apt-go install mlocate

Note: We will prove you a control later in this article that allows yous to determine where the executable for a command is located, if information technology exists.

The mlocate command does not use the same database file equally the standard locate command. Therefore, yous may want to create the database manually by typing the post-obit control at the prompt:

sudo /etc/cron.daily/mlocate

The mlocate command volition not work until the database is created either manually or when the script is run from cron.

For more data well-nigh either the locate or the mlocate command, blazon man locate or man mlocate in a Terminal window and press Enter. The same help screen displays for both commands.

Using the Which Command

The "which" control returns the absolute path of the executable that is called when a control is issued. This is useful in finding the location of an executable for creating a shortcut to the program on the desktop, on a console, or other place in the desktop director. For example, typing the control which firefox displays the results shown in the image below.

By default, the which control only displays the kickoff matching executable. To display all matching executables, apply the -a selection with the control:

which -a firefox

You tin can search for multiple executables using at once, every bit shown in the post-obit image. Only the paths to executables found are displayed. In the example beneath, only the "ps" executable was establish.

Annotation: The which command only searches the current user'south PATH variable. If you search for an executable that is but bachelor for the root user as a normal user, no results will brandish.

For more data about the which command, type "man which" (without the quotes) at the command prompt in a Terminal window and press Enter.

Using the Whereis Control

The whereis command is used to find out where the binary, source, and human page files for a command are located. For case, typing whereis firefox at the prompt displays results every bit shown in the following paradigm.

If you want only the path to the executable to brandish, and not the paths to the source and the human(ual) pages, utilise the -b option. For case, the control whereis -b firefox will display only /usr/bin/firefox equally the result. This is handy because yous will about likely search for a program's executable file more often than you would search for source and man pages for that program. You tin also search for only the source files ( -s ) or for but the homo pages ( -m ).

For more information about the whereis control, blazon man whereis in a Terminal window and press Enter.

Understanding the Difference Between the Whereis Command and the Which Command

The whereis control shows you the location for the binary, source, and man pages for a command, whereas the which command simply shows y'all the location of the binary for the control.

The whereis command searches through a list of specific directories for the binary, source, and man files whereas the which command searches the directories listed in the current user's PATH environment variable. For the whereis control, the list of specific directories tin can be found in the FILES section of the man pages for the control.

When it comes to results displayed past default, the whereis control displays everything information technology finds whereas the which command merely displays the start executable information technology finds. Y'all tin change that using the -a option, discussed before, for the which command.

Because the whereis command only uses paths hard-coded into the command, you may not e'er find what you lot are looking for. If y'all are searching for a plan yous think might be installed in a directory not listed in the man pages for the whereis command, you lot might desire to use the which command with the -a choice to observe all occurrences of the control throughout the system.

Source: https://www.howtogeek.com/112674/how-to-find-files-and-folders-in-linux-using-the-command-line/

Posted by: careydrife1958.blogspot.com

0 Response to "How To Find The Directory In Linux"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel