Most of the software development performed in the Mathews lab is done in the Linux operating system. Linux is an open-source operating system that is extensively used in applications ranging from High Performance Computing to networking hardware to mobile phones. This crash course is designed to help you get up and running using Linux to run the type of applications used in the Mathews lab.
Accessing the terminal
Applications can be installed through a number of ways. The most common way is through the package manager that is bundled with the Linux distribution. For Debian/Ubuntu-based distributions, the package manager is apt-get. Redhat-based systems use yum, while Arch-based distributions use pacman. Another way to install applications is through binary packages. This method is similar to the standard way that programs are installed in Windows. A third way to install programs is by compiling from source code. Whenever possible, it is recommended to use a distribution's package manager to install programs.
Many programs will have manual (man) pages that are distributed with the program. These manual pages can be read using the man program using the syntax man program_command. For example the man program itself has a manual page that can be read with the command man man. When viewing a man page, the arrow keys will navigate up/down and the q key will exit.
In Linux, all files can be found in a single filesystem. The base of the filesystem has the path /. Directories can be found within this 'root' filesystem. Directories are separated from each other by the character /. For example, most users' home directory can be found in the /home/ directory, as with /home/user/.
The filesystem can be navigated using either graphical programs, similar to Windows Explorer or MacOS Finder, or from a terminal interface. The graphical programs are fairly intuitive and work similarly to their counterparts in Windows or MacOS. Therefore, this section will focus on how to navigate in the terminal interface.
The terminal is always pointing to a file directory, called the Working Directory. In the terminal, you can get the path to the Working Directory using the command pwd. You can remember this command as an acronym for 'print working directory'. Example usage is shown below:
[user@host ~]$ pwd/home/user
To get a listing of the files and directories in the current working directory, use the command ls. For example:
[user@host ~]$ lsDesktop Downloads Pictures sourceDocuments Music Public Videos
There are additional flags that you can give the ls command to change the output. Two common ones are -a, to list all files, including hidden ones, and -l, to give more detailed output.
To change the current working directory, use the command cd followed by a path name.
[user@host ~]$ pwd/home/user[user@host ~]$ cd source[user@host source]$ pwd/home/user/source
Copying and moving files and directories can be done using the cp and mv command. The syntax is similar between the two commands. The cp command is called with at least two arguments as in cp source_path destination_path. If you are trying to copy a directory, you need to use the -R flag. For example: cp -R source_dir destination_dir. The command mv does not require that flag when moving folders.
To delete a file or folder, use the rm command, using the syntax rm target_path. To delete a folder, use the -r flag, such as rm -r target_dir. Be very careful using this command, especially when executing with administrative privileges.
There are a number of special paths that are available in the terminal. The path ~ is the user's home directory. The path . is the current working directory, while the path .. is the directory that contains the current working directory. For example, if the working directory is /home/user/, the path . is equivalent to /home/user/ and the path .. is equivalent to /home/.
In Linux, access to a file or directory is controled through file permissions. Each file has a user specified as the owner as well as a group. The owner and group associated with a file or directory is among the extra information provided with the -l flag for the ls command. For example:
[user1@host ~]$ ls -l /homedrwx------ 39 user1 users 4096 Feb 17 15:13 user1drwx------ 3 user2 users 16384 Dec 10 21:14 user2
In this example, the owner is listed in the third column, while the group is listed in the fourth column. Each file has permissions for three classes of users: owner, group members, and everyone else. Each group has three types of permissions: read, write, and execute. Users with read permissions can view the file, those with write permissions can change the file, and those with execute permissions can run the file.
In the above example, the string drwx------ at the beginning of each line of the output of the ls command shows the permissions. The first character tells us if the path is a directory (d), link (l), or a regular file (-). The next three characters show the permissions for the owner. In this case, the owner has read (r), write (w) and execute (x) permissions. The next three characters shows the permissions available to group members. In this case, group members have no permissions. Similarly, the last three characters show the permissions for everyone outside of the group, in this case, they have no permissions. If the permission string was instead drwxr-x---, the owner would have full permissions. Other group members could read and execute, but not modify. And people who are not group members could not do anything.
These permissions can be modified with the chmod command. Ownership can be changed with the chown command. See the manual pages for these commands for documentation