Every Day UNIX and Working with Hoffman: Difference between revisions

From Center for Cognitive Neuroscience
Jump to navigation Jump to search
 
 
(10 intermediate revisions by 3 users not shown)
Line 1: Line 1:
=Logging Into Hoffman (terminal vs. virtual desktop)=
==The Trifecta of Every Day Unix==
There are two options for logging into Hoffman2. The first is the one you know - and which is documented elsewhere. Open up a terminal window (or terminal emulator on a PC) and use the ssh -X loginname@address to log into your favorite node. More information is available on the ATS website.
 
The other approach is to create a virtual session with a node on Hoffman2. This is akin to a VNC approach (implemented by ATS to work with a web-browser) but is slightly more functional. It is more powerful for anyone working remotely and it has the built in ability to keep sessions open/running even if your internet connection dies (kind of like Screens in the terminal but prettier). To use this approach you need to:
 
 
# install NX Client for your system from [http://www.nomachine.com/download.php/ www.nomachine.com/download.php]
# via terminal, log into a node of your choice on Hoffman2 and then view the contents of the Hoffman DSN key using the cat function, e.g., ssh login4; cat /etc/nxserver/client.id_dsa.key
# on your machine, launch NX Client and set up a session with the following parameters: your login name and password, address of your favorite login node (e.g., login4.hoffman2.idre.ucla.edu)
# when you go to start your session you'll have to press configure (looks different on Mac vs. PC but you can find it) - navigate to where you see a "key" button and press it
# copy and paste THE ENTIRE DSN key (produced by the cat command in step 2) to replace any text that you see in this window
# save, and log in
 
 
Once in - you are working on a linux desktop. In the bottom left (or right) you'll see a PC-style button which will display all the folders, and in Systems (I *think*) is where you'll find Terminal.
 
 
a.l.
 
=The Trifecta of Every Day Unix=
Working with UNIX and UNIX like systems via the command line can be intimidating. The good news is a normal user only needs to have a firm understanding of three principle actions to efficiently use UNIX for their every day work.
Working with UNIX and UNIX like systems via the command line can be intimidating. The good news is a normal user only needs to have a firm understanding of three principle actions to efficiently use UNIX for their every day work.


Line 24: Line 5:
# File System Navigation
# File System Navigation
# File & Shell Management
# File & Shell Management
# Learning to Fish or The Man Pages


Each of these areas require knowledge of a few small programs and how they behave. In the following sections, each program and utility is covered in detail. When appropriate, a link to the relevant wiki page on the topic is provided.  
Each of these areas require knowledge of a few small programs and how they behave. In the following sections, each program and utility is covered in detail. When appropriate, a link to the relevant wiki page on the topic is provided.  
Line 31: Line 13:
Where appropriate, links to external tutorials deemed suitable and apropriate to the topic are provided rather than reproducing the work here.
Where appropriate, links to external tutorials deemed suitable and apropriate to the topic are provided rather than reproducing the work here.


==Learning to Fish or The Man Pages==
However, possibly even more important is being able to find information on one's own. In the spirit of this, the instructional is concluded with a detailed coverage of the built-in unix manual pages. Virtually every program installed on a UNIX like system provied a manual page for reference. Even the most proficient of UNIX users could never retain the dizzying array of programs and their options in their working memory and with the built-in manual pages, they'll never need to.
The man pages (for ''manual'') are the be all end all reference on UNIX systems. When reading a man page becomes natural, you know there is nothing you can't get done quickly and efficiently.


A [http://www.tfug.org/helpdesk/general/man.html Beginners Guide to man Pages] is an excellent introduction into how to move around a man page easily and understand what it's telling you.
===POSIX Permissions===
 
==POSIX Permissions==
POSIX permissions are what determines who and to what degree users can access a file. The key terminology and function of the POSIX permission system is found on the [[UNIX Permissions]] wiki page.
POSIX permissions are what determines who and to what degree users can access a file. The key terminology and function of the POSIX permission system is found on the [[UNIX Permissions]] wiki page.


Line 49: Line 25:
* newgrp
* newgrp


==File System Navigation==
 
===File System Navigation===
The following series of tutorials provide a very basic introduction to file system navigation on unix like systems without any assumptions of prior knowledge on the topics.  
The following series of tutorials provide a very basic introduction to file system navigation on unix like systems without any assumptions of prior knowledge on the topics.  


Line 56: Line 33:
* Copying files, moving files, removing files and directories, displaying the contents of a file, searching the contents of a file
* Copying files, moving files, removing files and directories, displaying the contents of a file, searching the contents of a file
** [http://www.ee.surrey.ac.uk/Teaching/Unix/unix2.html Tutorial Two]
** [http://www.ee.surrey.ac.uk/Teaching/Unix/unix2.html Tutorial Two]
====List of Utilities Covered====
====List of Utilities Covered====


Line 70: Line 48:
* grep
* grep


==File & Shell Management==
 
===File & Shell Management===
This is where your career on a UNIX type system can be made or crippled. Sure you know how to move around, list files, find out where you are, and display the contents of files. But now you have to ''do something'' with those files. And let's face it, there are a whole lot of files.
This is where your career on a UNIX type system can be made or crippled. Sure you know how to move around, list files, find out where you are, and display the contents of files. But now you have to ''do something'' with those files. And let's face it, there are a whole lot of files.


Line 127: Line 106:
  $ find . -type f -user foo -exec chmod -R ug+rwX {} \;
  $ find . -type f -user foo -exec chmod -R ug+rwX {} \;


=Setting up your Bash Profile=
 
This is the easiest part. Just place this one, single line in your ~/.bash_profile:
===Learning to Fish or The Man Pages===
However, possibly even more important is being able to find information on one's own. In the spirit of this, the instructional is concluded with a detailed coverage of the built-in unix manual pages. Virtually every program installed on a UNIX like system provied a manual page for reference. Even the most proficient of UNIX users could never retain the dizzying array of programs and their options in their working memory and with the built-in manual pages, they'll never need to.
 
The man pages (for ''manual'') are the be all end all reference on UNIX systems. When reading a man page becomes natural, you know there is nothing you can't get done quickly and efficiently.
 
A [http://www.tfug.org/helpdesk/general/man.html Beginners Guide to man Pages] is an excellent introduction into how to move around a man page easily and understand what it's telling you.
 
 
 
==Setting up your Bash Profile==
How to set up your Bash Profile to access CCN-supported software.
: [[Hoffman2:Modules]]
<!-- This is the easiest part. Just place this one, single line in your ~/.bash_profile:
  source /u/home/FMRI/apps/etc/profile
  source /u/home/FMRI/apps/etc/profile


Line 138: Line 129:
  umask 007
  umask 007


Save, then log out and back in. This is all that is needed to gain full access to all FMRI applications. Nothing else should be put in this file, ever, unless you 100% know what you are doing and why, don't take someone else's word for it either.
Save, then log out and back in. This is all that is needed to gain full access to all FMRI applications. Nothing else should be put in this file, ever, unless you 100% know what you are doing and why, don't take someone else's word for it either. -->


=Cyberduck: An SFTP client=
==Cyberduck: An SFTP client==
Cyberduck installs like most other mac application, just drag and drop. Please see our screen cast on using [http://ccn.ucla.edu/users/jkyle/weblog/b276e/Using_Cyberduck.html Cyberduck].
Cyberduck installs like most other mac application, just drag and drop. Please see our screen cast on using [http://ccn.ucla.edu/users/jkyle/weblog/b276e/Using_Cyberduck.html Cyberduck].


=MacFuse installation=
 
 
==MacFuse installation==
#Download [http://code.google.com/p/macfuse/ MacFuse] and install it. (double click the MacFuse.mpkg file)
#Download [http://code.google.com/p/macfuse/ MacFuse] and install it. (double click the MacFuse.mpkg file)
#Download the appropriate (tiger or leopard) sshfs from the [http://code.google.com/p/macfuse/wiki/MACFUSE_FS_SSHFS MacFuse wiki]
#Download the appropriate (tiger or leopard) sshfs from the [http://code.google.com/p/macfuse/wiki/MACFUSE_FS_SSHFS MacFuse wiki]
Line 150: Line 143:
#Make sure the sshfs binary has executable permissions
#Make sure the sshfs binary has executable permissions


==Example Workflow==
===Example Workflow===
This assumes the user has downloaded and installed or unarchived the needed packages listed above. The below example assumes the leopard sshfs binary was downloaded.
This assumes the user has downloaded and installed or unarchived the needed packages listed above. The below example assumes the leopard sshfs binary was downloaded.
  $ tar xzvf sshfs-static-leopard.gz
  $ tar xzvf sshfs-static-leopard.gz
Line 156: Line 149:
  $ sudo chmod +x /usr/local/bin/sshfs
  $ sudo chmod +x /usr/local/bin/sshfs


==Example Mounting of a Hoffman2 Directory==
===Example Mounting of a Hoffman2 Directory===
Of course, you can name the /Volumes/<directory> anything you want or even put it anywhere you want. For example, I have /Volumes/Hoffman/sbook, /Volumes/Hoffman/my_home, and /Volumes/Hoffman/data
Of course, you can name the /Volumes/<directory> anything you want or even put it anywhere you want. For example, I have /Volumes/Hoffman/sbook, /Volumes/Hoffman/my_home, and /Volumes/Hoffman/data


Line 163: Line 156:
  $ sshfs your_hoffman_username@hoffman2.idre.ucla.edu:/path/to/directory/you/want/to/mount /Volumes/MyHoffmanHome -oauto_cache,reconnect
  $ sshfs your_hoffman_username@hoffman2.idre.ucla.edu:/path/to/directory/you/want/to/mount /Volumes/MyHoffmanHome -oauto_cache,reconnect


=SPM=
 
 
==SPM==
SPM8 as well as the older SPM5 are on hoffman. In order to use these, you must add the path ("Add with Subfolders") in MATLAB.
SPM8 as well as the older SPM5 are on hoffman. In order to use these, you must add the path ("Add with Subfolders") in MATLAB.
The path to spm12 is:
/u/project/CCN/apps/spm12


The path to spm8 is:
The path to spm8 is:
  /u/home/FMRI/apps/spm8
  /u/project/CCN/apps/spm8


Likewise, the path to spm5 is:
Likewise, the path to spm5 is:
  /u/home/FMRI/apps/spm5
  /u/project/CCN/apps/spm5


=FAQ=
==FAQ==
==How do I change the permissions for all files I own in a certain directory?==
===How do I change the permissions for all files I own in a certain directory?===
As a reference, please see the above section on [#File & Shell Management | File & Shell Management]. We can do this using find and chmod.
As a reference, please see the above section on [#File & Shell Management | File & Shell Management]. We can do this using find and chmod.
  $ find . -user myusername -type f -not -perm -g+w -exec chmod g+w {} \;
  $ find . -user myusername -type f -not -perm -g+w -exec chmod g+w {} \;
Line 180: Line 178:
  $ fix_perms.sh
  $ fix_perms.sh


==How do I transfer data to and from hoffman?==
===How do I transfer data to and from hoffman?===
Please see our general FAQ on how to properly transfer data between two machines found here [[FAQ#How_do_I_properly_transfer_my_data_between_two_machines_on_the_network.3F | FAQ: How do I properly transfer my data between two machines on the network]]
Please see our general FAQ on how to properly transfer data between two machines found here [[FAQ#How_do_I_properly_transfer_my_data_between_two_machines_on_the_network.3F | FAQ: How do I properly transfer my data between two machines on the network]]


==How do I switch FSL Versions?==
===How do I switch FSL Versions?===
Please see the help output of the following utility on hoffman which eases this process:
Please see [[Hoffman2:Modules]] for more information on switching FSL versions.
<!--Please see the help output of the following utility on hoffman which eases this process:
  $ switch_fsl --help
  $ switch_fsl --help
  Description: switch_fsl easily and cleanly switches between various fsl versions.
  Description: switch_fsl easily and cleanly switches between various fsl versions.
Line 200: Line 199:
  switch_fsl --switch 4.0.4
  switch_fsl --switch 4.0.4
  switch_fsl -h
  switch_fsl -h
  switch_fsl --check
  switch_fsl --check-->


==External Links==
==External Links==

Latest revision as of 14:22, 8 July 2017

The Trifecta of Every Day Unix

Working with UNIX and UNIX like systems via the command line can be intimidating. The good news is a normal user only needs to have a firm understanding of three principle actions to efficiently use UNIX for their every day work.

  1. POSIX Permissions
  2. File System Navigation
  3. File & Shell Management
  4. Learning to Fish or The Man Pages

Each of these areas require knowledge of a few small programs and how they behave. In the following sections, each program and utility is covered in detail. When appropriate, a link to the relevant wiki page on the topic is provided.

Each section is followed by an itemized list of the programs covered and some links to further information on that particular utility as well as the command to bring up the man page for the utility contained with parthesis.

Where appropriate, links to external tutorials deemed suitable and apropriate to the topic are provided rather than reproducing the work here.


POSIX Permissions

POSIX permissions are what determines who and to what degree users can access a file. The key terminology and function of the POSIX permission system is found on the UNIX Permissions wiki page.

List of Utilities Covered


File System Navigation

The following series of tutorials provide a very basic introduction to file system navigation on unix like systems without any assumptions of prior knowledge on the topics.

  • Listing files & directories, making directories, changing directories, the . and .. directories, pathnames, the "home" directories
  • Copying files, moving files, removing files and directories, displaying the contents of a file, searching the contents of a file

List of Utilities Covered

  • ls
  • mkdir
  • cd
  • pwd
  • cp
  • mv
  • rm
  • cat
  • less
  • head & tail
  • grep


File & Shell Management

This is where your career on a UNIX type system can be made or crippled. Sure you know how to move around, list files, find out where you are, and display the contents of files. But now you have to do something with those files. And let's face it, there are a whole lot of files.

It is highly recommended that the reader look over Tutorial Four on how to use wildcards for matching before preceding with this section.

The good news is, using the above utilties we just learned about we can accomplish almost anything we want to do using a very handy utility called find.

As the name might imply, find, well, finds things. What it finds is up to you. find has many, many options. All laid out in its man page. However, for most purposes only a few are needed. We'll cover those here.

A basic find command looks like

$ find /path/to/directory -name 'filename.txt'

This command looks at all files in /path/to/directory and in all directories therein for a file named 'filename.txt'.

Common Options

-type
Specifies the type of file we're looking for. e.g. text file, directory, link, etc.
-name
Specifies the name of the file. Case Sensitive
-iname
Specifies the name of the file. Case Insensitive
-or
Joins the precedeing and following terms by the boolean OR
-and
Joins the preceding and following terms by the boolean AND
-not
negates the next term. e.g. -not -empty means "is not empty"
-exec
excutes a shell command for each file found. The only 'trick' is to replace the actual file name with {} and end the command with a \;. This should become clear when reviewing the examples below.
-empty
The file or directory is empty.

We can combine the above options to preform complex searches on the file system and, even better, execute commands on those search terms. For a list of all options and their arguments, please see Find Man Page.

Examples

  1. Find all directories named 'tsplot' in the current directory
$ find . -name tsplot -type d 
  1. Find all empty directories in the directory /u/home9/foo/data
$ find /u/home9/foo/data -empty 
  1. Find all empty files or directories named 'tsplot' in the current directory
$ find . -name tsplot -or -type d -empty

Using commands we've already learned to perform actions on the above.

  1. Find all directories named 'tsplot' in the current directory and delete them using rm
$ find . -name tsplot -type d -exec rm -rf {} \;
  1. Find all empty directories in the directory /u/home9/foo/data and delete them
$ find . -type d -empty -exec rmdir {} \; # using rmdir for empty directories is safe as it will refuse to delete a directory with a file in it
  1. Find all empty files or directories named 'tsplot' in the current directory and delete them
$ find . -name tsplot -or -type d -empty -exec rm -rf {} \;

But we're not restricted to rm, of course, we can use any of the utilities we've learned about as the -exec argument.

  1. Find all files named design.fsf and look for a subject named 'foo'
$ find . -name design.fsf -type f -exec grep "foo" {} \;

With a little reading of the man page, we find a new option called -user, which surprisingly finds all files that belong to the specified user

  1. Find all files owned by user 'foo' and change their permissions
$ find . -type f -user foo -exec chmod -R ug+rwX {} \;


Learning to Fish or The Man Pages

However, possibly even more important is being able to find information on one's own. In the spirit of this, the instructional is concluded with a detailed coverage of the built-in unix manual pages. Virtually every program installed on a UNIX like system provied a manual page for reference. Even the most proficient of UNIX users could never retain the dizzying array of programs and their options in their working memory and with the built-in manual pages, they'll never need to.

The man pages (for manual) are the be all end all reference on UNIX systems. When reading a man page becomes natural, you know there is nothing you can't get done quickly and efficiently.

A Beginners Guide to man Pages is an excellent introduction into how to move around a man page easily and understand what it's telling you.


Setting up your Bash Profile

How to set up your Bash Profile to access CCN-supported software.

Hoffman2:Modules

Cyberduck: An SFTP client

Cyberduck installs like most other mac application, just drag and drop. Please see our screen cast on using Cyberduck.


MacFuse installation

  1. Download MacFuse and install it. (double click the MacFuse.mpkg file)
  2. Download the appropriate (tiger or leopard) sshfs from the MacFuse wiki
  3. Un-archive the downloaded sshfs (double click)
  4. Copy the sshfs binary to your /usr/local/bin directory or anywhere else on your path
  5. Make sure the sshfs binary has executable permissions

Example Workflow

This assumes the user has downloaded and installed or unarchived the needed packages listed above. The below example assumes the leopard sshfs binary was downloaded.

$ tar xzvf sshfs-static-leopard.gz
$ sudo mv sshfs-static-leopard /usr/local/bin/sshfs
$ sudo chmod +x /usr/local/bin/sshfs

Example Mounting of a Hoffman2 Directory

Of course, you can name the /Volumes/<directory> anything you want or even put it anywhere you want. For example, I have /Volumes/Hoffman/sbook, /Volumes/Hoffman/my_home, and /Volumes/Hoffman/data

# Mounting the SSH file system
$ mkdir /Volumes/MyHoffmanHome
$ sshfs your_hoffman_username@hoffman2.idre.ucla.edu:/path/to/directory/you/want/to/mount /Volumes/MyHoffmanHome -oauto_cache,reconnect


SPM

SPM8 as well as the older SPM5 are on hoffman. In order to use these, you must add the path ("Add with Subfolders") in MATLAB.

The path to spm12 is:

/u/project/CCN/apps/spm12

The path to spm8 is:

/u/project/CCN/apps/spm8

Likewise, the path to spm5 is:

/u/project/CCN/apps/spm5

FAQ

How do I change the permissions for all files I own in a certain directory?

As a reference, please see the above section on [#File & Shell Management | File & Shell Management]. We can do this using find and chmod.

$ find . -user myusername -type f -not -perm -g+w -exec chmod g+w {} \;

There is also a helper script which will set group permissions on all files in the current directory that are owned by user called fix_perms.sh. To use this, simply

$ fix_perms.sh

How do I transfer data to and from hoffman?

Please see our general FAQ on how to properly transfer data between two machines found here FAQ: How do I properly transfer my data between two machines on the network

How do I switch FSL Versions?

Please see Hoffman2:Modules for more information on switching FSL versions.

External Links