Perl programming: using the terminal in Linux (or Mac?)

Pursuing summer tutoring, we have embarked upon the PERL programming journey.  The tutor continues it:  soon, there might be no turning back.

In my previous article, I described how you might, in Windows, create a text file, save it, then find it in the terminal. Now, I’ll describe the corresponding procedure in Linux – which I believe will be the same for the Mac. Once again: I don’t have a Mac, so I can’t be sure. It’s my impression, however, that Linux and Mac, for this purpose, are similar.

First, to create the file, you’ll open the text editor. In my flavour of Linux, it’s called “text editor”. You might write down a grocery list or colour choices for your paint:

maroon, cappuccino, red granite, basalt

Now, you’ll save that file. For convenience, you might create a new folder for PERL activities, then save the file in there. Perhaps you create the folder
“My_ perl_programs”. (Unlike with Windows, the Linux terminal may not tolerate spaces in names). Maybe you save the file as colours.txt in your “My_perl_programs” folder.

Now, you open the terminal – which, in my flavour of Linux, is called “terminal”. It’s in with the apps.

When I open the terminal, it puts me in what I’d call my “home” directory. To see the contents of the directory, I enter the command

ls

On my Linux terminal, ls displays the directories in blue, while the files are in white. From the terminal’s point of view, a folder is a directory. You (hopefully) see “My_perl_programs” – or whatever you called your PERL folder – among the items listed by the ls command. Maybe it’s even in blue.

Let’s assume you did call your PERL programs directory “My_perl_programs”. To go into it now, enter the command

cd My_perl_programs

Now, when you enter ls, you should see your text file colours.txt – or whatever you called it – listed. If you do see it, you have successfully created a text file, then found it in the terminal – which is, after all, the point of this article.

 Three observations:

  1. In Linux, the terminal doesn’t seem to tolerate names with spaces in between.  Windows users will notice this difference.
  2. The Linux terminal is case sensitive, whereas the Windows one is not.  Therefore, in Windows you can go into the “MeandMyself” directory using the command
    cd meandmyself, while in Linux, you can’t. You’d instead need to enter, literally, cd MeandMyself.
  3. In my Linux terminal, the dir command also works to list the contents of a directory, even though it’s the Windows command. However, you might not get the colour coding you might (in Linux) get using the Linux command ls.

To my knowledge, the Mac procedure for accomplishing the tasks above is very similar – if not virtually the same. Perhaps now “everyone” knows how to create a text file, then find it in the terminal. Next step: writing a PERL script, then (hopefully) running it!

Jack of Oracle Tutoring by Jack and Diane, Campbell River, BC.

Tagged with: , ,

Leave a Reply