Linux Commands | Introduction to Linux | Basic Linux Commands
Check the Total Number of Words and Lines in a File
wc [option] [file path/name to inspect]
wc stands for word counts. It shows totals such as the number of words and lines in a file.
Options
- -l lines
- -w words
Check the Absolute Path of a Linux Command
which [Linux command]
which shows the absolute path of a Linux command.
Search for a Specific Pattern in a File
grep [pattern] [file name to search]
grep tells you where a specific pattern appears in a file.
Pattern example: “dump”
Change the Current User
su [ID]
su stands for substitute user. It changes the user account currently being used. (ID change)
Specify Input and Output
> or >> [input/output device]
Redirection lets you directly specify an input or output device.
cat test.txt > 1.txtoverwrites1.txtwith the output ofcat test.txt.cat test.txt >> 1.txtappends the output ofcat test.txtto1.txt.- The command
cat test.txtis equivalent tocat test.txt >. If nothing follows>, the output is printed to the screen.
Run Linux Commands in Sequence
| (the character next to the Backspace key)
A pipeline connects Linux commands. It is used when running several commands together.
For example:
cat test.txt | head -1