Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Linux+ Certification Bible.pdf
Скачиваний:
46
Добавлен:
15.03.2015
Размер:
3.78 Mб
Скачать

Chapter 9 General Linux Administration 299

Use the groupdel command to remove a group of users. This command is used with the group name in order to remove a group from the Linux system. This command can only be used if the group exists, and you must manually check all files to verify that no files are assigned with the deleted group name as the file group ID. Finally, the primary group may not be removed until all users are removed from the group. This command writes to the following files:

/etc/group: Contains group account information

/etc/gshadow: Contains secure group account information

Getting Around Linux

You must be able to navigate and manage the Linux hierarchy, set file and directory permissions, and mount and un-mount file systems and devices. The following sections detail the Linux directory hierarchy and where important files can be found, and also the common commands used to traverse these directories.

Navigating Linux

4.5 Manage and navigate the Linux hierarchy (e.g., /etc, /usr, /bin, /var)

The Linux system uses a hierarchical file system structure, meaning that the system has a primary directory (/ or root) and sub-directories that are used to manage the files. When a user logs in, the system places the user in a default directory, which is usually the user’s home directory. Each directory can be referred to by using an exact path name. Because the Linux system is a hierarchy, any user (including root) can verify the directory that they are currently using.

To see what your current directory is, use the command pwd or print working directory. This command displays the current working directory. Therefore, when a user logs in, the most common reply to the pwd command is /home/<username>, where <username> is the logged-in user. After the current directory is known, the user can move to the desired directory. To move from directory to directory, use the cd (change directory) command.

The cd command is mainly used to move from directory to directory by using the syntax, cd </directory>. Use the cd command to change the current working directory to one directory level up. For example, use the cd command in the /home/ user directory to change the current working directory to /home. To move back to the user directory, use the cd /user command or just cd user. Note that the command without the forward slash “/” will only work for directories located under the

current one. Another navigation method is to use the cd command with the full directory path of the desired directory, for example, cd /home/user/files/documents.

300 Part IV Administration

See Chapter 4 for more information on common Linux directories and their normal contents.

Common file and directory commands

4.6 Manage and navigate the standard Linux file system (e.g., mv, mkdir, ls, rm)

After choosing the working directory, the user must know how to use common file and directory commands. These commands can be used to list, copy, move, delete, and create files and directories on the Linux system.

The ls command

To list files on a Linux system, use the ls command. The ls command employs the options shown in Table 9-6.

 

Table 9-6

 

Options for ls

 

 

Option

Description

 

 

-a

List all entries including all those normally not displayed.

 

 

-A

List all entries including all those normally not displayed except

 

the working and parent directories.

 

 

-b

Forces the printing of non-printable characters in the octal \ddd

 

notation.

 

 

-B

Ignore backup or do not list files ending with the ~.

 

 

-c

Uses the time of last modification of the i-node for sorting or

 

printing.

 

 

-C

Multi-column output that is the default output method. This

 

method sorts down the columns.

 

 

--color[=WHEN]

Used to supply color to file types, where [=WHEN] is auto,

 

always, or never.

 

 

-d

List only the name of a directory not the contents — useful with

 

the -l option to return directory status.

 

 

-D

Used to generate output designed for Emacs’ dired mode.

 

 

-f

Force each argument to be interpreted as a directory and list the

 

name found in each slot. This option turns off -l, -t, -s, and -r

 

options and turns on -a option.

Chapter 9 General Linux Administration 301

Option

Description

 

 

-F

Used to identify the contents of a directory, returning (/) for

 

directories, (>) for doors, (*) for executable files, (|) for FIFO’s,

 

(@) for symbolic links and (=) for AF_UNIX address family

 

sockets.

-g

List in long format, giving mode, ACL indication, number of links,

 

group, size in bytes, and time of last modification for each file,

 

often ignored in newer version.

 

 

-G

Don’t display group information.

 

 

-h

Print sizes in human readable format.

 

 

-H

Supplies the block sizes for each entry but uses powers of 1000

 

not 1024

 

 

-i

Prints the i-node number for each file.

 

 

-l

Use a long listing format.

 

 

-L

List the file or directory the link references rather than the

 

symbolic links.

 

 

-m

List the files across the page separated by commas.

 

 

-n

List in long format, giving mode, ACL indication, number of links,

 

owner’s UID, group’s GID, size in bytes, and time of last

 

modification for each file.

 

 

-N

Used to print raw entry names.

 

 

-o

List in long format, giving mode, ACL indication, number of links,

 

owner, size in bytes, and time of last modification for each file.

 

 

-p

Places a (/) after each listing of a directory, some

 

implementations include the -F features.

 

 

-q

Force printing of non-printable characters in file names as a

 

question mark (?).

 

 

-Q

Used to enclose entry names in double quotes.

 

 

--quoting-style=WORD

Use quoting style WORD for entry names: literal, locale, shell,

 

shell-always, c, escape.

 

 

-r

Reverses the order of sort to supply reverse alphabetic or date list.

 

 

-R

Recursively list subdirectories encountered.

 

 

-s

Supplies the block sizes for each entry.

 

 

-S

Sort by file size.

 

 

-t

Sorts by time stamp instead of name.

 

 

-T --tabsize=COLS

Assume tab stops at each COLS instead of 8.

Continued

302 Part IV Administration

 

Table 9-6 (continued)

 

 

Option

Description

 

 

-u

Used with the -t option to sort by last time accessed instead of

 

the default last modified.

 

 

-U

Don’t sort, just display entries in directory order.

 

 

-v

Sorts by version.

 

 

-w --width=COLS

Assume screen width supplied instead of current value.

 

 

-x

Multi-column output with entries sorted across the page.

 

 

-X

Sort alphabetically by entry extension.

 

 

-1

Print one entry per line of output.

 

 

--help

Provide help with the program.

 

 

--version

Provides version information about the program.

 

 

Use the ls command to view the files and directories of a Linux system. For example:

$ ls /boot

 

 

System.map@

chain.b

map

System.map-2.4.3-20mdk config@

message

boot-graphic.b

config-2.4.3-20mdk message-graphic

boot-menu.b

grub/

os2_d.b

boot-text.b

initrd-2.4.3-20mdk.img us.klt

boot.0300

initrd.img@

vmlinuz@

boot.b@

kernel.h

vmlinuz-2.4.3-20mdk

The cp command

Use the cp command to copy files and directories in the following format: cp [options] <source> <destination>. Use this command to copy a file or directory from the source to the destination. The cp command employs the options shown in Table 9-7.

 

Table 9-7

 

Options of cp

 

 

Option

Description

 

 

-a

Preserve links and file attributes if possible and copy directories

 

recursively.

 

 

-b

Make a backup of each existing destination file.

 

 

-d

Preserve links.

 

 

Chapter 9 General Linux Administration 303

Option

Description

 

 

-f

Automatically remove existing destinations.

 

 

-i

Prompt before overwriting the destination.

 

 

-l

Link files instead of copying.

 

 

-p

Preserve file attributes if possible.

 

 

-P

Append source path to DIRECTORY.

 

 

-r

Copy recursively and treat non-directories as files.

 

 

-R

Directories are copied recursively.

 

 

-s

Create symbolic links instead of copying.

 

 

-S --suffix=SUFFIX

Override the default backup suffix.

 

 

-u

Copy only files when the source file is newer than the destination, or

 

the destination does not exist.

 

 

-v

Verbose mode that explains what is being done.

 

 

-x

Stay on this file system.

 

 

--help

Provides help with the program.

 

 

--version

Provides version information about the program.

 

 

The cp command can be used like this:

[user@dhcppc1 user]$ cp /home/user/myfile /tmp/ [user@dhcppc1 user]$ ls /tmp

kde-root/ ksocket-root/ mcop-user2/ mcop-user/ kde-user/ ksocket-user/ mcop-root/ myfile

Anyone who uses a file system needs the ability to copy files from one location to another. Linux provides the cp command to perform this task.

The mv command

You can move files on the Linux system by using the mv command. This command takes on the following format: mv [options] <source> <destination>. The mv command is a very capable tool for moving files in the Linux environment. The available options for the mv command are shown in Table 9-8.

304 Part IV Administration

 

Table 9-8

 

Options of mv

 

 

Option

Description

 

 

-b

Make a backup of each existing file before removal.

 

 

-f

Automatically remove existing destinations.

 

 

-i

Prompt before overwriting the destination.

 

 

-S --suffix=SUFFIX

Override the default backup suffix.

 

 

-u

Move only older or brand new non-directories.

 

 

-v

Verbose mode that explains what is being done.

 

 

-V --version-control=WORD

Override the normal version control.

 

 

--help

Provide help with the program.

 

 

--version

Provide version information about the program.

 

 

The mv command can be used as follows:

[user@dhcppc1 user]$ mv /tmp/myfile /home/user/ [user@dhcppc1 user]$ ls /home/user

Desktop/ myfile nsmail/ tmp/

The rm command

Use the rm command to delete files on a Linux system. This command uses the following format: rm [option] <file>. Use this command with the options shown in Table 9-9.

 

 

Table 9-9

 

 

Options of rm

 

 

Option

Description

 

 

 

-d

 

Unlink directory, even if non-empty.

 

 

 

-f

 

Ignore nonexistent files.

 

 

 

-i

 

Prompt before any removal.

 

 

 

-r

-R --recursive

Remove the contents of directories recursively.

 

 

 

-v

 

Verbose mode that explains what is being done.

 

 

--help

Provide help with the program.

 

 

--version

Provide version information about the program.

 

 

 

Chapter 9 General Linux Administration 305

The rm command is used as follows:

[user@dhcppc1 user]$ rm /home/user/myfile rm: remove `myfile’? y

[user@dhcppc1 user]$ ls /home/user Desktop/ nsmail/ tmp/

The touch command

To create a file that does not exist on a Linux system, use the touch command. This command uses the following format: touch [options] <file>. This command employs the options shown in Table 9-10.

 

Table 9-10

 

Options of touch

 

 

Option

Description

 

 

-a

Change only the access time.

 

 

-c

Do not create any files.

 

 

-d --date=STRING

Parse STRING and use that instead of the current time when

 

marking the file.

 

 

-f

A BSD option ignored in Linux but allowed.

 

 

-m

Change only the modification time.

 

 

-r

Use the files time instead of the current time.

 

 

-t [[CC]YY]MMDDhhmm[ss]

*STAMP [[CC]YY]MMDDhhmm[ss] used instead of current

 

time.

 

 

--help

Provide help with the program.

 

 

--version

Provide version information about the program.

 

 

If the touch command is used on a file that does not exist, and the -c option is not specified, the file will be created. You can also use this command to modify dates on files to reflect a different time than the data and time that is already assigned. Use this command to ensure that a file is backed up on a specific archive, or to show that the file is used before you purge old files. Finally, use the touch command to create a file where one did not previously exist, as shown by the following:

[user@dhcppc1 user]$ ls /home/user Desktop/ nsmail/ tmp/

[user@dhcppc1 user]$ touch /home/user/myfile2 [user@dhcppc1 user]$ ls /home/user

Desktop/ myfile2 nsmail/ tmp/

306 Part IV Administration

The mkdir Command

You can create a directory on a Linux system by using the mkdir command. This command is commonly used in the following format: mkdir [options] <directory name>. This command employs the options shown in Table 9-11.

 

Table 9-11

 

Options of mkdir

 

 

Option

Description

 

 

-m, --mode=MODE

Set permission mode (as in chmod), not rwxrwxrwx - umask.

 

 

-p, --parents

Make parent directories as needed.

 

 

--verbose

Print a message for each created directory.

 

 

--help

Provide help with the program.

 

 

--version

Provides version information about the program.

 

 

The mkdir command looks like this:

[user@dhcppc1 user]$ ls /home/user Desktop/ myfile2 nsmail/ tmp/

[user@dhcppc1 user]$ mkdir --verbose /home/user/mydir mkdir: created directory `mydir’

[user@dhcppc1 user]$ ls /home/user Desktop/ mydir/ myfile2 nsmail/ tmp/

The rmdir Command

Use the rmdir command to remove a directory on a Linux system. This command is commonly used in the following format: rmdir [options] <directory name>.

Notice that most commands use the same format — [command] [options] [argument]. This convention is helpful for remembering the proper syntax for any command.

This command uses the options shown in Table 9-12.

Соседние файлы в предмете Операционные системы