Some Basic Unix Commands

Getting around your directory structure.
Command Function
pwd Print Working Directory - shows what current directory you are in.
ls Lists the contents of your current directory
ls /subdirectory Lists the contents of the subdirectory you specify.

Example:

web2:/u1/home/sclaus$ ls

dead.letter
ftp/
index.html
ispy.jpg
logs/
mail/
news.html
public_html

ls -la Lists all files in the current directory, showing detailed information such as file sizes, ownership, last modified date, and permissions.

Example:

web2:/u1/home/sclaus$ ls -la
drwx---r-x
drwxr-xr-x
-rw-r--r--
-rw-r--r--
-rw-r--r--
-rw-r--r--
-rw-r--r--
-rw-r--r--
-rw-r--r--
-rw-r--r--
-rw-r--r--
drwxr-xr-x
-rw-------
drwxr-xr-x
-rw-rw-r--
drwxr-xr-x
drwx------
-rw-rw-r--
drwxr-xr-x
8 sclaus
99 root
1 sclaus
1 sclaus
1 sclaus
1 sclaus
1 sclaus
1 sclaus
1 sclaus
1 sclaus
1 sclaus
2 sclaus
1 sclaus
8 sclaus
1 sclaus
2 root
2 sclaus
1 sclaus
25 sclaus
users
root
users
users
users
users
users
users
users
users
users
users
users
users
users
root
users
users
users
1024 Oct8 19:54 ./
2048 Oct8 15:29 ../
906 May 24 08:08 .addressbook
3653 May 24 08:08 .addressbook.lu
4946 Oct9 05:49 .bash_history
163 Apr 121999 .kermrc
34 Apr 121999 .less
114 Apr 121999 .lessrc
10210 Oct8 19:53 .pinerc
37 Apr 121999 .profile
46 May 24 08:08 .signature
1024 Apr 121999 .term/
415 Sep 26 17:34 dead.letter
1024 Apr 121999 ftp/
5902 May7 19:15 index.html
1024 Oct1 00:10 logs/
1024 Oct8 19:54 mail/
7450 May 13 16:17 news.html
2048 Oct 11 00:00 public_html/

Understanding the listing

The first character above shows the file type (d indicates it is a directory, - is a file) and the rest of the column shows the permissions.

The second column shows who owns the file. In this case, our user, sclaus, is the owner of most files.

The third and fourth show the file's last modification date, size, and file name.

Understanding Permissions
Going back to the first column of the listing as shown above, we get detailed information on the file's particular permissions. The 9 characters following the d or - represent the following:

  • The first three characters, represent permissions for that file for the owner.

  • The second three characters, represent permissions for that file for the group.

  • The third three is for the world.

What The Codes Mean

  • r - read
  • w - write
  • x - execute

In the following example, we can find out what permission is of the file,

-rw-rw-r--

  • The character indicates that the permission in that place is off. The very first character states whether or not the file is a directory. Since our above example is a file, and not a directory, it is turned off, represented by -.

  • The first group of 3 characters is for the owner permissions. rw- indicates the owner can read and write that file. But since there is a - in the execute position, this indicates that the excute permission is off, therefore the owner cannot execute it.

  • The second group of three represents permissions for your group. Like the owner permissions, the group can read and write to this file.

  • The last group shows the rest of the world's permissions, and in this case, it is read only since the write and execute permissions are off ().

Changing Permissions (chmod)
You may change the permissions by using the chmod command.

Syntax: chmod who[opcode]permission filename

Who
When using the command, you must tell the system who you want to change permissions for.

  • u = user
  • g = group
  • o = other
  • a = all (default

Op Codes
This tells either to add or remove permissions.

  • + = add permission
  • - = Remove permission

Permission

  • r - read
  • w - write
  • x - execute

Example:
Let's take a look at the line for news.html.

-rw-rw-r--   1sclaus  users  7450 May 13 16:17 news.html

Using the above, let's say that you wish to change the permissions so that the world (the third set of characters which has the values r--) to be able to do more than just read the file; let's change the permissions on this file so that the world can also write to it.

The proper syntax would be:

chmod o+w news.html

Breakdown: chmod is the command, o is who it applies to, + is to add permission, and w is write.

Using Numerical Commands
Unix has many different ways of doing things, and there is an alternative method to chmod files using numbers instead. Here's how it works. Each trio of values has a numerical value assigned to it.

  • r = 4
  • w = 2
  • w = 1

Let's look at our example file again:

-rw-rw-r--  1sclaus  users 7450 May 13 16:17 news.html

The first character is a -, but that particular place states whether or not the file is a directory, as we talked about above. Move to the next character.

The next character's place is worth 4, and there is a 4 there. The place after that has a value of 2, and we do have a 2. The third place has the value of 1, and it is off, indicated by the , which is a value of 0.

Add the three values, 4 + 2 and you have a value of 6. Make note of the 6.

The next trio of values are also rw-. The r has a value of 4, the w a value of 2 and x is off, so that has a value of 0. Make note of this second value as 6.

The third, r--, has the first value of 4, and 0 values for w and x, so this third value is 4.

So, the numerical equivalent of the command chmod o+w news.html is chmod 664 news.html.

-rwxr-xr-x breaks down as follows:
- r     w    x
4 + 2 + 1 = 7
r     -     x
4 + 0 + 1 = 5
r     -     x
4 + 0 + 1 = 5

Therefore, -rwxr-xr-x is equivalent to 755.

To create this condition, type chmod 755 filename.

More Commands to Help You Get Around

cd subdirectoryname Change directory - moves you to the subdirectory you specify.
cd .. Change directory - the .. takes you up one directory level.

Other Commands
du Print disk usage. If you type du from your public_html directory, it will give you the size of each file and sub-directory, then gives you the total for everything at the bottom. That is the storage that is checked for additional charges.
df Shows the amount of free disk space available on all mounted file systems.
mkdir Makes a directory (a subdirectory within your current working directory.
ftp Transfers files to and from a remote network site. Detailed Information
cp Copy command. You might want to copy a file and give it a new name.
Example: cp file1 newfilename
This takes file1 and makes a copy of it called newfilename.
rm Remove. Removes (deletes) the file you specify.
rmdir Remove directory. Removes (deletes) the directory you specify. Note: You cannot delete a directory that still has files or subdirectories in it.
mv Moves or renames files and directories.
Example: mv oldname newname
or: mv oldname subdirectory/newname

Note: Unlike the copy command, the mv command will delete the old file (the one you are moving).


Defining Files with Wildcard Characters
Wildcard characters can be used to represent many other characters. Use them whenever you need to define a string of characters, such as a file name with the use of a command.

  • * matches any string of characters
  • ? matches any single character
  • b* gets all files that start with b.
  • b?s*jpg gets all jpg files that start with b and have a third character of s.
  • *.htm* would get all html files, whether they were .htm or .html.

Text Editors
There are several editors available for you to use with your shell account: joe, pico, vi and emacs. If you are unfamiliar with using text editors, it is advisable to start with pico. It is the most user-friendly editor, with the commands shown at the bottom of the screen to help you along.

Tin - Shell-based News Reader
Tin allows you to view, subscribe to, and read your newsgroups via your shell account. Launch tin by typing tin at your command prompt. Once the program has launched, type h for an extensive help section which will get you started using tin.

Return to support index.

Return to shell4 home.