Six weeks basic computing workshop

Week 1: Linux/Unix/OSX environment

($ signs at the begining of the command lines indicate after $ is a command)
  1. Connect to the cluster using ssh.
  2. $ ssh 
  3. Clean the terminal.
  4.  clear 
  5. Lists the content of the directory. ~/ means your home directory.
  6. $ ls 
    $ ls ~/
  7. Exit from the cluster or your terminal
  8.  Ctrl+c
    $ exit
  9. Break a command
  10.  Ctrl+c
  11. Print working directory
  12. $ pwd
  13. Create a new directory
  14. $ mkdir example
    $ mkdir /home/your_user/example
  15. Change directory
  16. $ cd example
    $ cd /home/your_user/example
  17. go to one directory above
  18. $ cd ..
  19. go to your home directory
  20. $ cd
    $ cd ~/
  21. List directory with other information like file/directory privilages, data/time, size etc.
  22. $ ls -l
  23. Lists root, home, bin directories.
  24. $ ls /
    $ ls /home
    $ ls /bin
  25. List your home directory with fullpath
    $ ls /home/your_user
  26. Get help of a command
    $ ls --help
    $ man ls #(exit with q)
  27. list files with wildcard characther

    ls ls /bin/*cat*
    ls *.txt
    ls *files*
  28. Create and empty file
  29. $ cd ~/example
    $ touch myfile.txt
    $ ls -l myfile.txt
  30. Change the permission of a file or a directory
  31. $ chmod 777 myfile.txt
    $ ls -l myfile.txt
    It is easy to think of the permission settings as a series of bits (which is how the computer thinks about them). Here's how it works:
    rwx rwx rwx = 111 111 111
    rw- rw- rw- = 110 110 110
    rwx --- --- = 111 000 000
    and so on...
    rwx = 111 in binary = 7
    rw- = 110 in binary = 6
    r-x = 101 in binary = 5
    r-- = 100 in binary = 4
    Some examples:
    Value	Meaning
    (rwxrwxrwx) No restrictions on permissions. Anybody may do anything. Generally not a desirable setting.
    (rwxr-xr-x) The file's owner may read, write, and execute the file. All others may read and execute the file. This setting is common for programs that are used by all users.
    (rwx------) The file's owner may read, write, and execute the file. Nobody else has any rights. This setting is useful for programs that only the owner may use and must be kept private from others.
    (rw-rw-rw-) All users may read and write the file.
    (rw-r--r--) The owner may read and write a file, while all others may only read the file. A common setting for data files that everybody may read, but only the owner may change.
    (rw-------) The owner may read and write a file. All others have no rights. A common setting for data files that the owner wants to keep private.
  32. Learn vi
  33. vi editor: (Try the functions below especially the once we didn't use in the session)
    i insert text from current cursor position;
    esc return to command mode; used by most change commands
    q! quit the vi without saving
    wq! quit vi with saving
    I insert text at start of line;
    o opens a new line below cursor
    O opens a new line above cursor
    J joins next line to end of current line
    r replace character under cursor
    R enters replace (typeover) mode;
    s substitute character under cursor with one or many;
    S substitute whole line;
    a appends after cursor;
    A appends after current line;
    cw change current word starting at cursor;
    C change to end of line;
    dw delete current word starting at cursor
    dd delete current line; delete 3 lines (3dd)
    D delete to end of line
    h, j, k, l move the cursor around. h=left, j=down, k=up, l=right
    ^F move forward full screen
    ^B move back full screen
    ^U move up half screen
    ^D move down half screen
    ^L clear and redraw screen (R)
    w move forward to beginning of next word
    W move forward to beginning of next word after space
    e move cursor to end of word
    E move cursor to next space
    $ move cursor to end of line (3$ moves to end of third line)
    b move cursor to beginning of word
    B move cursor to previous space
    0 (zero) move cursor to beginning of line
  34. Create the file below with vi
  35. $ cd ~/example
    $ vi myfile.txt 
    1	human	        30 
    2	mouse	        20
    3	zebrafish	15
    4	yeast	         5
    5	fly	        25
  36. Look at your file
  37. $ cd ~/example
    $ more myfile.txt
  38. Look at your file with fullpath
  39. $ more /home/ak97w/example/myfile.txt
    $ less /home/ak97w/example/myfile.txt
  40. Look first ten lines of your file
  41. $ head myfile.txt
  42. Look first two lines of your file
  43. $ head -n 2 myfile.txt
  44. Look last ten lines of your file
  45. $ tail myfile.txt
  46. Look last 3 lines of your file
  47. $ tail -n 3 myfile.txt
  48. copy a file
  49. $ mkdir backup
    $ cp myfile.txt backup/mynewfile.txt
  50. copy a directory
  51. $ cp -r backup newbackup
  52. mova a file(rename)
  53. mv backup/mynewfile.txt backup/mynewname.txt
  54. move a directory
  55. $ mv newbackup movedbackup
  56. A little bit awk. Show second column of a file
  57. $ awk '{print $2}' myfile.txt
  58. Switch second and third column of a file and print to the screen
  59. $ awk '{print $3"\t"$2}' myfile.txt
  60. Switch second and third column of a file and write to a file
  61. $ awk '{print $3"\t"$2}' myfile.txt > myswithedfile.txt
  62. Get the detailed list of the files and print only permission column
  63. ls -l|awk '{print $1}'
  64. Find a file
  65. find /home/your_user -name *.txt
    find --help

For more vi tutorials and cheat sheet;

For linux commands and cheat sheet;

Your homework (deadline: Jul 17, Thursday 17:00pm):

  1. Please create “homework” directory in your home folder.

  2. Create a week1 directory under homework

  3. Create a tab separated file under week1 named mylibrary.bed that includes

  4. chr3	5000 6000	Fgf21	0 +    
    chr1	1000 2000	Cyc1	0 +    
    chr2	3000 4000	Tdp43	0 - 
  5. write an awk command to show only gene names and write the output into genenames.txt in the same folder. Write the awk command into Readme.txt file in the same folder.