Before this course, install theUni-VPNand confirm that it works [estimated time: 5-10 minutes]
In this class, we will introduce the idea of the command line, executing commands without the normal graphical user interface (GUI) and accessing remote computers via ssh (Secure Shell).
On Windows or Mac, search for "terminal" in the launcher. You should see a small black box (called a "Command Prompt" in Windows) with a cursor. On Windows, you can also type
cmd.exein the search field in the lower left corner.
Note that the cursor appears after some information indicating the file path and/or the identity of the computer. Just as RStudio has a working directory, a place to load or save files, so does the command line. This is very important, as many command line statements only work if they are executed.in the right place.
8.2Change folder ("browse directory tree")
Get the content of the current directory with
directory(without Windows) o
You will get a list of contents, some of them are folders, some are files. Can you identify what is what?
You can change to a subfolder with
CD folder name. With you can move up/down the road
You can get the current path
People with disabilities(Mac)
This allows you to browse all the files stored on your computer. It's cumbersome and annoying compared to the normal GUI method, but it's more fundamental to the "under the hood" operation of computers, and this way of interacting with computers is necessary in some situations (including frequent access to remote computers). .
Remember that, like in RStudio, you can use TAB to complete commands.
Computers connected to a network have an address, known asIP adress, which are always four numbers separated by periods. Are you used to dealing with domain names likesheffield.ac.uk, but these names exist for human convenience. Like the command line for individual computers, IP addresses are closer to how computer networks work.
Copy this IP into your browser and see which website it takes you to:22.214.171.124.
Your computer is also connected to the Internet, so it has an IP address. You can find out by typing
ifconfig(Mac) from the command line. (You can also google "what's my IP", but that won't work for what we're going to do.) This command should provide a lot of information. Look up the IP addresses. If you are at home you can see one with the first two numbers
192.168.xxx.xxx. If you are on campus, you should see an IP in the format "172.xxx.xxx.xxx". All computers on the university network have IP addresses that start with the same number.
Now start the college VPN and find your IP again. If you're off campus, this should change, so you now have an IP starting with 172. Remember this number, we'll use it later.
Computers communicate with each other in many different ways, but you are probably most familiar with web pages: the "World Wide Web" (www) that is served throughprotocolo http.
One of the easiest ways for two computers to communicate is
RingThis is just a tool to check if two computers can send and receive messages. The content of the message is not important, just check that both are connected to the network.
You can ping an IP or a website. Try it on the command line
You should receive a series of lines telling you how long it took your computer, in milliseconds, to receive a message to and from this site. Try somewhere further away.
ping wapo.com(US East Coast), or
ping globaltimes.cn(China continental)
But we can also ping individual computers. "sharc" is one ofhigh performance computing(HPC) in Sheffield. You can only talk to him if you are within the university network (ie you have to be on campus or activate your VPN). To try
If you have your VPN enabled correctly it will work.
8.5Remote access via SSH
If two computers are connected, you can access one remotely with a command called ssh. take the form
Tom will set up a machine for you to try this out in class. If it's successful, you should see something like this.
The terminal is similar, but the commands you run will now be executed on that remote computer. It is also possible that you have changed your operating system so that instead of using Mac or Windows commands, you need to use commands that work on the remote computer. Many HPC machines and web servers are Linux machines (including the one we'll connect to in class).
8.6Find files, run files, copy files
This section assumes that you are working on a remote Linux machine.
Let's use the command
Thinkto search for R scripts on this remote machine. The use of * here is called a "wildcard".
find -name '*.R'
We can run R on the remote machine, but it can't run RStudio (because the terminal doesn't display graphics, just text). Running software without the GUI is called headless running software.
Starts an interactive R console. stop me
But we can also run the script without starting R (so the script runs and exits, leaving us back in the terminal. You can navigate to the containing folder and run it.
You can also pass the script to R by providing the full path
Find out how long the script takes to run by typing put
tempo Rscript toyscript.R
Now there is no point in running a simple R script remotely, but if you have a large amount of data, it might be useful to run your analysis on a more powerful remote machine (or many remote machines that allow parallel processing).
Let's copy this script from the remote machine to our home machine. For that you need the
scpcommand and know your username and IP address. The path where the file will be saved comes after the colon:
scp toyscript.R user@your_ip:/path/to/Desktop/toyscript.R
scp works on Linux or Mac, but not on Windows.
We often feed additional switches (sometimes called "switches") to command line tools. then the command
speakspeak words out loud
we can read themTalk Documentationto see what options are available. Let's adjust the pitch and speed.
espeak -p 8 "Hello, but with extra seriousness"
espeak -s 230 "Hello my name is fast"
These exercises must be completed during the week following the class, since the remote device is not permanently on. See in Slack the IP, username and password for remote access
- Enter the remote IP in a browser; this will display a website served by the remote computer
- remote access via ssh
- Locate the index.html file
- Note: It is located in /var/www/html
- Copy to your local computer using scp
- edit it with a text editor and save it to your local computer
- copy back to server
- Look again at the IP address in a browser to see if it has changed (remember to press refresh/F5/clear cache).
- Identify and open a terminal window
- Navigate the directory tree using command line instructions
- find your ip address
- Ping an IP or website
- Find files, run programs, on remote computers
- Pass options to command line tools using options
- Copy files to/from remote machines with scp
- Five Reasons Researchers Should Learn to Love the Command Line
- University of Sheffield VPN
- For historical interest:At first... it was the command line(1999)Neal Stephenson
- If you want to try Linux, you can start withLinux libre