Fundamentals

Creating and editing files

Easy
10 min

You can use the Linux command line at the bottom of the page to practice commands. Finally, solve the given tasks using the same command line.

It is also possible to create and edit files on the command line. When you want to create one or more empty files, you can use, for example, the touch command.

touch file1.txt file2.txt

In the image below, we created a new file using the touch command and confirmed the success of the command by using the ls command.

When you want to see the content of a file on the command line, it is possible to use, for example, the cat command. The cat command comes from the word concatenate, which means to link together or chain together. In practice, the command simply prints the content of the file to the command line.

cat file.txt

In the image below, we tried printing the contents of two different files using the cat command. One of the files was empty and the other one was not.

There are several different editing programs available for editing text-based files, such as vim, emacs, and perhaps the most well-known, nano. nano is the simplest to use and the easiest way to start editing on the command line, so we will use it to edit files in this course.

You can start the nano program by giving it an existing file name. Alternatively, you can also give it a new file name, in which case nano will create the corresponding file.

nano file.txt

The nano- program opens to the command line, allowing you to freely write to a file. When you're ready, you can close the program and save the file by pressing ctrl - x and y + enter. You can check the content of the edited file with the cat-command.

Below is a picture of a nanoprogram.

Training

Let's practice using the nano command. Make sure that the requested files are found in the home folder and that the content of the files is correct.

Exercises

Task 1

Make sure that the file ~/notes.txt exists and that it contains the text "2023 rocks!"

Task 2

Make sure that the file ~/plan.txt exists and that it contains the text "solve all hakatemia challenges!"

hakatemia pro

Ready to become an ethical hacker?
Start today.

As a member of Hakatemia you get unlimited access to Hakatemia modules, exercises and tools, and you get access to the Hakatemia Discord channel where you can ask for help from both instructors and other Hakatemia members.