Introduction to Computing and Unix


Today’s Topics

First, a few things about computing

See resources page

What is a program?

What is programming

Why program?

Elements of style

Languages


A note on backups: Everyone should back up their computer regularly. We will discuss some commands today that can remove files, or even your entire file system if you are not careful.

File systems

Remember - Whenever you call the full path, you can reach the file from anywhere on your computer. Relative paths will change based on your current location.

Unix

Let’s try out some commands

Command Translation Examples
cd change directory cd /absolute/path/of/the/directory/
Go to the home directory by typing simply cd or cd ~
Go up (back) a directory by typing cd ..
pwd print working directory pwd
mkdir make directory mkdir newDirectory creates newDirectory in your current directory
Make a directory one level up with mkdir ../newDirectory
cp copy cp file.txt newfile.txt (and file.txt will still exist!)
mv move mv file.txt newfile.txt (but file.txt will no longer exist!)
rm remove rm file.txt removes file.txt
rm -r directoryname/ removes the directory and all files within
ls list ls *.txt lists all .txt files in current directory
ls -a lists all files including hidden ones in the current directory
ls -l lists all files in current directory including file sizes and timestamps
ls -lh does the same but changes file size format to be human-readable
ls ../ lists files in the directory above the current one
man manual man ls opens the manual for command ls (use q to escape page)
grep global regular
expression parser
grep ">" seqs.fasta pulls out all sequence names in a fasta file
grep -c ">" seqs.fasta counts the number of those sequences
cat concatenate cat seqs.fasta prints the contents of seqs.fasta to the screen (ie stdout)
head head head seqs.fasta prints the first 10 lines of the file
head -n 3 seqs.fasta prints first 3 lines
tail tail tail seqs.fasta prints the last 10 lines of the file
tail -n 3 seqs.fasta prints last 3 lines
wc word count wc filename.txt shows the number of new lines, number of words, and number of characters
wc -l filename.txt shows only the number of new lines
wc -c filename.txt shows only the number of characters
sort sort sort filename.txt sorts file and prints output
uniq unique uniq -u filename.txt shows only unique elements of a list
(must use sort command first to cluster repeats)



Handy dandy shortcuts

Shortcut Use
Ctrl + C kills current process
Ctrl + L
(or clear)
clears screen
Ctrl + A Go to the beginning of the line
Ctrl + E Go to the end of the line
Ctrl + U Clears the line before the cursor position
Ctrl + K Clear the line after the cursor
* wildcard character
tab completes word
Up Arrow call last command
. current directory
.. one level up
~ home
> redirects stdout to a file, overwriting file if it already exists
>> redirects stdout to a file, appending to the end of file if it already exists
pipe (|) redirects stdout to become stdin for next command


Homework

  1. using commands and arguments
    • Find a partner to do the assignment. Spend 15 minutes using the commands on the cheat sheet with a directory on your computer. Be sure to try different arguments and use both files and directories.
    • Look up at least one command and read about all of its options. Share with your partner.
    • Create a directory called “My Directory”. What happened?
  2. redirecting output
    • Create a new file containing your bash history.
    • How many times did you use the command ls?
    • Be sure to use these three symbols: |, >, »
  3. google groups!
    • Post at least one question and one answer on the google groups page regarding what we covered today.

[top]