≡ Menu

Read file from command line

We can read a text file from command line using type command. This command is similar to cat command on Linux.

Example: Let us print the contents of the file c:\boot.ini

C:\>type c:\boot.ini
[boot loader]
[operating systems]
multi(0)disk(0)rdisk(0)partition(2)\WINDOWS="Microsoft Windows XP Home Edition"

If the file is very huge, we can use more command to read the data one page at a time. This more command is pretty much similar to the Linux more command.

Syntax of the command is:

more filename

This command prints one page text on the console and waits for the user to press Enter before it shows the next page.

The above explained commands work in Windows 7, Windows 10 and all Server editions

7 comments… add one
  • Anonymous

    Very thanks! :)

  • Anonymous

    Is there any command to read only the last two lines of a file?

  • Techblogger

    We can do it using tail command. Read the post Tail command for windows

  • jinei


  • Connor

    How can you test for a line and then run a command that if text that matches that string, run a command. Sorta like if specified text is on this line, run a command.

    • admin

      What’s the input to the command you want to run? is it the file having the string or the line that’s matching the string? If it’s the latter case, you would need to have a script i think.

      If the input is file, you can use below command.

      for /F %i in ('findstr /M pattern fileName') do command %i

      The above is executed only on one file. If you want to run this on all the files in current folder

      for /F %i in ('findstr /M pattern *') do command %i
  • MingYao

    http://puu.sh/luPZx/eaa285c0cf.png as you see i typed the commands using CMD run as admin and it is still telling me Access is denied. What can I do to delete this directory?

Leave a Comment