-->
Previous Table of Contents Next


File-Management Commands

These commands are used to manage your files and directories—move them, copy them, delete them, compress them, and more.

basename......Basename Listing

basename filename.suffix

PURPOSE

The basename command (if specified on the command line) strips leading directories and the suffix.

EXAMPLE


$ basename changes.txt



changes

cd Change......Directory

cd directory

PURPOSE

The cd command changes the current directory. Although this is actually a shell command, it’s normally treated as a standard Linux command.

EXAMPLES


$ cd

This changes the current directory to your home directory.


$ cd /usr/kevin

This changes your current directory to the directory named /usr/kevin.


$ cd kevin

This changes your directory to the subdirectory named kevin.


$ cd ~

This changes the current directory to your home directory.


$ cd /

This changes the current directory to the root directory.

RELATED COMMANDS

pwd Prints the name of the current directory.

chgrp......Change Group

chgrp option(s) newgroup file(s)/directory

PURPOSE

The chgrp command changes the group assignments associated with a file or directory. Group IDs or group names can be assigned to a file or a directory (the information is stored in /etc/groups). You must own a file or be the root user in order to change the groups.

OPTIONS

-c Prints information about the changes made.
-f Ignores information about files that can’t be changed.
-v Returns all information about the changes in verbose form.
-R Recursive mode, which means that subdirectories are also changed.

EXAMPLES


$ chgrp management kevin.memo

This changes the group for kevin.memo to the restricted group.


$ chgrp -R management /home/kevin/memos

This changes the group for the directory /home/kevin/memos, its contents, and all subdirectories within to the restricted group.

RELATED COMMANDS

chown
chmod

chmod......Change Mode

chmod option(s) mode file(s)

PURPOSE

The chmod command changes the permissions associated with a file or directory. Permissions are set for the owner of a file, a group owner of the file, and the world at large. Permissions are stored in one of two ways: numeric or symbolic form. The symbolic form is used to set values relative to the current permissions, while the numeric method is used to set absolute permissions. These values are in modes, which can be an octal number (when using the numeric form) or a symbol (when using the symbolic method). You can combine modes if you separate them with a comma.

You must own a file or be the root user in order to change the permissions.

The current permissions for a file can be displayed with the ls command, which is covered elsewhere in this section. The ls command lists the permissions in the following manner:


     rwxr--w--

Permissions are set in trios: owner, group, and world. Any of the three can read (r), write (w), and execute (x). If permission is denied to one of the three, the letter is replaced with a hyphen (-). The root user has full permissions for every file.


NOTE:  Permissions are one of the more important things to watch when using the Linux operating system. Many beginners get tripped up because they want to run or access a file, only to find out that they don’t have permission to do so.

EXAMPLES USING SYMBOLIC FORM


$ chmod g+x pat.memo

This command line adds the permission to execute a file (x) to the group (g). In symbolic form, permissions are added or subtracted to existing permissions.


$ chmod go-w pat.memo

This command line removes the write permissions from the group and the world.


$ chmod g+x,go-w pat.memo

This command line adds the permission to execute a file to the group, while removing the write permissions from the group and the world.

SYMBOLS

The following symbols are used to set the mode:

u User (the current owner of the file).
g Group.
o Other (world).
all All (the default).
+ Adds a permission to the current permissions.
- Deletes a permission from the current permissions.
= Assigns a permission while deleting the other permissions from unspecified fields.
r Read.
w Write.
e Execute.
s Sets user ID
t Sets sticky bit, which is used for additional security both on a Linux system and the Internet.
l Sets mandatory lock.


Previous Table of Contents Next