# Linux and Vim Tutorials ### **Installing JDK 11** **The Java code you submit in the programming assignments must compile and run on JDK 11 on ieng6.** If you ssh into ieng6, then you should be using the correct programming language version **by default** (no installation needed). Please use link if you want to install JDK 11 on your local machine. You need to do this in order to compile and run Java programs locally. https://www.oracle.com/java/technologies/javase-jdk11-downloads.html **** ### **Login Info** Find out your login info at [ETS Account Lookup](https://sdacs.ucsd.edu/~icc/index.php) It will likely be a cs12sp20__ account. The account password is the same as your regular TritonEd password. However, it's possible that you don't have this account. If that's the case, use your email username. Upon logging in, type "prep cs12sp20". This prepping command is not needed for cs12sp20__ accounts. If you are unable to login using the username and your password either in-lab or remotely, you may need to reset your password for your cs12 account at the above link or contact ETS to get it fixed. **** ### **Using Shell** #### Mac/Linux users SSH allows you to access the ieng6 machines and use the shell on the ieng6 servers to work on your assignments. For UNIX machines, you can do so in the terminal with the following command: ``` ssh YOUR_USERNAME@ieng6.ucsd.edu ``` ieng6.ucsd.edu is the domain name which allows you to connect to UCSD from anywhere on the internet. Please replace YOUR_USERNAME with your cs12__ account name. #### Windows ##### Option #1: MobaXterm For Windows users, we recommend downloading and installing MobaXTerm, which is a very convenient SSH client program. It comes with the networking protocols to both use the remote shell and to transfer files between your local Windows machine and the ieng6 lab machines. Click on "Start local terminal" to open the terminal shown below. Then type in the ssh command using the `ssh` command shown previously. ![](https://i.imgur.com/XWj8jNE.png) Note that when typing your password, nothing will show up on the screen. This is the intended behavior to keep your password hidden. After typing in your password, press enter. Upon successful login through SSH, a shell will spawn. ![](https://i.imgur.com/sB1TYnv.png) ##### Option #2: Powershell You can also use Windows Powershell as your terminal to ssh. Windows Powershell is unix command compatible Just click on the windows button and search for 'powershell' ![](https://i.imgur.com/BxYbZfA.png) ![](https://i.imgur.com/d14yHrO.png) --- Some useful Linux commands (try them out in terminal!): `pwd` - display absolute path of the current directory `ls` - list out the files of the current directory `mkdir pa1` - make new directory in the current directory and name it "pa1" `cd pa1` - change directory one level down into a folder named “pa1” **** ### **[Mac/Linux users] Transferring Files between local machine and ieng6** #### Transfer a single file from local to ieng6 For UNIX machines like macs, to transfer a single file from your own machine to your ieng6 account, type in your terminal: ``` scp my_file.txt <your username>@ieng6.ucsd.edu:<path to destination directory> ``` where you replace `<your username>` with your cs12sp20 account, and `<path to destination directory>` with the directory you want to copy `my_file.txt` to. Make sure you are in the directory where the file is located in, otherwise you have to specify the path to that file (i.e. `./Desktop/CSE12/my_file.txt`) You can read more about the `scp` command [here](https://haydenjames.io/linux-securely-copy-files-using-scp/) ##### Example 1 Suppose I have a file named `HelloWorld.java`, which is located in the current directory `sample_directory` (you can double check that the file you want to copy is in the current directory using the `ls` command, which shows you all the files in the current directory) And suppose I want to copy over `HelloWorld.java` into the home directory of my ieng6 account. Type into terminal: ``` scp HelloWorld.java cs12sp20ta99@ieng6.ucsd.edu:~/ ``` where `~/` is the notation for home directory. This will prompt you to type in the password to your ieng6 account. Once you type in your password, there will be output that looks something like this: ``` HelloWorld.java 100% 1985 1.9KB/s 00:00 ``` which means the file was successfully transferred over. The numbers are just some information about the file and how long it took to transfer. ![](https://i.imgur.com/yEBDNB1.png) ##### Example 2 Suppose instead of the home directory if my ieng6 account, I want to transfer it to a folder named "MyProgramDir" on my ieng6 account. Type in your local terminal: ``` scp HelloWorld.java cs12sp20ta99@ieng6.ucsd.edu:~/MyProgramDir/ ``` **The forward slash `/` signifies that `MyProgramDir` is a directory, instead of a file. Don't forget it! Otherwise you will get an error.** If the directory `MyProgram` doesn't already exist on your ieng6 account, the command above will create the directory and copy `HelloWorld.java` into the newly created `MyProgram` directory. #### Transfer a single file from ieng6 to local machine Type in your local terminal: ``` scp <username>@ieng6.ucsd.edu:~/<path to file> <path to destination directory on your machine> ``` ##### Example 1 Suppose you made some changes to `HelloWorld.java` on your ieng6 account and want to transfer it to your local machine. `HelloWorld.java` is currently located in your home (`~/`) directory on your ieng6 account. Type into your local terminal (Make sure you're typing in the command on your local machine, **not** inside your ieng6 account): ``` scp cs12sp20ta99@ieng6.ucsd.edu:~/HelloWorld.java . ``` This will copy over the file to your current directory that you are in in your local terminal (signified by the dot `.`) #### **Transfering multiple files between local workspace and ieng6** You can also transfer entire folders (directories), which is most likely are trying to do when verifying your PA on ieng6. The same idea from single file transfer applies. ``` scp -r <path to directory to copy> cs12sp20__@ieng6.ucsd.edu:~/ ``` You need to include the `-r` flag to signify that you want to copy over all the contents of that directory/folder. ![](https://i.imgur.com/mDyXKe6.png) ##### Example 1 Suppose you are working on PA1, and you want to copy over the entire PA1 folder to your ieng6 account. And suppose your PA1 folder is called `PA1`, which is located in the current directory that you're in. ``` scp -r PA1/ cs12sp20ta99@ieng6.ucsd.edu:~/ ``` This will copy the entire directory named `PA1` to the home directory `~/` of your ieng6 account (Don't forget the forward slash `/` after the directory name `PA1`). You'll see output as the files are being transferred over. Something like this: ``` hamcrest-core-1.3.jar 100% 44KB 44.0KB/s 00:00 junit-4.12.jar 100% 308KB 307.6KB/s 00:00 Counter.java 100% 905 0.9KB/s 00:00 CounterTest.java 100% 1953 1.9KB/s 00:00 RockPaperScissors.java 100% 5772 5.6KB/s 00:00 RockPaperScissorsTest.java 100% 1663 1.6KB/s 00:00 writeup.md 100% 19KB 19.2KB/s 00:00 ``` ### **[Windows users] Transferring Files between local machine and ieng6** For a Windows machine, the command prompt does not support UNIX commands like `scp` #### MobaXterm You can use [MobaXterm](https://mobaxterm.mobatek.net/) as mentioned from the **Using Shell** section. MobaXterm can serve as your terminal (ssh client too) and it also has a simple interface that allows you to transfer files between your local machine and remote server by click, drag, and dropping files or folders on the left side panel. #### Powershell You can also use Powershell and follow the instructions on how to `scp` files in the Mac/Linux user section ### **[All users] Transferring Files between local machine and ieng6 using Filezilla** You can use [Filezilla](https://filezilla-project.org/) to transfer files through a user interface between the ieng6 server and your local machine. Once you download the application, on the top bar enter the following information: * Host: ieng6.ucsd.edu * Username: <your cs12sp20 account> * Password: <your account password> * Port: 22 ![](https://i.imgur.com/TisdUEg.png) Then click "Quickconnect". When asked about the host key, click "ok". You will now be connected to your account on the ieng6 server. On the left is your local file system. On the right is the ieng6 server file system. Navigate to the file(s)/directory you want to copy and, on the other side, navigate to their destintation. Drag the files and/or directories over from one side to the other to copy them. On the top window, the status will state "File transfer successful" once completed. Check to make sure they were copied over properly. You can then close the application. ![](https://i.imgur.com/qAjmAYo.png) **** ### **Using vim** Next, we will work with our text editor. You can use any text editor/IDE you would like but make sure to compile and execute using the command line. We will use the Vim text editor. This editor can be started by inputting the command: `vim` What you should see in your terminal is no longer the shell, but the Vim editor. It has a welcome message, which is there because we technically started editing a new file. To exit the Vim editor, we must give Vim a command (and this is different from giving the shell Shell commands!) `:q` Now press enter. You should be returned to the shell. Some quick basics on working with your file: `vi FILENAME` - open your file in vim. Upon first entering Vim, we are in “Command Mode”. That means we can’t actually type text in the file yet. We need to enter insert mode. The Vim command for this is: `i` - entering "Edit Mode" and insert before the cursor After finishing typing, don't forget to press `esc` to exit the "editing mode" and go back to command mode. In command mode, you can use the following command to save your work or quit vim: `:w` - write(save) your changes to the file `:q!` - get out of vim (quit), but without saving your changes (!) `:wq` - write(save) your changes and exit vim [Here ](https://vim.rtorr.com/)is a neat cheat sheet for you to reference when using vim until you become more familiar! **Note: all the commands listed above are case sensetive** **** ### **Configure vimrc file** The .vimrc file is a vimscript file, and vimscript is a full programming language in itself. You can use it to configure your favorite settings, key mappings and custom commands. You'll be able to edit your vimrc file by typing the following command in shell: ``` vim ~/.vimrc ``` Enter editing mode by pressing `i`. Then type the two following lines: ``` set number set colorcolumn=80 ``` Press `esc` to go back to command mode. Type `:wq` and press `enter` to save the changes. Those two lines above will show line number and set up a line length mark at the 80th character. Feel free to explore and add more configurations to vim by editing this vimrc file.