Name:
PID:
Some Key Commands
cat <path1> <path2> ... Prints the contents of one or more files given by the paths
ls <path> - “List” Used to list the files and folders the given path
pwd - “Print working directory” Used to display the current working directory
cd <path> - “Change Directory” Used to switch the current working directory to the given path
Example file structure:
/Users/
|- joe/
|- lecture1/
|- Hello.java
|- README
|- messages/
|- en-us.txt (English, USA)
|- es-mx.txt (Espanol, Mexico)
|- zh-cn.txt (Chinese, PRC)
Absolute path: Where a single file or folder is within a filesystem Example: /Users/joe/lecture1/README
Root folder/directory: The folder that isn't contained in any other folder. Often written as / or C:\\
Relative path: A part of a path that doesn't start with the root. Example: lecture1/README
Current/working directory: An absolute path to a directory that a program or terminal uses to resolve relative paths.
Parent directory: The directory “above” or “outside” the current directory. In paths, written ..
Home directory: A directory where a user's files are stored, which can be abbreviated as ~ at the start of a path
Consider the following working directories, relative paths, and corresponding absolute paths. Fill in the blanks. Assume the home directory is /Users/joe
To resolve a relative path, join it with the current working directory, then collapse directory names that are followed by ..
Working Directory (pwd) Relative Path Absolute Path
/Users/joe lecture1 /Users/joe/lecture1
/Users/joe/lecture1/messages ../Hello.java /Users/joe/lecture1/Hello.java
/Users/joe/lecture1 /Users/joe/lecture1/messages/en-us.txt
/ Users/joe
/Users/joe/lecture1 ..
/Users/joe/lecture1 Goodbye.java
/Users/joe/ messages/
/Users/joe/lecture1 ~/lecture1/Hello.java
/Users/joe ~/lecture1/Hello.java
joe $ pwd
/Users/joe/lecture1
joe $ ls
Hello.java README messages
joe $ cat messages/en-us.txt messages/es-mx.txt
Hello World!
Hola Mundo!
joe $ cd messages
joe $ pwd # fill in the blank below
joe $ cat en-us.txt zn-ch.txt
Hello World!
你好世界
Name:
PID:
ssh <username>@<servername>
ssh switches your terminal's context to running commands on another computer. It stands for "secure shell". A shell is the program running in your terminal, or on another computer, to run commands. Depending on how the other computer, and your account, is set up, commands may work a little differently in the remote shell compared to on your computer. The commands will be working with the filesystem from that computer.
What are some reasons you might want to run commands on a computer that isn't the one you're physically logged into? Discuss with the people around you, and write down some thoughts.
joes-computer $ ssh cs15lsp23zz@ieng6.ucsd.edu
(cs15lsp23zz@ieng6.ucsd.edu) Password: <type in password>
... lots of messages about the server ...
Sun Sep 25, 2022 8:26pm - Prepping cs15lsp23
[cs15lsp23zz@ieng6-203]:~:212$ cat WhereAmI.java
class WhereAmI {
public static void main(String[] args) {
System.out.println(System.getProperty("os.name"));
System.out.println(System.getProperty("user.name"));
System.out.println(System.getProperty("user.home"));
System.out.println(System.getProperty("user.dir"));
}
}
[cs15lsp23zz@ieng6-203]:~:213$ javac WhereAmI.java
[cs15lsp23zz@ieng6-203]:~:214$ java WhereAmI
Linux
cs15lsp23zz
/home/linux/ieng6/cs15lsp23/cs15lsp23zz
/home/linux/ieng6/cs15lsp23/cs15lsp23zz
[cs15lsp23zz@ieng6-203]:~:215$ exit
logout
Connection to ieng6.ucsd.edu closed.
joes-computer $ javac WhereAmI.java
joes-computer $ java WhereAmI
Mac OS X
joe
/Users/joe
/Users/joe/lecture2
[ieng6]:~$ ls
WhereAmI.java example
[ieng6]:~$ cd example/
[ieng6]:example$ ls
[ieng6]:example$ cat message.txt
cat: message.txt: No such file or directory
[ieng6]:example$ exit
logout
Connection to ieng6.ucsd.edu closed.
joes-comp $ ls
message.txt
joes-comp $ scp message.txt cs15lsp23zz@ieng6.ucsd.edu:~/example/
(cs15lsp23zz@ieng6.ucsd.edu) Password:
message.txt 100% 7 0.6KB/s 00:00
joes-comp $ ssh cs15lsp23zz@ieng6.ucsd.edu
(cs15lsp23zz@ieng6.ucsd.edu) Password:
...
Sun Sep 25, 2022 8:53pm - Prepping cs15lsp23
[logout]:~:224$ ls
WhereAmI.java example-lecture-2
[logout]:~:$ cd example
[logout]:example:$ cat message.txt
hello!
scp <file1> <file2> <username>@<servername>:<path>
scp copies files from one computer to another; it stands for "secure copy". It uses the same accounts and logins as ssh, so if you can ssh into a computer, you can copy files to it with scp.
What do you notice and wonder about these terminal interactions? What's new? What's confusing?
You all have accounts specific to CSE15L on a server called ieng6.ucsd.edu that is managed by UCSD. A server is another word for a computer or a program running on a computer that enables communication to other programs and computers – ssh is one of the programs that does this communication.