Summary Page: Basic Linux & Bash

CISC 220, winter 2008

Make sure you're running bash:

echo $SHELL

If you're running bash, the result will be /bin/bash

If you're not running bash automatically:

run caslabUtils.sh

change your shell to /bin/bash – not just to "bash"

Warning: If you change your shell to something other than the path name of a valid

shell, you will not be able to log in to Linux again and will have to contact the

CASLab staff to repair your account.

Navigating through directories:

cd (change directory): moves you to another directory

cd otherDir: moves you to otherDir

cd with no arguments: moves you back to your home directory

pwd (print working directory): shows the name of you current directory

Listing file information:

arguments should be names of files & directories

for each file: lists the file

for each directory: lists the contents of the directory (unless –d flag)

ls with no arguments: equivalent to ls .

flags for ls:

-a: include files & directories starting with "."

-d: for directories, show directory itself instead of contents

-l: (lower-case L) long format: lots of information about each entry

-R: list sub-directories recursively

-1: (one) list each file on separate line (no columns)

Information about commands (Linux "manual"):

man ls: information about the ls command

File/directory protections:

chmod <who>=<what> <list of files and folders>

where

<who> is u for owner, g for group, o for other users

<what> is r for read, w for write, x for execute

can use + or – instead of =, to add or subtract permissions

umask <who>=<what>: sets the default protections for new files you create

umask –S: displays your current set of default protections

Copying files:

cp oldFile newFile

oldFile must be an existing file. Makes a copy and calls it newFile.

cp file1 file2 file3... fileN dir

file1 – fileN must be existing files and dir must be a directory. Makes

copies of the files and puts them in directory dir (with their original names).

Moving/renaming files:

The mv command is just like cp, except that the original file or files disappear. So you

can use it to rename a single file or to move one or more files into a different directory.

Deleting files:

rm <list of files>

Deletes ("removes") all of the files in the list. The deletion is permanent; there is no recycle bin or un-delete command.

rm -i <list of files>

Same as above, but in interactive mode. It prompts the user about each file, so

that you can type "y" to delete it or "n" to leave it alone. The standard

initialization files create an alias so you always get the "-i" flag.

rm –f <list of files>

no prompt and no error message if you ask to delete a file that doesn't exist

Create & remove directories:

mkdir dir

If dir is a simple name, it is created in the current directory. If dir is not a

simple name, its parent directory must already exist. For example:

mkdir one/two/three will create a new directory called three inside

the existing directory one/two.

rmdir dir

Removes directory dir, providing the dir is empty.

rm –r dir

Removes directory dir and all of the files and sub-directories inside it.

Log out of the Linux system:

logout

See a list of your current jobs:

jobs

Change to a background job:

%n, where n is number of job as shown by jobs

%pre, where pre is a prefix of the job name

To terminate a job:

kill %n

kill %pre

To stop a foreground job:

control-c (hold down the control key and type c)