Files & Directories
Searching
where
searches directories that are defined in the PATH
environment variable.
# cmd only
where cmd.exe
If what we are searching is elsewhere, we must define the path to start searching for and add /R
for recursiveness.
where /R c:\users\ text.txt
find
is used to search for strings within a file or output. The downside is that cannot take wildcards or regex.
# cmd only
find "string" file.txt
# lines that do NOT match
find /V "string" file.txt
# case insensitive
find /I "string" file.txt
# display line numbers
find /N "string" file.txt
findstr
is an upgrade from find
as it accepts regex patterns. Similar to grep
for Linux.
findstr "name" test.txt
Sorting
Prior comparing data, it is best to first sort them.
# CMD only
sort text.txt /O sorted.txt
# reverse
sort text.txt /r
# dedup
sort text.txt /unique
Comparing
# compare two files (byte output)
comp test.txt test2.txt
Comparing test.txt and test2.txt...
Compare error at OFFSET 10
file1 = 2E
file2 = 21
# ASCII output with line numbers
comp test.txt test2.txt /A /L`
Comparing test.txt and test2.txt...
Compare error at LINE 1
file1 = .
file2 = !
fc
differs with comp
as it shows which lines are different instead of individual characters.
# CMD only
fc test.txt test2.txt /N
Comparing files test.txt and TEST2.TXT
***** test.txt
1: My name is x7331.
***** TEST2.TXT
1: My name is x7331!
*****
Last updated