Please note that Linux doesn't find the oldest file by using the file creation date. The above command returned the following output: 13:42:40.0000000000 /home/sk/ostechnix/Absolute FreeBSD_ 2nd Edition.pdfĪs you see in the above output, Absolute FreeBSD_ 2nd Edition.pdf is the oldest file in /home/sk/ostechnix/ directory. Here, -n 1 indicates only one file i.e oldest file.Īs you might already know, Explainshell helps you to find what each part of a Linux command does. sort | head -n 1 - The sort command sorts the output and sends the output to head command to display the oldest file.-printf '%T %p\n' - Prints the file’s last modification date and time in separated by symbol.type -f - Searches only the regular files.find - Search for files in a directory hierarchy.Let us break down this command and see what each command line argument does. For the whereis command, the list of specific directories can be found in the FILES section of the man pages for the command.$ find /home/sk/ostechnix/ -type f -printf '%T %p\n' | sort | head -n 1 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. The whereis command shows you the location for the binary, source, and man pages for a command, whereas the which command only shows you the location of the binary for the command. Understanding the Difference Between the Whereis Command and the Which Command You can also search for only the source files ( -s ) or for only the man pages ( -m ).įor more information about the whereis command, type man whereis in a Terminal window and press Enter. This is handy because you will most likely search for a program’s executable file more often than you would search for source and man pages for that program. For example, the command whereis -b firefox will display only /usr/bin/firefox as the result. If you want only the path to the executable to display, and not the paths to the source and the man(ual) pages, use the -b option. Therefore, you may want to create the database manually by typing the following command at the prompt: sudo /etc/cron.daily/mlocate The mlocate command does not use the same database file as the standard locate command. NOTE: We will show you a command later in this article that allows you to determine where the executable for a command is located, if it exists. To install mlocate, if it’s not already included in your Linux distribution, type the following command at the prompt. When you install mlocate, the /usr/bin/locate binary file changes to point to mlocate. 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 drive. When you update the mlocate database, it keeps timestamp information in the database. It indexes the entire file system, but the search results only include files to which the current user has access. The mlocate command is a new implementation of locate. In the above example, the backslash disables the implicit replacement of “mydata” by “*mydata*” so you end up with only results containing “mydata.” The most common wildcard symbols are the question mark ( ? ), which stands for a single character and the asterisk ( * ), which stands for a contiguous string of characters. A wildcard is a symbol that can be replaced by one or more characters when the expression is evaluated. The backslash in the above command is a globbing character, which provides a way of expanding wildcard characters in a non-specific file name into a set of specific filenames. If you want to find all files or directories that contain exactly and only your search criteria, use the -b option with the locate command, as follows. locate mydataįor example, the above command found two files containing “mydata” and one file containing “data.” The basic form of the locate command finds all the files on the file system, starting at the root, that contain all or any part of the search criteria.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |