How to create a file, rename it, then search for the contents within it

A basic Linux tutorial to get you started

·

2 min read

How to create a file, rename it, then search for the contents within it

Hello everyone, welcome to today's Linux tutorial

Today, will be a bit easier. These are the simple commands you can run in your terminal, and in the future you may find them useful.

Let's start!

1.

Before we create the file, we are going to switch into the correct directory. Change into the Documents Folder by running this command:

cd Documents

We are simply changing into this directory since we are creating a text file and it only makes sense to put it in Documents ;)

1.png

2.

To create the file, run this command:

touch (nameoffile).txt

As you can see below, I did

touch SebsTutorial.txt

2.png

3.

After you create it, we're going to edit the file using VIM. Run this command:

vim (nameoffile).txt

3..png

4.

To edit the file, hit the 'i', this will put you in insert mode.

Add the text below

4.png

5.

To save the file, hit the "esc" on the keyboard, and then do :wq to save and quit.

5.png

6.

Now we are going to change the file name. To rename the file, run this command

mv (NameofFile).txt (NewNameofFile).txt

See my example below.

After this, the file name should be changed.

6.png

7.

Now, we are going to use the grep command to search through the contents of the new file.

The literal definition of 'grep' is to search for a string of characters. So basically, search for a word.

In this case, I'm just searching for the letter 'a', but again, when using the grep command, you can search for words.

grep a (nameoffile).txt

7.png

8.

As you can see in the above example, after we grepped for 'a', in the file "TheFox.txt",

The letter was marked in red, indicating that it was found in the file.

Of course, you can search for full words, just as an example, I did the one letter.

Stay tuned for the next tutorial!