Read A File
Part of the Fundamentals section of Coddy's Terminal journey — lesson 11 of 82.
The
The contents of the file will be printed to the terminal immediately.Other useful ways to read files:
You can control how many lines to show with the
Note:
cat command is short for concatenate, which means to link things together. While its original purpose was to join files, its most common use today is to read and display the contents of a file directly in the terminal.Simply type cat followed by the filename:cat readme.txtThe contents of the file will be printed to the terminal immediately.Other useful ways to read files:
head — displays only the first 10 lines of a file:head readme.txttail — displays only the last 10 lines of a file:tail readme.txt-n option:head -n 5 readme.txt # show first 5 lines
tail -n 3 readme.txt # show last 3 linesless — opens the file in a scrollable viewer. Press q to quit:less readme.txtcat is best for short files. For long files, less is more comfortable to read.Challenge
BeginnerUse the cat command to read and display the contents of readme.txt.
Hint: Type
catfollowed by the name of the file you want to read.
Try it yourself
Terminal
This lesson includes a short quiz. Start the lesson to answer it and track your progress.
All lessons in Fundamentals
4Directories
Create A DirectoryCopy A DirectoryMove And Rename A DirectoryDelete A DirectoryRecap - Directory Operations7File Content
Head And TailWord CountSort CommandUnique CommandGrep BasicsGrep With FlagsRecap - Text Detective2Navigation
Print Working DirectoryList FilesChange DirectoryAbsolute vs Relative PathsHome And Root DirectoryRecap - Find Your Way8Redirection
Standard OutputOverwrite To A FileAppend To A FileStandard InputStandard ErrorRecap - Log Builder6Wildcards And Patterns
The Star WildcardThe Question Mark WildcardBracket WildcardsCombining WildcardsRecap - Selective Operations9Piping
What Is A PipeChaining Two CommandsChaining Multiple CommandsPipe With GrepRecap - Data Pipeline