U: Drive, Unix, and the Command Line
Your U: Drive
Note: H Drive replaced by U: drive
- In summer 2018, RU changed from H drives to U: drives
- What used to be available on your H drive
is now available on your U: drive
- The H drive still exists, and files can be stored on either.
- Only files stored on the U: drive are available on Unix
- Your public_html directory is only available on the U: drive, not the H drive
What is Mapping Your U: Drive and Why Do It?
- Your U: drive is storage provided by the university
- You can access this storage from anywhere on campus and from off campus (with a VPN
connection
- Mapping your U: drive makes it available as a File Explorer window on the PC
- Once U: is mapped, you can simply drag and drop it to and from your U:
drive window
- This moves files to and from RUCS
Mapping Your U: Drive
- On a Windows 10 PC, do the following:
- Locate "This PC"
- Right click on This PC
- and select Map Network Drive
- Select U: from the Drive dropdown
- In the Folder textbox, enter \\userdir\unix\yourRUuserid
- This is your email userid, not your ID number
- FYI, your H: drive is at \\userdir\yourRUuserid
- Click Finish
- You can choose whether to Reconnect at sign-in
Accessing your U: Drive from Off Campus
- If you are off campus, then you must have a VPN session running to access your U: drive
- Download the VPN client from RU One Stop, install it, and run it before trying to access your
U: drive
- IMPORTANT: If you are NOT logged into the machine using your RU userid, then after starting
VPN, you will have to do an extra step to access your U: drive:
- On the Map Network Drive Screen described above, Select Connect using different credentials
- After pressing Finish, you will get a login box
- In the User name box, enter RADFORD\yourRUuserid if the Domain does not show RADFORD
- Enter your password
Accessing Rucs and What is a Shell
VPN Client Required
- To access rucs from off campus you must first run a VPN session on your
home machine
- VPN stands for Virtual Private Network
- When running VPN, your machine is treated as if it's on campus
- To run a VPN: First download the VPN client from RU One Stop, then install it.
After this is done, you can run VPN client
to give access to your U: drive and to rucs login
Windows: Use Putty to Access Rucs
- To access rucs from windows you will use a program such as putty that gives
command line access
- putty is available on lab machines
- For home machines you can download putty
- Directions:
- For host name, enter "rucs"
- Press open
- Accept the certificate
- Login with your RU uid and password
Accessing from a Mac or Linux System
- A terminal window will allow you to access rucs
- Must be on campus or have vpn client running
- Enter "ssh userid@rucs.radford.edu"
- You may need to enter "./ssh userid@rucs.radford.edu"
- Make sure that you use your RU userid, not the userid on your local machine
- Enter your RU password
What is a Terminal Window?
- Putty and terminal windows provide you with access to a remote machine
- For us, this remote machine is rucs
- Where is rucs?
- We will say "putty" for putty/terminal window
- No GUI access to rucs
- Steps of interaction
- Putty sends each line of input to the remote machine
- Commands in the line of input are executed by ... the remote machine
- The results from the commands are sent back to putty
- Putty then dispays these results and awaits your next command
- After you log in, the remote machine is running a shell
- A windows command window is similar
What is a Shell?
- After login, putty provides you with a shell running on a remote machine
- A shell is a program reads and executes commands from the command line
- The underlying shell program looks like this:
loop
get(command_line);
exit when command_line = "exit";
process(command_line);
end loop;
Different shells include bash, sh, csh, and tcsh
Below you can see how to find out your shell (ie command ps)
Command Line Commands
Command Line Commands
- What can we do:
- Query the system
- Access files and folders
- Run programs
- Results appear in terminal window
- Unix is case sensitive (windows is not)
- Options are introduced with dash (see below)
- Commands are short (from days of small memories)
ps - Query Processes
- ps - gives a list of processes currently running that:
- belong to this user
- were started during this session
- A process is a program executing on the system
- An executing program may be paused and waiting for something
Current Shell
- Output from ps shows what shell you currently have running
- The shell will show up as a process
- This information can be useful later
Command Line Options
- Specify options using dash
- Example: ps -a - shows all processes belonging to current users
- Shows processes started elsewhere
- Example: ps -e - shows all processes belonging to all users
- More Options:
- -e -A = all
- -f -F - full or really full
- -j - jobs
- -H- process hierarchy
- -u - user oriented
More on Command Line Options
- Options that are a single letter are normally preceded by a single dash (ie '-')
- Options that are a single word are normally preceded by two dashes (ie '--')
- Example: ps -a --forest
- Example: ps --help
- Multiple options can sometimes be combined
- Example: ps -e - show all processes
- Example: ps -l - show processes in long format
- Example: ps -H - show processes in tree format
- Example: ps -elH - show all processes in long format and tree format
Questions: How to show how many processes and how to show one screenful at a time?
Pipes
- The pipe (ie '|') sends the output from one command to the input of another
- Example: "ps | wc"
- wc is the command word count: it lists a count of lines, words, bytes in input
- ps | wc runs ps and the pipe sends the output of ps to the input of wc
- What does
ps -e | wc
give?
- Very common in Unix to combine commands with a pipe
- Example - count number of unique lines: Sort myfile | uniq | wc
less - Display a Screen at a Time
- Example: ps | less - displays the output of ps a screen at a time
- Advance with space or ctrl-F
- Go back with ctrl-B
- Quit with q
- Search with /string
- Can also say "less fn" to display contents of file fn
man - Get Help on a Command
- man ps - get help with ps
- Works like less
- man -k word - keyword search of man pages
Directories (ie Folders)
Directory Definition
- Directory: Collection for files and other directories
- aka folder
- Abbreviate as "dir"
- Thus: There is a hierarchy of folders (ie one inside another inside another)
- One folder is at the top - not inside anything
- All other folders have a parent
- Many folders have children
Path - Absolute and Relative
- Shows where a file or folder are within the hierarchy
- Written sequence of folders, separated by /
- Example: /home/nokie/DemoUnix
- Folders are hierarchical (eg DemoUnix is a folder in nokie, a folder in home which is at the top)
- Absolute Path: begins with /. not nested in anything.
- Relative Path: does not begin with /
- Name is relative to the current directory
- Examples:
- /home/nokie/DemoUnix is absolute
- DemoUnix/foo is relative
- foo can be either a folder or file in DemoUnix
Current Directory
- Directory that a command operates on if no directory is specified
- AKA Working directory
- Essentially the default directory
- On login, current directory is /home/your_username
- This is also your U: drive
Home Directory
- Your home directory is /home/userid
- When login to rucs, your current directory is set to your home directory
- Your home dir is the same your U: drive
- ~ - another name for your home directory
Special Directories
- ~ - Your home dir
- . - the current directory
- .. - the parent of the current directory
- Can chain together: eg ../../..
Completion and Command Line Editing
- In many cases, you can press TAB to get command line completion
- If you want to use vim commands to edit the command line, enter
- for bash: set -o vi
- for csh and tcsh: bindkey -v
- Use j and k to traverse history, h, l, w, b to move right and left,
i to enter insert mode, esc to exit insert mode
Directory Related Commands
pwd - Print Working Directory
- pwd - Print Working Directory
- Gives name of current directory
cd - Change Directory
- Changes current directory
- Example: cd UnixDemo
- Relative path
- Only works if in /home/nokie (ie the directory that contains UnixDemo)
- cd /home/nokie/UnixDemo
- Absolute path
- Works from anywhere
- cd - (goes to previous directory)
- What do these do?
- cd ~
- cd ..
- cd ../..
- cd ../foofoo
- cd .
- cd
ls - List Files
- ls - lists files in current directory
- ls -l - lists files in long format
- What do these do?
- ls -a - lists all (including . files)
- ls -F - marks directories and executables
* - Wild Cards
- Many commands allow use of * as a wildcard
- Example: ls *.adb - lists all .adb files
- Example: ls p*.adb - lists all .adb files whose names start with p
- Example: ls p0.* - lists all files whose names start with p0.
- Example: ls */* - lists all files in child dirs
mkdir and rmdir - Make and Remove a Directory
- mkdir
- mkdir foofoo - creates dir foofoo in current dir
- mkdir ~/foofoo - creates dir foofoo in home dir
- mkdir
- rmdir foofoo - removes dir foofoo in current dir
- rmdir ~/foofoo - removes dir foofoo in home dir
- rmdir only works if the directory to be removed is empty
File Commands
cat, more, less, head, tail - viewing files
- cat foo - displays contents of file foo, all at once
- less foo - displays contents of file foo, a screen at a time
- Can go forward and backward with ctrl-F and ctrl-B
- Restores screen after display
- more foo - displays a screen at a time like less, no backwards, does not restore screen
- head foo - show first few lines of foo
- head -n foo - show first n lines of foo
- tail foo - show last few lines of foo
- tail -n foo - show last n lines of foo
- tail -f foo - show last few lines of foo, displays lines as they are added
cp - Copy
- Operation depends on whether or not last operand is a directory
- cp p1.adb p2.adb - creates p2.adb as a copy of p1.adb
- cp p1.adb somedir/p3.adb - creates a copy of p1.adb in somedir called p3.adb
- cp p1.adb somedir - creates a copy of p1.adb in dir somedir
- cp ~/foo.adb . - copies foo.adb from home dir to current dir
- cp ./foo.adb ~ - copies foo.adb from current dir to home dir
mv - Move or Rename a File
- Operation depends on whether or not last operand is a directory
- mv aaa.adb bbb.adb - renames aaa.adb to bbb.adb
- mv aaa.adb foo - moves file aaa.adb to dir foo
- mv aaa.adb foo/bbb.adb - moves file aaa.adb to dir foo and changes name to bbb.adb
rm - Remove a File
- rm foo - deletes file foo
- rm -i foo - Interactive remove (ie ask are you sure)
- rm -r foo - RECURSIVELY deletes dir foo and all of its files (CAUTION!! DON'T DO THIS!!!)
- rm does NOT move to a recycle bin or garbage can! File is REALLY GONE!
Alias
- Give a command a new name and/or define options
- alias ls ls -F
- Entering ll executes ls -F
- Add to .cshrc or .bashrc or .profile
Job Control
- Ctrl-z suspends the current job
- jobs lists the executing jobs
- fg resumes the most recent job (ie brings it to the foreground)
- fg resumes the most recent job as a foreground process
- fg %n - resumes job n
- kill %n - kills job n
diff, grep, wc - compare, search, count a file
- diff fn1 fn2 - display differences between files fn1 and fn2
- grep string f1 f2 - searches for string in file foo
- grep string fn* - searches for string in all files whose names start with fn
- grep string * - searches for string in all files in current directory
Redirect Input and/or Output
- Programs normally read from Standard Input (Ada and Java and ...)
- Programs normally write to Standard Output (Ada and Java and ...)
- Pipes send standard output to standard input
- Standard Input is normally the keyboard
- Standard Output is normally the screen
- Can make standard input read from a file:
- Example: homeword_one < somefile.txt - causes homeword_one to read two
integers from file somefile.txt instead of the keyboard
- Example: homeword_one > myOutputFile.txt - causes homeword_one to send its
output to the file myOutputFile.txt instead of the screen
- Can be combined: homeword_one < somefile.txt > myOutputFile.txt
More Fun with Redirection and Pipes
- Another way to send output of one command to another - allows access to output from two commands:
diff <(ls somedir) <(ls anotherdir)
- Compares the contents of directories somedir and anotherdir
- The < must be adjacent to the (
- A second way of comparing
comm <(ls somedir) <(ls anotherdir)
Use standard input in place of a file argument:
- Normally diff takes two files, but diff can also use standard input
- The following shows both ways and do the same comparison:
diff file1 file2
cat file1 | diff - file2
This is useful for checking the results of a running a program if you have the correct
result in a file:
./myprogram < myinputfile | diff - correct.output.txt
This example runs myprogram with input redirected from myinputfile, and then it diffs
the output from the program with the correct output
Startup Files
- Can put options (eg alias) in a startup file
- Examples startup files: .cshrc, .bashrc, .profile
- Put in home directory
- Vim users: .vimrc contains startup commands for vim
Path
- Specifies where shell looks for commands
- echo $PATH - to see path (on cshell
Environment
- printenv - prints environment variables and their values
- setenv - prints environment variables and their values
- setenv variable value - set environment varible to value