

Python is another scripting language that is used very widely in Ubuntu world. Introduction The Linux file command helps determine the type of a file and its data. With a small script, you can traverse directory tree, push files that contain the desired string into array, and then print it like so: #!/usr/bin/env perlĪnd how it works: $. If you want to view or manipulate an image, you need to identify the file format to choose the proper tool for working with the image. Perl has Find module, which allows to perform recursive traversal of directory tree, and via subroutine perform specific action on them. **/* expansion is a file and whether it contains the desired text: bash-4.3$ for f in. All we need to do is test for whether item in the. bashīash has a very nice globstar shell option, which allows for recursive traversal of the directory tree.
#UBUNTU FIND FILE EXTENSION PDF#
pdf from the /home/sourcedigit:įind /vhome/sourcedigit -name `*.pdf` -deleteīe extra cautious using the delete option with the command.While find command is simplest way to recursively traverse the directory tree, there are other ways and in particular the two scripting languages that come with Ubuntu by default already have the ability to do so. To find a file by name but ignore the case of the query, use the -iname option: find -iname ' query '. This will be case sensitive, meaning a search for query is different from a search for Query. For example, to delete all files ending with. To find a file by name with the find command, you would use the following syntax: find -name ' query '.

To delete all matching files, add the -delete option to the end of the match expression. For example, to search for all files and directories owned by the user sourcedigit:įind / -user sourcedigit Find and Delete Files Similarly, one can easily serach the files by owner, particular user or group, use the -user and -group options. See the following command where we are searching all files in the /home directory that were modified 30 or more days ago:įind /home/sourcedigit -mtime +30 -daystart Simlarly we can search based on the modification date using the -daystart option. I like your answer the most as mine has some other constrains for the filenames and yours is bullet proof. you can also use the -maxdepth option to reduce the search depth. pdf and has been modified in the last five days:įind /home/sourcedigit -name "*.pdf" -mtime 5 type f -name '.' the negates the following expression, here a filename that contains a. See the following example where we will search all files under the /home/sourcedigit directory that ends with. For example, we wiant to find a file which was modified few days ago, but you forgot the name of the file. The most useful aspect of find command it to search for files based on their last modification, access, or change time. tar.gz inside the /home/sourcedigit directory, you would type:įind /home/sourcedigit -type f -name '*.tar.gz' Find Files by Modification Date For example, to find all files ending with. To find files by extension we will use the extension with the command. For example,įind /home/sourcedigit -type f -iname file123.xls Find Files by Extension To remove all files with a specific extension (e.g.data) in the current directory and all subfolders run find. To execute the command in a case-insensitive search, change the -name option with -iname. Note that the command option name is case sensitive by default. For example, to search for a file named file123.xls in the /home/sourcedigit directory, you would use the following command:įind /home/sourcedigit -type f -name file123.xls To find a file by its name, use the -name option along with the find command.

For example it will define the file extension.

type f \ ( -name '.sh' -o -name '.txt' -o -name '.c' \) Find Multiple File Extensions in Linux 3. c extensions, issues the command below: find. expression defines the options, search patterns, and actions for the files to be searched. It is recommended that you enclose the file extensions in a bracket, and also use the \ ( back slash) escape character as in the command.path… defines the starting directory or directories where find will be searched.In other words the type of file to search. options defines the treatment of the symbolic links and optimization method.The general syntax for the find command is find /path/ -type f -name file-to-search
