Search

Liko Learns Linux, Episode 3 — Read and Search Files with cat, head, tail, and grep

You’ve learned how to create, copy, rename, and delete files in Linux. In Episode 3 of Liko Learns Linux, you’ll learn how to look inside a text file, preview its first or last few lines, and find the lines that contain a particular word.

Set up the practice file

In a practice folder, use a text editor to save these eight lines as linux_notes.txt. Then open a terminal in the same folder.

Linux makes command-line work easier.
Practice in a separate folder.
Use short, descriptive filenames.
Keep a copy of important notes.
Read a file before editing it.
Linux tools can search text.
Check your results as you go.
Try one new command today.

1. Display the whole file with cat

cat linux_notes.txt

This displays all eight lines in the terminal. Try it when you want to read a short file from start to finish.

2. Show the first three lines with head

head -n 3 linux_notes.txt

The option -n 3 tells head to display three lines from the beginning of the file.

Linux makes command-line work easier.
Practice in a separate folder.
Use short, descriptive filenames.

3. Show the last three lines with tail

tail -n 3 linux_notes.txt

tail uses the same -n option but reads from the end of the file.

Linux tools can search text.
Check your results as you go.
Try one new command today.

4. Find matching lines with grep

grep "Linux" linux_notes.txt

grep prints each line containing the search text. This search is case-sensitive, so it matches Linux with a capital L.

Linux makes command-line work easier.
Linux tools can search text.

Try it yourself

Change -n 3 to -n 2 in either head or tail. Then search for "file" with grep. Does it also find a line containing filenames?

Follow Liko Learns Linux for more hands-on terminal lessons.

Learn Linux with Liko: Create, Copy, Rename and Delete Files

Learn Linux with Liko: Create, Copy, Rename and Delete Files

In the previous lesson, we used pwd, ls, mkdir, and cd to work with directories. In this second lesson of Liko Learns Linux, we’ll use four commands to manage files from the terminal.

  • touch creates a new empty file.
  • cp copies a file.
  • mv moves or renames a file.
  • rm removes a file.

Watch Liko type each command and use ls to show what changed.

Before you begin: Open a terminal in a fresh, empty practice directory so the example filenames won’t conflict with existing files.

1. Create a file with touch

touch notes.txt
ls

touch creates an empty file if the filename doesn’t already exist. The ls output confirms that it’s there.

notes.txt

2. Copy a file with cp

cp notes.txt notes_backup.txt
ls

The first filename is the source and the second is the destination. The original stays in place and a copy appears alongside it.

notes.txt  notes_backup.txt

3. Rename a file with mv

mv notes.txt linux_notes.txt
ls

Because both names refer to the same directory, mv renames notes.txt to linux_notes.txt. The backup keeps its original name.

linux_notes.txt  notes_backup.txt

4. Delete a file with rm

Check the filename before pressing Enter. rm bypasses the Trash, so you can’t restore the file from there.

rm notes_backup.txt
ls

The backup is removed, leaving only the renamed file.

linux_notes.txt

Try the complete sequence

Run these commands one line at a time and check the output after each ls.

touch notes.txt
ls
cp notes.txt notes_backup.txt
ls
mv notes.txt linux_notes.txt
ls
rm notes_backup.txt
ls

Follow Liko Learns Linux for more beginner-friendly terminal lessons you can try yourself.

Four Basic Linux Commands Every Beginner Should Know


 


The Linux terminal may look complicated at first, but you only need a few commands to start navigating the system confidently. In this beginner-friendly video, Liko demonstrates four essential Linux commands: pwd, ls, mkdir, and cd.

These commands help you identify your current location, view files and folders, create a new directory, and move between directories.

1. pwd — Find Your Current Location

The pwd command stands for print working directory. It displays the complete path of the directory in which you are currently working.

Enter:

pwd

Example output:

/home/user

You can think of pwd as asking Linux: “Where am I?”

2. ls — View Files and Folders

The ls command lists the files and folders available in your current directory.

Enter:

ls

Example output:

Desktop  Documents  Downloads  Pictures

This command is useful whenever you want to check what is available in a directory before opening, copying or deleting anything.

3. mkdir — Create a New Directory

A directory in Linux is similar to a folder in Windows. The mkdir command stands for make directory.

To create a directory named linux-practice, enter:

mkdir linux-practice

The command normally produces no output when it is successful. Use ls to confirm that the directory was created:

ls

You should now see linux-practice in the list:

Desktop  Documents  Downloads  linux-practice  Pictures

4. cd — Change Directory

The cd command stands for change directory. It allows you to move from your current directory into another directory.

To enter the newly created directory, use:

cd linux-practice

The terminal prompt may change to indicate your new location. You can also verify it using:

pwd

Example output:

/home/user/linux-practice

Practice Exercise

Open a Linux terminal and enter the following commands one at a time:

pwd
ls
mkdir linux-practice
ls
cd linux-practice
pwd

After completing the exercise, you should be able to:

  • Identify your current directory

  • View files and folders

  • Create a new directory

  • Enter the newly created directory

Command Summary

CommandMeaningPurpose
pwdPrint working directoryDisplays your current location
lsListDisplays files and folders
mkdirMake directoryCreates a new directory
cdChange directoryMoves into another directory

Conclusion

These four commands provide a simple foundation for working with the Linux terminal. Once you are comfortable with them, you can proceed to creating files, copying and moving content, deleting files safely, and understanding Linux permissions.

Try the commands yourself instead of only watching the demonstration. Regular practice is the easiest way to become comfortable with the Linux command line.

Next lesson: Creating, copying, moving and deleting files in Linux.