fbpx
Linux 101

Your first Linux commands – Lesson 8 – Creating files and making them executable

In this lesson we will work with vi, mkdir, grep and wc. They are used to work on files and the directory structure in Linux. Let’s go through them.
vi – a text file editor.

touch – Create an empty file with a specific filename.
grep – filter strings from text that is output on your console.
wc – Count the number of bytes, characters and lines from the output data in your console.

To create an empty file, run touch getprocesses.sh. This creates the empty file.

Now run vi, vi getprocesses.sh.

Enter edit mode and enter the following text:
ps aux | grep -i usr
Save the script and exit vi.
Let us make this text file executable, that is, a Bash script: chmod 744 getmyprocesses.sh
In the same directory, run ./getprocesses.sh. You should get a list of the running processes on your Linux box.

Let us modify the Bash script. Open the file with vi getprocesses.sh. Now, modify the one line to be as follows: ps aux | grep -i usr | wc -l

Run the Bash script again and notice how you only get a list of lines from the results obtained with ps aux | grep -i student

Open the help section for ps with man grep. Search the contents by pressing colon (:), then /-i to find the section for the i switch (press ENTER multiple times to find the specific entry). You have now successfully searched the manpages.

In this lesson you have created a file, added text into it (a commandline with multiple commands), made the file executable and ran it. You have also used the manpages to find information about a command switch.

Well done! You have successfully completed the introduction course “Your first Linux commands”.