Next / Previous / Contents / TCC Help System / NM Tech homepage

4. Organizing your files

4.1. Commands for the current working directory

ls -F [file…]

List your files (in columns)

ls -l [file…]

List your files (in detail).

ls -al

Also list all the hidden files (those whose names start with a period).

cp oldname newcopy

Copy a file.

mv oldname newname

Rename or move a file.

4.2. Working with directories

At any given time, you will be located in some current working directory. When you first log in, this will be your account's home directory. You can create subdirectories under that, so you can keep files for different projects separate. You can create subdirectories within subdirectories, and so on to any depth.

You will also need to know how to use directories so that you can use files located under other users' accounts.

A pathname is a description of a file's location somewhere in the Unix directory structure.

  • Most file and path names are assumed to be in the current working directory. Slashes (“/”) are used to denote subdirectories, so for example this pathname

    bill/cat

    refers to file cat in directory bill under the current working directory.

  • Pathnames that start with a tilde character “~” are relative to your home directory. For example,

    ~/foo

    refers to file foo in your home directory.

  • Pathnames that start with “~”a tilde followed by another user's name are relative to that user's home directory (assuming that you have permission to see into that directory). For example,

    ~moriarty/bar/klarn

    refers to file klarn in directory bar under user moriarty's home directory.

  • You can refer to the parent directory by using two dots (“..”), so pathname

    ../ack

    refers to file ack in the directory above the current working directory. Similarly, the pathname

    ../../letters/susie

    refers to file susie in subdirectory letters under the directory two levels above the current working directory.

  • Pathnames starting with a slash (“/”/) are called absolute pathnames. Your home directory will typically be located at absolute path /u/yourname, where yourname is your account (login) name. (The path reported by the pwd command may be different, but that's an artifact of our local software.)

Commands for working with directories:

cd pathname

Change the current working directory.

pwd

Show the pathname of the current working directory.

mv file

Move the given files to a different directory.

mkdir path

Create a new directory.

rmdir path

Remove an empty directory.

ln -s oldfile newname

Make newname a symbolic link to oldfile.

4.3. Controlling access to your account

The first line of defense against others tampering with your files is proper user authentication. Don't tell anyone your password, and don't write it down. To change your password, use this command:

passwd

Also, always log out when you are finished. From an X window session, move the mouse to the background, press and hold the right button, and select Logout.

4.4. Controlling access to your files

You can control whether others can see or change your files. This is done by setting permissions on a file-by-file basis. There are three kinds of permissions:

  • If someone has read permission for a file, that means they can see its contents.

  • Write permission is the power to change or delete a file.

  • Execute permission applies to programs and commands—the ability to execute a file as a program or command. (Execute permission for a directory grants the right to see what files are there.)

To find out the permissions for a file, use this command:

ls -l [file]…

In the output from this command, the first ten characters show you the file type and permissions.

  • The first character is “-” for an ordinary file, “d” for a directory, or “l” for a symbolic link.

  • The next three characters specify the read (“r”), write (“w”), and execute (“x”) permissions for the file's owner. A hyphen (“-”) means no permission.

  • The next three characters specify the read, write, and execute permissions for group members. Groups are a mechanism for allowing file access to a specific list of people; if you need to set up this kind of access, e-mail a request to tcc-eng@nmt.edu.

  • The next three characters specify the read, write, and execute permissions for the “world” (all other users).

The command to change permissions is:

chmod who=value file

where:

who

is u to set the owner's permissions, g to set group permissions, o to set world (“other”) permissions, and a to set all three at once.

value

can be up to three of the letters r for read permissions, w for write permissions, and x for execute permissions.

file

is a list of files whose permissions are to be changed.

To remove permissions, use:

chmod who-value file

And to add permissions:

chmod who+value file