Wherever you see <your CLASSE username> below, substitute your own CLASSE username.
Open a terminal on lnx201 using one of the following options:
sshfrom your computer's terminal (for Mac and Linux users)- Type
ssh <your CLASSE username>@lnx201.classe.cornell.edu
- Type
- PuTTY (for Windows users)
- Use CLASSE's NoMachine service
- Browse to https://nomachine.classe.cornell.edu
- Respond to Duo prompt
- Click on
lnx201 - Create a new desktop or custom session → Create a new virtual desktop
- Click on Terminal icon in bottom menu bar
- To log out: Applications → Log Out
- Use CLASSE's JupyterHub service
- Browse to https://jupyterhub.classe.cornell.edu
- Respond to Duo prompt
- Server Options: Select a job profile: CLASSE Compute Farm, click Start
- Launcher tab: Terminal
- OR File → New → Terminal
- To log out: File → Log Out
After logging in, you will be in your home directory. Start navigating in the same terminal window as before. Run the following commands:
pwd- pwd = print working directory. This commend tells you what the current working directory is
ls- This command lists the contents of your current working directory
ls -la- This command lists the contents of the current working directory with the additional options
-ltellslsto show details about each file’s type, permissions, size, etc. (lowercase “l” = “long”)-atellslsto list hidden files, too (“a” = “all”)
- Individual options to ls like
-land-acan be shortened to-la - How to read the output of
ls -l: https://docs.nersc.gov/filesystems/unix-file-permissions/
- This command lists the contents of the current working directory with the additional options
Do not make a habit of working in your home directory /home/<your CLASSE username>!
Instead, use your CHESS user directory: /nfs/chess/user/<your CLASSE username>.
- Type
cd /nfs/chess/user/<your CLASSE username>- cd = change directory
- If your CHESS user directory does not exist, first type
mkdir /nfs/chess/user/<your CLASSE username>
- OR, use the premade symbolic link in your home directory:
- Type
cd /home/<your CLASSE username>/CLASSE_shortcuts/chess_<your CLASSE username>
- Type
- Repeat Exercise 2 and observe how your CHESS user directory differs from your home directory
- Return to your home directory
- Type
cd /home/<your CLASSE username> - OR type
cd ~- The tilde symbol
~is shorthand for your home directory
- The tilde symbol
- Type
Tab completion is an extremely useful feature of the Linux command line that helps you type commands much faster. It works with commands and file paths. Simply start typing one or two characters of a command or file path, then hit the tab key. The command line will automatically fill in additional characters if it can. If it cannot fill in your command or file path all the way, hit the tab key twice to see the available options. (Unfortunately tab completion is not available in the JupyterHub terminal.)
For example:
- Type
cd ~/CL, then hit thetabkey- The command line should automatically complete what you typed to
cd ~/CLASSE_shortcuts/(unless you have another file or directory that begins with "CL") - Hit
return. Now you are in the CLASSE_shortcuts directory within your home directory - Type
lsto see the directory contents
- The command line should automatically complete what you typed to
- Type
cd ch, then hit thetabkey- This time, the command line can only partially complete what you've typed. Hit the
tabkey twice to show the available options, one of which should bechess_<your CLASSE username>. - Now, type the first letter or two of your CLASSE username and hit
tabagain. - If the command line was able to complete your username, then hit
returnto go to your CHESS user directory- If not, keep typing letters followed by
tabuntil your username is complete, then hitreturn
- If not, keep typing letters followed by
- This time, the command line can only partially complete what you've typed. Hit the
In Linux (UNIX), a pipe (|) is used to connect the output of one command to the input of another. This allows for powerful chaining of small utilities to perform complex tasks, following the UNIX philosophy:
"Do one thing well."
For example:
command1 | command2means “take the output of command1 and pass it as input to command2”.
For the following set of exercises please review Linux commands like echo, cat, env, grep, more and less.
# print string; the flag -e will properly handle backslash escapes `\n`
echo -e "apple\nbanana\ncherry"
# now combine commands via pipe
echo -e "apple\nbanana\ncherry" | grep 'an'What will be printed?
Expected:
banana
env | grep SHELLList all environment variables, then print only the one that specifies your current shell.
Combine Linux tools introduced above and redirect the output to produce a new file.
# find who you are
env | grep USER
# make new area on /tmp (default temporary area on ANY Linux node)
mkdir /tmp/$USER
# create new file in /tmp/$USER area
echo "my data" > /tmp/$USER/file.dat- What would be content of /tmp/$USER/file.dat?
- Can you print content of the /tmp/$USER/file.dat?
Hint: cat tool can be used both for viewing and creating files
# create new file
cat > /tmp/$USER/file.txt << EOF
one
two
three
EOF
# view the file
cat /tmp/$USER/file.txt
# chain together multiple commands with pipe
cat /tmp/$USER/file.txt | grep t | wc -l
Linux offer two pagination tools less and more, which can be combine with the pipe concept:
# use paginators, less and more
ls /etc | lessUse either tool to view and navigate large files or lengthy output from a command.