Chapter 2

Getting to Know the Tools

Everything you do on a computer involves the running of software. At the most basic level, your computer has some operating system on it that controls everything that happens, organizes data, and lets you execute other programs inside of it. What operating system and tool set you choose to use has a significant impact on how you go about doing things. This chapter walks you through some tools that you might use and might not be familiar with. It then moves on to look at some of the tools that are part of a standard Scala distribution that we will use through the rest of the book.

Your choice of tools begins with your choice of operating system. It is very likely that you are familiar with common graphical environments on a Windows PC or Macintosh environment. For that reason, we are not going to take time to introduce them. Instead, this chapter talks about how you interact with various operating systems using a text interface. There are a number of reasons why it is good to be able to use this type of interface. For our purposes, the most significant is that is it the way we will interact with some of the Scala tools that we will be using.

2.1 Unix/Linux (includes Mac OS X)

This section covers the environment you will encounter in a Linux and Unix environment. Mac OS X is built on top of BSD Unix so everything here applies to the Mac. If you are on a Mac you can open a console to get access to the command-line tools.

2.1.1 Command-Line

Most people these days are used to the point and click approach of a Graphical User Interface, GUI. This is not how people have always interacted with computers. Indeed, a GUI takes a significant amount of processing power to run. For many years, computers had to have a simpler interface. Even today, there are times when you will need to interact with a computer without a GUI. This can happen when something goes wrong with the computer or if you need to use a computer that is located far away. There are also situations where people will choose to not run a GUI on a computer simply because they don’t want to waste the processing power.

Even when a computer is running a GUI, you can choose to interact using a command-line interface. The GUI can give you the ability to keep multiple command prompts open at once and using the command-line itself provides you with abilities that are not easily accomplished with a GUI. The reason why many people choose not to use a command prompt is that it does have a bit of a learning curve. You have to know some basic commands to be able to do anything. If you are going to spend much time working on computers it is worth putting in the small amount of effort to learn the basic commands for the command prompt interface on your OS. Odds are that you will find that not only does it speed things up on a regular basis, but there will be times when it allows you to do things that you simply could not do otherwise.

Figure 2.1 shows a terminal window under Linux that gives a command prompt. Your command prompt might look different than this. In general, the prompt should display some useful information followed by a character that signifies the end of the prompt. In this figure the prompt shows the user name and computer name followed by the current directory and a $. It is the $ that signifies the end of the prompt. Commands that you enter appear after the $. Anything the command displays will be printed out below the prompt. After the command finishes, another prompt will be given.

Figure 2.1

Example showing a Linux terminal with a command prompt.

An example of a Linux terminal with a command prompt.

2.1.1.1 Files and Directories

In a GUI you organize your files in folders. You have icons that represent different file types or folders and you can place files/folders inside of folders to organize them. These concepts came from the systems already in place on the command-line. The only change is terminology. The term folder worked well from a graphical standpoint. On the command-line they have long been called directories.

The first set of commands we will learn about allow us to work with files and directories so that we can navigate around and do the types of things you are used to doing by clicking, double-clicking, or drag and dropping. Here is a list of commands with a brief description of each. You will notice that in general they are abbreviations for what they do.

  • cat – Display the contents of one or more files.
  • cd – Change directory.
  • cp – Copy one file to another name or location.
  • less – Display out the contents of one or more files with the ability to move forward and backward, search, etc. (Less is more than more.)
  • ls – List the contents of a directory.
  • mkdir – Make a directory.
  • more – Display the contents of one or more files with the ability to page through or search.
  • mv – Move a file to a new name or location.
  • pwd – Stands for “print working directory”. This prints out the directory you are currently working in.
  • rm – Remove a file.
  • rmdir – Remove a directory if it is empty.

The big advantage of the command-line is that each command can be followed by arguments. Just entering a command is like double-clicking on a program icon. It is the arguments that let you specify additional information. Most of these commands do not do anything unless you give them one or more file/directory names to work on.

To see how you go about using these commands we will begin with pwd. It is a very simple command and can come in handy when you are starting off, or if you have lost track of where you are in the directory structure. At the command prompt simply type in pwd and hit Enter. Exactly what you get will depend on many things, but it should print out one line of output showing you the current directory. It could look something like this.

mlewis@mlewis-laptop:~$ pwd
/home/mlewis
mlewis@mlewis-laptop:~$

In this case, the directory is /home/mlewis. After printing the output we get a new prompt to enter the next command.

Aside

In Unix and Linux systems, the base of the entire file system is /. That is why it appears at the beginning of the /home/mlewis directory. A directory that begins with / is an absolute directory.

The next command we want to enter is the ls command. Type in ls, followed by an Enter and you will get a listing of all of the files in your current directory. This is the most basic usage of the command. You can also use it to see the contents of some other directory by following the ls command with a directory name. Here we see a listing of the contents of the root directory.

mlewis@mlewis-laptop:~$ ls /
bin dev initrd lib lost+found opt sbin tmp vmlinuz
boot etc initrd.img lib32 media proc srv usr vmlinuz.old
cdrom home initrd.img.old lib64 mnt root sys var

If you list a directory and it does not start with / then it will be a relative directory. So what you list will be appended to the end of the current directory. You might have a directory called Desktop in the current directory. Typing in ls Desktop will list the contents of the Desktop directory under the current directory.

mlewis@mlewis-laptop:~$ ls Desktop
AdobeReader.desktop QtCreator.desktop

You can also specify multiple files or directories and they will all be listed as seen here.

mlewis@mlewis-laptop:~$ ls Desktop /
/:
bin dev initrd lib lost+found opt sbin tmp vmlinuz
boot etc initrd.img lib32 media proc srv usr vmlinuz.old
cdrom home initrd.img.old lib64 mnt root sys var
 
Desktop:
AdobeReader.desktop QtCreator.desktop

You might not think that you would normally want to list multiple things at once, but it is a feature people use all the time with wild card characters. If you put a * into a name, the system will replace it with all the files or directories that match if the * is replaced with zero or more characters. Here is an example of that usage.

mlewis@mlewis-laptop:~$ ls /vmlinuz*
/vmlinuz /vmlinuz.old

For the first file, the * is replaced with nothing. For the second it is replaced with “.old”. You can also use a ? to represent any one character. These wild cards are not ever seen by the ls command of other commands. The command shell replaces them with all of the matching files and it is the multiple file names or directory names that get passed to the command.

The ls command has a lot of other possible options as well. The options are all preceded by a hyphen. The most commonly used option is -l, which tells ls to use a long display format. The following is an example of that.

mlewis@mlewis-laptop:~$ ls -l Desktop
total 8
-rwxrwxrwx 1 root root 1261 2008-11-28 12:21 AdobeReader.desktop
-rw-r--r-- 1 mlewis mlewis 250 2009-12-22 11:03 QtCreator.desktop

The long format puts each file or directory on a separate line. In addition to the file names it shows a number of other pieces of information. The first ten characters show permissions on the files. Permissions are discussed in section 2.1.1.4. After the permissions is a number showing how many links there are to this file. After that are the user name of the owner of the file and the group that the file belongs to. The last two pieces of information are the size of the file, measured in bytes, and the date and time of the last modification of that file.

The next most commonly used option is -a. This tells ls to list all the files, including the hidden files. Hidden files in Unix and Linux are files whose names begin with a period. We see here a usage of this combined with the long option. Only one hyphen is needed when options are combined.

mlewis@mlewis-laptop:~$ ls -al Desktop
total 16
drwxr-xr-x 2 mlewis mlewis 4096 2010-02-27 20:02 .
drwxr-xr-x 106 mlewis mlewis 4096 2010-08-09 16:57 ..
-rwxrwxrwx 1 root root 1261 2008-11-28 12:21 AdobeReader.desktop
-rw-r--r-- 1 mlewis mlewis 250 2009-12-22 11:03 QtCreator.desktop

This adds two additional lines. The letter d at the far left edge tells us that these are actually directories. The . directory is the name for the current directory. The .. directory is the name of the directory in which the current directory sits. We might also refer to it as the parent directory.

By default, commands work on the things in the current directory. For this reason, one of the commands you will use the most is the command that changes the current directory, cd. The cd command is followed by a single directory name. The directory will be the new current directory. As we just saw, each directory has . and .. as directory names inside of it. If you want to move up a level in the directory structure, simply do “cd ..”. You can also enter cd without a directory at any time to change back to your home directory.

Other tasks that you do frequently when you are manipulating files in a GUI are to copy, move, or delete. The commands for these are cp, mv, and rm. The cp and mv commands are used in roughly the same way. One way to use them is to enter two file names where the first file will be copied to the second name or renamed to the second name. A second usage is to enter one or more file names and then end with a directory name. In that usage all of the files listed are either copied or moved to the directory listed at the end. If you include a name that has a wild card in it, it will be expanded to all the file names. We can see these along with cd in use here.

mlewis@mlewis-laptop:~$ cd Desktop
mlewis@mlewis-laptop:~/Desktop$ mv ../*.txt .
mlewis@mlewis-laptop:~/Desktop$ cp test.txt test2.txt

We start by changing to the Desktop directory. Note the prompt used in this example changes so that we can see we are in this new directory. We then move all the files from our home directory that end with .txt into the current directory. This line with mv uses both .. to refer to the directory above the current one and . to refer to the current directory. In this case, one of those files was named test.txt. The last command makes a copy of that file and gives the copy the name test2.txt.

If you want to remove a file, use the rm command. The rm command can be followed by one or more files. Again, wild cards can be used to match multiple files. Here we are getting rid of all of the files that end with .txt.

mlewis@mlewis-laptop:~/Desktop$ rm *.txt

There is a word of warning about removing files on most Linux-based systems with the command-line, it is not forgiving. This is true whether you are using rm or if you happen to mv or cp to a file name when you already had a file of that name. While most of the GUIs that you have used probably move files you delete to some form of trash can, really just a different directory, and then allow you to clear that out later, doing rm on a file really deletes it then. You can not go digging in the trash to find it. In general when you delete a file with rm on these systems, it is gone and your only chance of getting it back is if you have a backup.1

This can be especially dangerous with the way that the command-line deals with wild cards. Take the rm command above. If you accidentally insert a space between the asterisk and the dot, you will delete every file in the current directory. This is because the * alone matches everything.2 So be careful when you are using rm and look over the command before you hit Enter to make sure you did not mistype anything or insert any unwanted spaces.

Directories exist to keep files organized. For this reason, you should probably make directories for each different major grouping of work that you have. You might also nest these to further refine the organization scheme. You can make a new directory with the mkdir command. Simply follow the command with the names of one or more directories you want to create. For example, it is probably a good idea to make a directory to store all of the work for this book or the course you are taking. You might make subdirectories in there for different assignments/projects or the code you write in class.

By default, rm does not remove directories. To remove a directory use the rmdir command. Like mkdir, you follow it with the name of one or more directories you want to remove. rmdir will only remove a directory if it is empty. So you would need to remove the contents to the directory first before you can remove it.

2.1.1.2 Aside

If you really want to delete an entire directory and all of its contents, including potentially other directories, there is an option for rm that will do that. The -r option tells rm or cp to recursively3 run down into a directory and either remove or copy all of its contents. This is very helpful if you want to copy a directory that has a lot of things in it. It can also be of great help if you want to remove such a directory. Remember to tread carefully though. Using rm with the -r flag has the possibility to wipe out a lot of files that you might have wanted to keep around. The command below uses -r with a copy to copy over an entire directory and all of its contents into the current directory.

mlewis@mlewis-laptop:~/Desktop$ cp -r ../Music/ .

The last thing you might want to do with your files is actually look at what is in them. There are many ways to do this. Indeed, a big part of most of the programs you have on your computer is the ability to let you view the contents of specific types of files. The commands we will consider here work best with plain text files. We will be dealing with a lot of those in this book. The most basic way to look at such a file is with the cat command, which simply prints the contents of one or more files to standard output. A step above that is the more command which will display one screen at a time and let you move down one line by hitting enter or a whole screen by hitting space. You can also search for things by typing what you want to search for after pressing /. Yet another step up is the less command, which allows you to move around freely using arrow keys or page-up and page-down as well as search as you could with more.

2.1.1.3 Helpful Tips

Many people who are not familiar with the command-line are initially turned off a bit by the amount of typing they have to do. People who use command-line all the time do not necessarily like typing more, they know more tricks to do things with the keyboard that do not require a lot of typing. Here are some handy tricks to help you use the command-line more efficiently.4

Typing in complete file names can be tedious and worse, is often error prone. If you mistype something it will not work and you have to enter the whole thing again. Worse, it might work and do something you did not really want to do. Because of this, tab completion is probably the most helpful feature you will find in your command-line environment. If you type in the first few letters of a file or directory then hit Tab, the shell will fill in as many characters as it can. If there is only one file that starts that way, it will give you the whole file. If there is more than one, it will fill in as much as it can until it gets to a point where you have to make a choice. If you double tab it will print out the different options that fit.

You should try this by going back to your home directory (remember you can do this at any time by typing in cd and hitting enter without giving it a directory) and then typing cd De and hitting Tab. Odds are good that the word Desktop will be completed for you with a / at the end because it is a directory. Use ls to see if there are two files/directories that start with the same first few letters. Type in cat followed by the first two letters and hit Tab. The shell will complete as much as it can then stop. Hit Tab twice quickly and it will show you the different options. It might look something like this.

mlewis@mlewis-laptop:~$ cd Do
Documents/ Downloads/

Not only does tab completion save you from typing a lot of extra characters, it never misspells a file or directory name. Use tab often and it will save you a lot of key strokes and a lot of little mistakes.

It is not uncommon to want to enter the same command or a very similar command more than once. The easiest way to do this, if it is a command you entered recently, is to use the up and down arrow keys to navigate backward and forward through the command history. When you get to a command, you can edit it if you want to make changes.

Using the arrow keys is not all that convenient if the command was something you entered a long time ago. The simplest way to repeat an old command exactly is to start the line with an exclamation point (often read “bang”) and follow it by some of the command. This will go back through the history and find the most recent command that started with those characters. That command will be executed without the chance to edit it. The limitation that you can not edit it or see exactly what the command is you will execute before you execute it means that ! is most useful for commands that start in a rather unique way.

You can also press Ctrl-r to get the ability to search through history. After pressing Ctrl-r, start typing in characters that occur consecutively in the command you want. It will bring up the most recent command that includes what you have typed in and you can edit it.

Another command that is very useful in general is the man command. This is short for manual and basically functions as help pages for commands or installed programs on the systems. The most basic usage is to type in man followed by the command that you want information on. You can also put in a -k option to do a search for something in the man pages.

2.1.1.4 Permissions

All modern operating systems have permissions that control who can get access to different types of files. What files you can access depends on who you are and what permissions you have. The act of logging into a machine determines who you are. You can use the command whoami to see who you are logged onto the machine as.

mlewis@mlewis-laptop:~$ whoami
mlewis

In this case the prompt also displays the user name, but that will not always be the case. Each user can also be a member of various groups. You can use the groups command to see what groups you are a member of.

mlewis@mlewis-laptop:~$ groups
mlewis adm dialout cdrom floppy audio dip video plugdev fuse lpadmin admin

The combination of who you are and the groups that you are in will determine what you have access to on a machine.

On Unix and Linux every file has read, write, and execute permissions for their owner, their group, and others. Those, along with the owner and the group of a file are displayed by ls when you use the -l option. Let us go back to the Desktop directory and look at the long listing of the files again.

mlewis@mlewis-laptop:~/Desktop$ ls -l
total 8
-rwxrwxrwx 1 root root 1261 2008-11-28 12:21 AdobeReader.desktop
-rw-r--r-- 1 mlewis mlewis 250 2009-12-22 11:03 QtCreator.desktop

There are two files here. The first ten characters tell us the permissions on the file. The first one is either ‘d’ or ‘-’. The ‘d’ would tell us it is a directory. Neither is a directory so both of these begin with ‘-’. After that are three groups of rwx where any of those can be replaced by ‘-’. The letters stand for read permission, write permission, and execute permission with ‘-’ being used when that permission is not granted. The first set of rwx is the permissions of the user the file belongs to. The second set is for the group the file belongs to. The third is for others. The first file listed here gives full permissions to all three. The second gives read and write to the user and only read to the group and others. Shortly after the permissions appear two names. For the first file they are both root. For the second they are both mlewis. These are the user and group owners for the file. The name root is the superuser on Unix and Linux machines.

To make this more interesting, let us use the mkdir command to make a new directory and then list the contents of the directory again.

mlewis@mlewis-laptop:~/Desktop$ mkdir NewDir
mlewis@mlewis-laptop:~/Desktop$ ls -l
total 12
-rwxrwxrwx 1 root root 1261 2008-11-28 12:21 AdobeReader.desktop
drwxr-xr-x 2 mlewis mlewis 4096 2010-08-11 19:59 NewDir
-rw-r--r-- 1 mlewis mlewis 250 2009-12-22 11:03 QtCreator.desktop

This new directory is also owned by mlewis and is part of the group mlewis. Note the letter ‘d’ first thing on the line telling us that this is a directory. The owner, mlewis, has full read, write, and execute permissions. Anyone in group mlewis will have read and execute permissions as do other users on the machine. If you try to use a file/directory in a way you do not have permissions for, you will get an error message. To go into a directory and see what is inside of it you need both read and execute permissions.

So now that you know how to tell what permissions a file has, the next question is how do you change them. The chmod command is used to change permissions on a file. There are quite a few different ways to use chmod. We’ll just introduce one of them here. After chmod you specify how you want to change or set permissions, then give a list of the files you want to make the changes to. The simplest way to specify changes is to use character codes for which set of users and the permissions involved and separate them with a ‘+’, ‘-’, or ‘=’ to say if you want to add them, remove them, or set them. The different permission sets are specified by ‘u’ for the user, ‘g’ for the group, ‘o’ for others, and ‘a’ for all. The rights are specified by the letters ‘r’, ‘w’, and ‘x’ as we have already seen.

Let us say that we are going to put things in this new directory that we do not want anyone but the user to have the ability to see. In that case we would want to remove the read and execute permissions from the group and others. We can see how that is done and the result of doing it here.

mlewis@mlewis-laptop:~/Desktop$ chmod go-rx NewDir/
mlewis@mlewis-laptop:~/Desktop$ ls -l
total 12
-rwxrwxrwx 1 root root 1261 2008-11-28 12:21 AdobeReader.desktop
drwx------ 2 mlewis mlewis 4096 2010-08-11 19:59 NewDir
-rw-r--r-- 1 mlewis mlewis 250 2009-12-22 11:03 QtCreator.desktop

Had we wanted to give everyone full permissions we could have used a+rwx as the second argument to chmod.

Less common than changing permissions is changing ownership. If you own the file you can change the user and the group of the file with the chown command. The most likely scenario for this is if you want to change the group to a shared group so that a select set of users can have access to something. If the group were called project then you would type in “chown :project files”.

Aside

As with the cp and rm commands, there are times when you will want to change the permissions of a large number of files in an entire directory. Both chmod and chown accept the -R option so that they will do this.

2.1.1.5 Compression/Archiving

If you spend much time on a system, you will likely need to interact with compressed or archived files at some point. Both of these play the role of taking many separate files and turning them into one large file. If it is compressed, that large file should be smaller than the sum of the files that went into it. Many programs that you might want to put on your computer come in the form of compressed files. If you have assignments or projects that span multiple files, your instructor might want you to combine them into a single file to turn them in. There are many different compression and archiving utilities. We’ll just talk about the main ones here.

  • tar – Archive files to a single tarball.
  • gzip/gunzip – Compress one or more individual files to the gzip format.
  • zip/unzip – compress multiple files to a single zip file. The zip format is used extensively on many operating systems.

The first two are used in the Unix/Linux world. They do archiving and compression separately, but are often used together to do both. The archiving program is called tar. It was originally created for archiving files from disk to tape. It simply collects multiple files together into a single file called a tarball. It can also extract files from a tarball. As with our other programs, tar is controlled by passing it arguments. You can use the man pages to see the many different options for tar. We will only discuss the basic ones.

The three main ways you will interact with a tarball are to create one, view the contents of one, or extract files from one. These different options are given with the characters c, v, and x. Most of the time you will want to interact with a file, and for that you will give the f option. The next thing after the f option should be the file name of the tarball you are creating, viewing, or extracting. Tarball files should typically end with the extension .tar. If you are creating a tarball, that will be followed by the file and directory names of the things you want to put into the tarball. Here are some sample invocations.

tar cf assign1.tar header.txt Assign1/
tar tf assign1.tar
tar xf assign1.tar

The first command is what you might execute to create a tarball called assign1.tar, which contains a header file and all the contents of the directory Assign1. The second command might be used to verify that everything you want is in the file or to check what is there before it is extracted. The last command would extract the contents.

The counterpart to tar is gzip. This command will compress one or more files. Simply follow the gzip command with a set of file names to compress. That will create a new set of compressed files that end with the extension .gz. The gunzip command will unzip any file to give you back the original file. You can use the -r option to recursively descend into a directory.

The combination of tar and gzip is so common that you can get tar to automatically zip or unzip files using gzip. Simply put the z flag in the options to tar and either gzip or gunzip will be invoked. Files created that way are typically given the .tgz extension.

Both tar and gzip are rather specific to the Unix/Linux world. If you have to deal with compressed files going to or from other systems, you might want to use the more broadly used zip format. The zip command can be followed by the name of a zip file and the set of file names to zip up into the specified zip file. If you want it to zip up a whole directory structure you will need to use the -r option. There is an unzip command that will extract the contents of a zip file.

2.1.1.6 Remote

One of the great strengths of Unix/Linux is the true multiuser capabilities that they have. In Windows you are probably used to only having one person at a time logged into a computer. That person will be sitting in front of the computer and if no one is at a computer, it is not being used. This is not true with Unix/Linux. These systems will allow multiple people to be logged in at once. A computer could be in full use even if no one is sitting at it. In fact, this is a big part of why you should be familiar with the command-line. Running graphical interfaces on machines across long distance Internet connections can be very unpleasant. However, the plain text form of a command-line will be quite responsive even across slow networks.

So how do you log into one computer from another one? If you are on a Unix/Linux box and you want to log into another there are several commands that you could use to make a connection. The most basic, and likely least useful, is telnet5. Simply type in telnet followed by the name or IP address of the machine that you want to connect to. This opens a very simple network connection between the machines. Because telnet connections are not secure and are, in a way, too flexible, you will probably find this approach blocked by the security setting on most machines.

Next up the scale is rsh. This stands for remote shell and can be invoked in the same way as telnet. The rsh connection is also not secure and as such, is blocked on many systems. However, for various reasons, it might be allowed on your system if you are logged into a trusted machine inside of the local firewall.

The connection type that you probably should use by default is ssh. This stands for secure shell and, as the name implies, all communication across a ssh connection is encrypted using public key cryptography. As such, if a system is going to let you log in remotely, this is the method that most system administrators are likely to leave open for you.

When you connect remotely to a machine you will be asked for your password and, assuming you get it right, you will be dropped at a command prompt on that machine. Everything that is discussed in this section will work on the remote machine just as well as the local one, no matter how far away the machine is. When you are done entering commands and you want to come back to the current machine, type logout or exit to terminate the remote session.

Aside

If your username on the remote machine is different from that on the current machine you can use “ssh username@machine” to specify the remote username. Also, the ssh command has one argument that will be particularly helpful once you get past chapter 11. The -Y option allows the remote machine to send windows back to the current machine. Use “ssh -Y machine” to activate this.

What if you are on a Windows machine? How can you connect then? Your windows machine should likely have telnet on it if you bring up the command prompt. As was mentioned above, this type of connection will likely be blocked for security reasons. Thankfully, there are free ssh programs that you can get for Windows. One of these is called putty and it will allow you to ssh into a remote machine and use it from a Windows box. If you decide you like the Unix/Linux command prompt you can also install Cygwin under Windows and get rsh, ssh, and all the other commands we will talk about on your Windows machine.

Aside

You can get remote windows sent back to your machine through putty using X-forwarding. This is a bit more complex so you should look at the help for putty to see how to do it.

An even better approach if you have a Windows machine is to run Linux on the machine. There are versions of Linux such as Ubuntu® and Linux Mint® which are specifically targeted at novice users or people who want to just get things running without much difficulty. You can download these from their websites at http://www.ubuntu.com, and http://linuxmint.com, respectively. If you do not want to dual boot your machine, you can even run Linux in a window under Windows using free virtualization software such as VirtualBox®(http://www.virtualbox.org) or VMWare Player®(http://www.vmware.com/products/player/).

telnet, rsh, and ssh all give you ways to log into a remote machine and execute commands on that machine. Sometimes what you need is to move files from one machine to another. For this you should probably use scp or sftp.6 The scp command stands for secure copy. You use it much like you would the normal cp command. The only difference is that your file names can be prepended with a machine name and a colon to say that they come from or are going to a different machine. A sample invocation is shown here.

scp cs.trinity.edu:Desktop/fileINeed.txt .

This copies the file fileINeed.txt from the Desktop directory on the machine cs.trinity.edu to the current directory on the current machine. If the second argument has a machine name with a colon then the file will go to that remote location. As with cp, the -r option can be used to copy an entire directory structure.

The sftp command is a secure version of the classic ftp program. ftp stands for File Transfer Protocol. It allows you to navigate local and remote directory structures, see what files are on the remote machine, and then move them across. The full usage of sftp is beyond the scope of what we want to cover here, but you should be aware it exists in case you need to move files around and are not certain what you want to move or where it should be moved to or from.

2.1.1.7 Other Commands

There are many other commands that are available to you on the Unix/Linux command-line. You do not have to be familiar with all of them to get things done with the command-line. In fact, after this chapter you should have enough to get through the tasks that you will need for this book. There are just a few more commands you might find helpful that we will list here.

  • clear – Clears the terminal so you get a fresh screen. This is only cosmetic, but it can be helpful at times.
  • df – Stands for disk free. This will list all of the different volumes on the current disk system and show you information on their usage.
  • du – Stands for disk usage. This will give you a rundown of how much disk space is being used in the current directory and its subdirectories.
  • echo – Prints whatever follows the command back to the terminal.
  • find – Find files that have different properties specified on the command-line.
  • grep – Searches for text inside of the specified files.
  • head – Print the first lines of a file.
  • ps – Show information about processes running on the machine.
  • tail – Print the last lines of a file.
  • touch – Updates the edit time on the specified file to the current time.
  • top – Lists the top resource consuming programs currently running on the machine.
  • w – Tells you who is logged onto your machine, where they are coming from, and what they are running.
  • wget – You give this command a URL and it will download the file at that URL to the current directory.
  • where – This command should be followed by the name of an executable. It will tell you the full path to that executable if it is in the current path.

As a final tip, you can follow any command with & to make it run in the background.

2.1.2 I/O Redirection

So far we have been talking about the different commands we can run from the command-line. We have typed input into the console when it was needed and the commands have output to the terminal so we could see it. The Unix/Linux command-line gains a significant amount of power from the fact that you can redirect input and output. The simple forms of redirection have the output of a program go to a file or have the input come from a file. These will be of use to you in many of the projects in later chapters even if you do not see the benefit right now.

To send the output of a program to a file you put a greater than, >, followed by a file name after the command. The output will go into that file. Here is an example.

mlewis@mlewis-laptop:~/Desktop$ ls -l > list.txt
mlewis@mlewis-laptop:~/Desktop$ ls -l
total 16
-rwxrwxrwx 1 root root 1261 2008-11-28 12:21 AdobeReader.desktop
-rw-r--r-- 1 mlewis mlewis 259 2010-08-12 22:32 list.txt
drwx------ 2 mlewis mlewis 4096 2010-08-11 19:59 NewDir
-rw-r--r-- 1 mlewis mlewis 250 2009-12-22 11:03 QtCreator.desktop
mlewis@mlewis-laptop:~/Desktop$ cat list.txt
total 12
-rwxrwxrwx 1 root root 1261 2008-11-28 12:21 AdobeReader.desktop
-rw-r--r-- 1 mlewis mlewis 0 2010-08-12 22:32 list.txt
drwx------ 2 mlewis mlewis 4096 2010-08-11 19:59 NewDir
-rw-r--r-- 1 mlewis mlewis 250 2009-12-22 11:03 QtCreator.desktop

The first call to ls does not print to screen. Instead, it sends it to the file list.txt because of the greater than followed by that file name. We can then do another ls and let it print to screen to verify the new file is there. Indeed, we have a new file that is 259 bytes in length. We can also use cat to view the contents of the file and you see the output you expect from ls. There is one interesting aspect to it. The file we are outputting to is there, but it has a size of zero. This is because the file is created as soon as we execute the command, but it does not get contents written to it immediately. That happens over time as parts of the output get big enough that they have to be moved from a buffer in memory to the file.

Using > for redirecting output will create a new file if none is there and will wipe out any existing file if one is there. If you want a command to add onto an existing file, use >> instead. This will redirect the output, but append to any existing file.

We can also tell a command to take its input from a file instead of from standard input using the less than, <, symbol. None of the commands we have looked at require additional input from standard input unless it requires a password, which you do not want to put in an unencrypted file. Many of the programs that you write will need to have you type text into them. You will often have to run these programs multiple times and it can get very tedious to input the same values over and over while you try to get the program to work. Having it take the input from the file can save you time as you only have to enter it into the file once and then use the file when you are testing the program.

The real power of redirection power comes from the the ability to send the output of one command into the next command as the input. This is called “piping” and it is done with the vertical bar, |, a symbol that is read as pipe. Perhaps the most common usage of the pipe is to send an output that is long into grep to search for something in it. This example here will find any files in the current directory that were last edited in December of 2009. For the directory listings we have done so far this type of thing would not be of much use, but it is more helpful in large directories like the one this example was executed on.

mlewis@mlewis-laptop:~$ ls -l | grep 2009-12
drwxr-xr-x 6 mlewis mlewis 4096 2009-12-22 11:03 qtsdk-2009.05
drwxr-xr-x 4 mlewis mlewis 4096 2009-12-23 17:33 QtWorkspace
-rwx------ 1 mlewis mlewis 2291366 2009-12-28 12:21 SwiftVis-0.3.0.jar

Another example is when some programs that are long running produce very long output files. Even if you use grep to cut the output down to just lines that have what you are interested in, that might still be many pages of material. You could pipe that output to programs like head, tail, or less to allow you to look at them in a manner that is easier to handle. For example, if you have a log file for a program that includes certain lines that have the word “Step” that you care about and you only want to see the last few you could do this.

grep Step log | tail

2.1.3 Text Editors (vi/vim)

Most programming languages have programs that are written in plain text. As such, you can use any simple text editor that you want to edit your programs. Word processors, such as Microsoft Word® or Open Office® are not plain text editors. You should not use them to edit your programs. Word processors store all types of additional information such as the font and format of text in addition to the text itself. Programs need only the straight text. On a Windows machine, Notepad is an example of a text editor.

You could use Notepad to edit Scala programs, but not all text editors are equally useful for programming. Due to the fact that programming is a fairly common usage for plain text editors, many text editors have features in them that are specifically aimed at programming. On Unix/Linux a primary example of this is the vi editor. While there are lots of different editors that one can choose from on Unix/Linux, we will work with vi because it is lightweight and is installed on virtually all such machines.7 Many other editors will bring up separate windows or are not part of a default installation. If you decide you do not like vi or have another preference, you are more than welcome to use whatever editor you want in going through this book.

To start running vi, simply type in vi followed by the name of the file you want to edit. If the file exists, you will see its contents on your screen. If not, you will get a mostly blank screen with tildes down the left side and some extra information at the bottom.

The first thing to know about vi is that is has two main modes. When you first start it up, you are in command mode. To type things you need to be in an editing mode. When you are in an editing mode you can type just like you would in Notepad. What gives vi the extra power that is helpful for programmers is the ability to use the command mode. To get from command mode into a edit mode, type one of the following.

  • i – Insert before the current character.
  • I – Insert at the beginning of the current line.
  • a – Append after the current character.
  • A – Append at the end of the current line.
  • R – Start replacing characters from the current position.

Most of the time you will probably just use i, but there are occasions when the others can be helpful. The line at the bottom of your terminal should change to show you that you are now in an edit mode. After you get into edit mode you start typing. In vim you can also use the arrow keys along with Home, End, Page Up, and Page Down to move around. If you are in a true vi install that will not work, instead you will have to return to command mode to move the cursor around.

To get back into command mode, simply hit escape (Esc). The bottom line will let you know that you are back in command mode. In command mode you can move the cursor around. In vim the special keys will still work for this. If you are in a true vi install, you will need to use the following keys to move around.

  • h – Move left.
  • j – Move down.
  • k – Move up.
  • l – Move right.
  • Ctrl-d – Page down.
  • Ctrl-u – Page up.

You can do other edits while you are in command mode. Here are some of the other keys that do things for you in command mode.

  • x – Delete a character.
  • dd – Delete a line and place on the clipboard. (Precede with a number for multiple lines.)
  • yy or Y – Yank a line. This copies to the clipboard. (Precede with a number for multiple lines.)
  • p – Paste the clipboard after the current line.
  • P – Paste the clipboard before the current line.
  • r – Replace a single character.
  • J – Join lines.
  • / – Search for something. Enter the search string after the /.
  • n – Repeat the last search.
  • cw – Change the current word. This removes up to the next white space and goes into insert mode.
  • . – Repeat the last command.
  • u – Undo the last command.
  • Ctrl-r – Redo the last undone command.

If you type in a number before any command in vi, that command will be repeated that number of times. This includes going into an edit mode. So if you type 100 and ’A’, any text you add in will be added 100 times when you hit Esc. If that is not what you wanted, you will probably find that the ’u’ command comes in handy.

Some commands work well in patterns. For example, if you want to do a find and replace where you look at each instance before doing the replace, you might use ’/’ to search for the first instance, then use ’cw’ to replace the word in question and hit Esc. After that, you use ’n’ to move to the next instance of the string and ’.’ to repeat the ’cw’ command if you want to replace that instance. The ’.’ command is something that would only have minimal value in writing a term paper, but comes in handy a lot more with programming tasks.

There are also a whole set of commands that you invoke by typing a colon. For example, you might have wondered how you save files or how you get out of vi all together. Here are just a few of the colon commands that you might find helpful.

  • : n – Jump to the nth line of the file where n is a number.
  • :w – Save the file as it is.
  • :q – Safe quit of vi. This won’t work if you have made changes since the last save.
  • :q! – Unsafe quit of vi. This will quit and throw away any unsaved changes.
  • :wq – Save the file and quit vi.

You should spend some time getting used to these commands. If you really want to see what vi can do, read the man page. Many students who are new to vi fall into the pit of hitting ’i’ as soon as they start up and then using it like Notepad until they are ready to save. This approach ignores all the powerful features of vi and, in the long run, slows you down. Try to get used to hitting Esc whenever you pause in your typing. If nothing else, it will allow you to also hit ’:w’ so you save your changes frequently. On systems with vim, you can run vimtutor to get a guided tour.

vi Settings

You can change settings in vi by editing a file in your home directory with the name “ .exrc”. In particular, you should consider adding this line.

set tabstop=2

This makes it so that tabs display as four characters. You can use 4 if you want, but the default is 8 which is a bit too large to work well with Scala.

2.2 Windows

Based on installation statistics, odds are good that the computer you use most of the time is running some form of Microsoft Windows®. That will not prevent you from programming or doing any of the activities described in this book. One of the advantages of the Scala language is that it is platform independent and will work equally well on many operating systems, including Windows.8

2.2.1 Command-Line

Most people interact with Windows using the GUI. This is so much the case that you might not even realize that there is a command-line interface. If you look under the Accessories option on the Programs menu you will see an option for “Command Prompt”. If you select and run this, you should see a window that looks like figure 2.2. Like the terminal for Unix/Linux, this is a text interface that gives you some type of prompt with basic information. In the figure it shows you the current directory followed by a ’>’. In this case we are in the directory “C:Usersmlewis”.

Figure 2.2

Figure showing the Windows command prompt. This is the command-line interface for Windows.

This figure shows the Windows command prompt. This is the command-line interface for Windows.

While the Windows command prompt looks and acts much like a Unix/Linux terminal, it has a different set of commands. The history of Windows and its command prompt are rooted in DOS (Disk Operating System) and the commands that are used in the command prompt for Windows today are largely the same as for that purely command-line based operating system. One of the differences between Unix/Linux and Windows that should be noted immediately is that unlike Unix/Linx, the Windows system is not case sensitive. Commands will be presented here in lowercase, but they will work fine in uppercase or mixed case.

2.2.1.1 Files and Directories

As with the Unix/Linux environment, the folders that you are used to in a GUI are called directories on the command-line and they are used to organize files on the computer. There are a number of different commands that can be used for working with directories and files with the Windows command prompt.

  • cd/chdir – Changes the current directory.
  • copy – Copy files from one location/name to another.
  • del/erase - Deletes files. This doesn’t move them to Trash like doing a deleter from the GUI. Once this has been executed the files can not be recovered.
  • dir – Lists the contents of the specified directory or the current directory if none is listed.
  • md/mkdir – Make the specified directory.
  • more – Print the contents of a file one screen at a time.
  • move – Moves a file to a different directory.
  • path – Let’s you see the current path or change the path.
  • ren/rename – Rename an existing file.
  • rd/rmdir – Remove a specified directory.
  • tree – Display the contents of a directory or drive as an ASCII-based tree.

There are some significant differences between directories under Windows and those under Unix/Linux. The first is that directories are separated by a backslash, ’’, instead of a forward slash, ’/’. This is something you have to keep in mind, but it does not significantly impact how any commands are used. The other difference is that Windows machines have different drives, each with its own directory tree.

The prompt above showed the current directory as being “C:Usersmlewis”. The C: at the beginning of this specifies the drive. The drives on a Windows machine are specified as single capital letters. By default, C: is the master hard-disk of the machine. If you want to deal with locations on other drives you need to be certain to specify the drive name in the path you are using. In addition, by default the cd command will either change drives or move you to a different directory. To do both you have to give the ’/d’ option.

Aside

The C: standard for the hard drive arose early on. The first DOS machines did not have hard-drives. Instead, they typically had one or two floppy disk drives. These were named A: and B:. When hard drives were added on, they took the next letter in the alphabet. Even though it is very rare to find a computer with a floppy disk drive these days, the main disk still gets the C: distinction and other drives use higher letters in the alphabet.

By contrast, different drives in Unix/Linux systems are represented as directories under the main directory tree that starts with /. Removable drives are typically mounted in subdirectories of /media.

Figure 2.3 shows what the command prompt looks like after the dir command has been run. This shows a lot of the same information that you get from running “ls -l” on a Unix/Linux machine.

Figure 2.3

Figure showing the command prompt from Windows after the dir command has been run.

This figure shows the command prompt from Windows after the dir command has been run.

2.2.2 Text Editors

No matter what the operating system, programs are still generally written in plain text files so you need a plain text editor for doing that. In this section we’ll look at some of the options you have for this in Windows.

2.2.2.1 Edit

Working on the command-line in 32-bit Windows the command “edit” will bring up a text-based program that works much like a GUI. You can see what it looks like in figure 2.4. It has a set of menus that you can access by hitting Alt. These let you do the normal things you would expect from an editor. The edit program is much more of a general purpose editor and is much more user friendly than vi. As a result, you can use it without too much introduction. The downside is that it lacks features that are specifically beneficial for programming. If you have a newer Windows install it is probably 64-bit and there will not be an install of edit. You can use a GUI-based text editor instead.

Figure 2.4

Figure showing a command prompt with the edit program running.

This figure shows a command prompt with the edit program running.

2.2.2.2 Notepad

Of course, you do not have to edit your text files in the command prompt. You can feel free to bring up Notepad on a Windows machine and edit files that way. Then you can use the command prompt just for running the programs that need to use that interface. The simple GUI of Notepad has the same benefits and drawbacks of edit. It will work fine for small things, but it was not built for programming and will slow you down at a certain point.

2.2.2.3 Others

There are many other text editors that you could use on Windows which are more directly aimed at programming. Attempting to list all such editors and provide any type of comparison or judge their relative merits in this space would be pointless. Not only are there too many of them, they can change over time. Doing a web search for “text editor” will likely provide you with many different options. In addition, other people have done the work of compiling a list with comparisons on Wikipedia®. Simply go to http://en.wikipedia.org/wiki/Comparison_of_text_editors and you can see tables comparing different editors and check out other information on the ones that seem interesting.

2.2.3 Other Commands

There are a number of other commands that you might find it helpful to know when working with the Windows command prompt.

  • cls - Clears the screen and puts you at a blank prompt. This command only impacts appearance, but can be useful at times.
  • echo - Like the Unix/Linux command, this will print out whatever text is passed in to it.
  • exit - This will close the command prompt.
  • find - This is the equivalent of grep in Unix/Linux. It will find strings in a file for you.
  • help - This gives you help on commands. If you enter it without specifying a command it will list the possible commands for you.
  • where - Takes one argument which is the name of a command. It will tell you the full path of that command.
  • whoami - Tells you the name of the user account you are logged in as.

In addition to these commands, I/O redirection with ’<’, ’>’, ’>>’, and ’|’ work in the Windows command prompt just like they did in Unix/Linux. You can also use tab completion in Windows to auto-complete file names and save yourself some typing or the possibility of typos. The use of Tab in Windows is particularly helpful because many files and directories have spaces in them that have to be handled properly. If you use tab completion, the system will automatically add double quotes around things so that spaces are dealt with appropriately.

2.3 Scala Tools

When you install Scala on your machine there are several different programs that get installed in the bin directory under the Scala installation. To begin with, we will only concern ourselves with two of these: scala and scalac.9 The scala command actually runs scala programs. The scalac command is used to compile scala text files into bytecode that is compatible with either the Java or .NET platform. It will be a while before we begin writing our own classes and using scalac to compile larger programs. However, we will begin using the scala command immediately.

Scala on Your Machine

If you only use Scala on a machine in a computer lab, hopefully everything will have been set up for you so that you can simply type the name of a command and it will run. To run Scala on your own machine may take a little more setup.

Installation

The first thing you will have to do is install Scala on your computer. Scala requires Java® to run so if you don’t have Java installed you should go to http://java.oracle.com and download then install the most recent version of the Java SE JDK. When you install you can go with the default install locations.

Once you have Java installed you can install Scala. To download Scala go to http://www.scala-lang.org. On that site download the latest version of Scala. There are typically several installers to choose from. The IzPack installer for all platforms is typically the easiest to work with even if it is a bit larger to download. It is suggested that when you run that you use the default install location.

Dealing with the PATH

If you are using Scala on your own machine it is possible that entering the command “scala” or “scala.bat” could produce a message telling you that the command or program scala could not be found. This happens because the location of the installed programs are not in your default PATH.

The PATH is a set of directories that are checked whenever you run a command. The first match that is found for any executable file in a directory in the PATH will be run. If none of the programs in the PATH match what you entered, you get an error.

When you installed Scala, a lot of different stuff was put into the install directory. That included a subdirectory called “bin” with different files in it for the different executables. If you are on a Windows machine, odds are that you installed the program in C:Program Filesscala so the scala.bat file that you want to run is in C:Program Filesscalainscala.bat. You can type in that full command or you can add the bin directory to your PATH. To do this right click on the Computer and go to the Advanced Settings and change the Environment Variables.

Under Unix/Linux you can do this from the command-line. Odds are that Scala was installed in a directory called scala in your user space. To add the bin directory to your path you can do the following.10

export PATH=$PATH:/home/username/scala/bin

Replace “username” with your username. To make it so that you do not have to do this every time you open a terminal, add that line to the .bashrc file in your home directory.

There are three ways in which the scala command can be used. If you just type in scala and press Enter you will be dropped into the Scala REPL (Read-Execute-Print Loop). This is an environment where you can type in single Scala commands and immediately see their values. This is how we will start off interacting with Scala and it is something that we will come back to throughout the book because it allows us to easily experiment and play around with the language. The fact that it gives us immediate feedback is also quite helpful.

To see how this works, execute scala. It should print out some information for you, including telling you that you can get help by typing in :help. It will then give you a prompt of the form scala>. If you type in :help you will see a number of other commands you could give that begin with a colon. At this time the only one that is significant to us is :quit, which we will use when we are done with the REPL and want to go back to the normal command prompt.

It is customary for the first program in a language to be Hello World. So as not to break with tradition, we can start by doing this now. Type the following after the scala> prompt.

println("Hello World!")

If you do this you will see that the next line prints out “Hello World!”. This exercise is less than exciting in the REPL because it always prints out the values of things, but it is a reasonable thing to start with. It is worth asking what this really did. println is a function in Scala that tells it to print something to standard output and follow that something with a newline character. In this case, the thing that was printed was the string “Hello World!”. You can make it print other things if you wish. One of the advantages of the REPL is that it is easy to play around in. Go ahead and test printing some other things to see what happens. We will come back and do a lot more with this in the next chapter.

The second usage of the scala command is to run small Scala programs as scripts. The term script is generally used in regards to short programs that perform specific tasks. There are languages that are designed to work well in this type of usage and they are often called scripting languages. The design of Scala makes it quite usable as a scripting language. Unlike most scripting languages, however, Scala also has many features that make it ideal for developing large software projects as well. To use Scala for scripting, simply type in a little Scala program into a text file that ends with “.scala” and run it by putting the file name after the scala command on the command-line.

2.4 End of Chapter Material

2.4.1 Summary of Concepts

  • The software you use to interact with your computer comprises a tool set. The nature of these tools is extremely important to software developers.
  • The first half of this book is written with the expectation the reader is using command-line tools. These vary between operating systems.
  • Linux and Unix based operating systems, including Mac OS X, include a powerful command-line that is often utilized.
    • There are a number of different commands that you use to give instructions to the computer using the command-line. You will likely commit these to memory over time as you use them. The real power of these commands is that they can be given arguments to make them behave in specific ways or do specific things.
    • Files are organized in directories. Some of the most important commands you will need to learn are for dealing with directories and navigating the directory structure. The name . always represents the current directory and .. represents the parent directory.
    • Input and output for commands can be redirected in different ways.
      • Use > to send the output of a program to a file, deleting anything that is there.
      • Use >> to send the output of a program to a file, appending to the end of current contents.
      • Use < to have the contents of a file act as the standard input for a program.
      • Use | to have the output of one program sent to the input of another. You can chain multiple programs together with this technique called “piping”.
    • Programs are typically written in plane text with a text editor. The text editor described in this chapter is vi. It is very common on Linux/Unix installs and the capabilities of the command mode make it a good editor for programming.
  • Windows also incorporates a command prompt that resembles the older DOS interface.
    • There are a different set of commands that you can use in the Windows command prompt. I/O redirection works like it does in Linux/Unix.
    • The command-line text editor is called edit. It is not included in 64-bit Windows installs. You can use Notepad or some other GUI text editor. Microsoft Word and other word processing programs are not text editors.
  • When you install Scala on your computer you get a number of different executable commands.
    • The scala command can run scripts or applications. If no argument is given it opens up the REPL for you to type in individual statements.
    • The scalac command is used to compile Scala source code to bytecode. This usage is more significant in the second half of the book.

2.4.2 Exercises

  1. Make a directory for the work associated with this book in your user directory.
  2. Enter the “Hello World” program in the directory you created. Make sure the file name that you use ends with .scala. Run it using the scala command.
  3. (Linux/Unix/Mac) Use wget to download the file for the primary page of Google. This should give you a file called index.html. Move this to the name google.html. Count how many times the word “google” appears in that file. Describe how you did this and how many times it occurred.
  4. Ask your instructor if you have a web space on the machines you work on. If so, make a directory in that space called CS1. Put a file called persinfo.txt in that directory that tells your instructor a little about you and why you are taking the course. Set permissions on the directory and the file so that they are visible for the web (a+rX for Linux). You can test if you did this correctly by pointing a browser at your web space to make certain the files are there.
  5. (Linux/Unix/Mac) The ps command can tell you what is running on a machine. Run “ps -ef” and send the output to a file called allprocs.txt. Look at the file to see what all is running.
  6. (Linux/Unix/Mac) Do a long listing (ls -l) of the /etc directory. Pipe the output to grep to see how many files contain your first and last initials (e.g., jd for John Doe).

Additional exercises can be found on the website.

1There is a -i option for rm, mv, and cp that will cause the program to prompt you before any file is removed. This is not practical if you want to remove a lot of files, but it could be considered a good default for most of what you do.

2There is one minor safety in place. The * alone does not match files that start with a ., so hidden files would not be deleted in that situation. That will not make you feel much better though if you have just erased five different multihour coding projects.

3Recursion is a topic that you probably are not familiar with yet, but which we will hit on several times during this book.

4Tricks like those discussed in this section vary depending on the exact command shell you are using. This describes features of the bash shell, which is standard for many Linux installs.

5You will have occasion to use telnet in the second half of the book when we start writing our own networked code. One of the project ideas from the second half of the book is a networked text-based game called a MUD that users would connect to with telnet.

6There are also rcp and ftp programs, but just like rsh and telnet, secure systems likely will not let these through.

7Many Linux installs technically come with vim instead of vi. vim stands for “vi improved” and everything covered in regards to vi here will work for vim. On those systems executing vi will typically run vim by default so it is likely you will never notice a difference. In fact, a few features described in this section, like multiple undo and redo, only work in vim, not in standard vi.

8Even though you can do your coding under Windows, you might want to consider installing Cygwin or running Linux through virtualization or as a dual-boot configuration just to get experience with something new.

9On a Windows system these commands should be followed by “.bat

10This syntax assumes you are using the bash shell. If it does not work for you, you can do a little searching on the web for how to add directories to your path.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset