Linux Search For File Through Terminal




File search that usually I do is locate files based on the name of the file with the command:
find / -name namefile.txt

Find = is search orders
/ = Search directory
-name = name as key parameters determination

Based on the results of information browsing with google, I found that:
  • There are some search applications.
  • Search for files with a specific name.
  • Search for files with a specific type.
  • Search for a file with a specific size.
  • Search for files owned by the user.
  • Perform the action for the search results.
  • Search for files with specific access rights
  • And many other sophisticated
This time I will try to explain it

Some kind of search applications on linux
whereis
whereis specifically used to locate the file binary, source and manual page. use enough with the command "whereis name program"

Locate
locate command is used to search for files based on the database used updatedb. using them more widely and common than whereis


find
the find command this is the command to use.
 
Search for a file by name
Perhaps this is one of the most widely used IE search for files based on their name. On this search we can use wildcard character such as. For example we want to search for files that contain the letter e in the name of the file:
# find ~ -name "*e*"

and this is an example where we look for files with two characters where the first character is "free" and the second character of his "e" then the injunction will be like this:
# find -name "?e"

This is a frequently used search by me and maybe you too will often use it. Now what if we want to find a file in a specific folder, in our example will search for the file in the folder or the file name starts with ' C ' then his command like this:
# find ~ -name "C*"

If we want to search for files on specific directories then the first argument is the directory we will find then search will be done on that directory to sub dirktori below.

Search for files with a specific type
The find program could also be used to search for files based on the type of example we will be looking for a certain directory - directory under "/usr/local/" then the injunction as follows:
# find ~ -type d

And if we want to know how many directories on the "/usr/local/" we just ping command earlier to the program wc.
# find /usr/local/ -type d | wc -l

the intended file type extension is not here but the file type and we already know one command to search for files of type directory, in the following example we will look for a file of type block special in the directory "/dev/" but who has a name the file begins with "hda":
# find /dev/ -type b -name "hda*"

We combine the above argument type and name and means you already understand how to use the find with two arguments. For notation of the file types recognized by linux will be described as follows:

b = to block special
c = for character special
d = for a directory
p = to fifo
f = for regular files
l = to symbolik links
s = for socket

Search for a file with a specific size
This search is also one of the frequently used especially by an administrator to search for a file that is empty or that is too large for the system. In the example below we will search for files that are 0 bytes:
# find /tmp/ -empty

The result of the above command is the file size is 0 bytes (empty) or an empty directory (that there are no files in it) so don't be surprised if the results there are many directories. The following example is a search on the folder "/home" the file size more than 200 KB, the orders are:
# find ~ -size +200k

The following command we will look for the file in the bin folder, measuring less than 10 KB and a regular file type, the orders are:
# find /bin/ -size -10k -type f

We already discussed the files less than and more than. We now search for files whose size was certainly we specify, his command as follows:
# find /bin/ -size 10k -type f

We do not use " + or - " to search for files with a size that's for sure. Now how about a search for files whose size between or within a certain range, his command as follows:
# find /bin/ -size +10k -size -20k

From last we look for files with a size of Kilobytes that a file how to find another unit, are some examples of arguments that can be used:

b = for blocks 512 bytes
c = to byte
w = for word
k = for kilobytes (1024)
M = for mega byte (1048576)
G = for giga byte (1073741824)

Search for files owned by the user.
Search the user ownership of files based on the file using the command:
# find / -user root -name "*.iso"

Perform the action for the search results
In searching files and make changes towards invented file we can use the command:

Delete a file ending in .ISO that is present in the home folder, to the subdirectory
find ~ -name “*.iso” -exec rm -rf {} \;

Move files ending in .ISO that exists in the test folder, to the subdirectory to the folder backups
# find . -name "*.iso" -exec mv  {} /root/backup/ \;
Search for files with specific access rights
The files world-writable file system, especially, can be a security hole if a cracker gained access to your system and modify it. In addition the directory world-writable is dangerous, because it allows crackers to add or remove files according to his desire. To search the whole world-writable files on your system, use the following command:
# find / -perm -2 -print

and make sure you understand why the file is world-writable. In normal operation, there are some files writable, including some of the "/dev", and symbolic links.



Next
Previous
Click here for Comments

0 comments: