Hoffman2:Linux Tutorial

From Center for Cognitive Neuroscience
Jump to navigation Jump to search

Back to all things Hoffman2

Lynda.com tutorials

UCLA employees and students have access to video tutorials through Lynda.com.

One course that will be especially helpful to Hoffman2 users is "Learning Linux Command Line". This video series will help you get up to speed with commands like cd, ls, mkdir, cp, mv, find, grep, awk, sed, vi, tar, and so on. The whole series will take you about 2 hours to complete, but you are welcome to pick and choose from the individual tutorials that interest you (each video runs from about 2 to 6 minutes).

To access these video tutorials:

  1. Start here: http://learnit.ucla.edu
  2. Click "Lynda.com"
  3. Log in with your UCLA Logon ID and password
  4. If this is the first time you are using Lynda.com, you may need to type in your name and preferred email address.
  5. Search for "Learning Linux Command Line"

Once you have sharpened your Linux command line skills, search around for other videos that interest you. Hint: I really enjoyed the "iMovie Essential Training" course.

  1. Permissions
  2. File System Navigation
  3. File & Shell Management
  4. Environment variables

Each of these areas requires 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.

Permissions

Permissions determine who and to what degree users can access a file.

The key terminology and function of the permission system is found here:

UNIX Permissions

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 utilities 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.