How to Change File Attributes – (ATTRIB, Windows Command Line, CMD, DOS)
File attributes grant or deny certain rights to every file and folder. The attrib command can be used to view or change file attributes on files or folders.
Welcome!
This guide is all about locating files folders or strings using the Find command in the Windows Command Line (Cmd).
Lets get started!
While windows has some search capabilities from the GUI, searches are usually quite slow and they can not search within the contents of any files.
Often however it might be necessary for you to locate a file based on the text within it, such as for example when you don’t remember the name or location of a specific file but remember what was written within it.
That’s where the command find comes in.
You can use the find command to search for a file based on the contents inside it.
Alternatively, in a similar fashion, you can use the find command to find where a string is located within multiple files.
The find command is especially useful for programmers, writers or people that use lots of files in a frequent basis.
An alternative to the find command is findstr. The difference being that findstr has more search options and includes support for regular expressions, which makes it similar to the grep command in linux.
If you would like to follow along, open your command line and navigate to a directory of your choice (i.e. Desktop) and use the echo command along with a redirector to create two files.
echo Awesome > File1.txt & echo awesome > File2.txt
Two files should immediately be created in you current directory.
Now that our files have been created lets learn how to locate them using the FIND command.
To use the find command to check whether a file contains a specified string simply type “find” followed by the text you want to search for within quotes and the location or name of your text file.
Find "Awesome" "File1.txt"
Your file should be located at once.
If the string was found within your file the command line will output the name of the file and the string below it.
If the find command did not manage to find your text even tho you are sure that it is contained within your file, try using the /i parameter, which will ignore whether or not the case of the characters in the file is different from the ones in the provided string.
Find /I "Awesome" "File2.txt"
Your file or string should be located at once.
But what if we want to search within multiple files at once?
To search for a string inside multiple documents either enter the names or the locations of your text documents one after the other.
Find /I "Awesome" "File1.txt" "File2.txt"
Or alternatively take advantage of wildcards to search through every text document in a directory.
Find /I "Awesome" *.txt
Using wildcards you can even restrict your search to files that contain a specific word within their name.
Find /I "Awesome" *File*.txt
In this example the find command will only search through text files that have the word “file” in their name.
So far we have been using the find command to locate files based on their contents, but what if we want to search for where a specific word or phrase is located within a single or multiple files?
To do so we would have to use the /n parameter which shows us the number of the line in which our string was found at.
Find /N /I "Awesome" *.txt
The number of the line in which the specified word or phrase was located at will immediately appear in our output.
Since both the name of the file that the string was found at as well as the location of said string is displayed with the use of the /n parameter, you can use the find command to search for both files that contain a string as well as strings within files.
Searches for the word “Awesome” within the “Document.txt” file while ignoring any casing differences.
Find /I "Awesome" "Document.txt"
Searches every text document in the current directory for the word “Awesome”.
Find "Awesome" *.txt
Searches for the word “Awesome” within every text file in the desktop directory (replace with your computers name).
Find "Awesome" "C:\Users\\Desktop\*.txt"
Displays the number of the line in which the word “Awesome” was found at within the “Document.txt” file while ignoring any casing differences.
Find /I /N "Awesome" "Document.txt"
Displays the every line that does not contain the specified string within the “Document.txt” file.
Find /V "Awesome" "Document.txt"
Displays how many times the string was found in the specified file.
Find /C "Awesome" "Document.txt"
Searches for a text string in a file or files.
FIND [/V] [/C] [/N] [/I] [/OFF[LINE]] "string" [[drive:][path]filename[ ...]]
/V Displays all lines NOT containing the specified string.
/C Displays only the count of lines containing the string.
/N Displays line numbers with the displayed lines.
/I Ignores the case of characters when searching for the string.
/OFF[LINE] Do not skip files with offline attribute set.
"string" Specifies the text string to find.
[drive:][path]filename
Specifies a file or files to search.
If a path is not specified, FIND searches the text typed at the prompt
or piped from another command.
You now know how to use the Find command to locate files and strings from the Windows Command Line.
If you liked this short guide take a look at a few of our other posts related to the windows command line, or if you really liked it consider enrolling in our video course where you will learn the ins and outs of the Windows command Line.
This course has everything you need to start learning about the windows command line along with batch scripting.
File attributes grant or deny certain rights to every file and folder. The attrib command can be used to view or change file attributes on files or folders.
Easily create one or many folders/directories from the command prompt (cmd), with just a few simple commands.
The most useful commands, tips, tricks and hacks you can use to increace your efficiency and productivity with the command prompt (cmd).
Learn the Windows command line And Become an Expert!