AIX笔记2

Unit 5.  Using Files

Copying files
The cp command copies from one or more source files to a target file. The source is usually an ordinary file, but can also be a directory file if the -R (recursive) option is used.

Copying multiple files
The cp command can copy multiple files to a target. In that case, the target must be a directory.

Target exists
When using the cp command, if the file specified as the target file already exists, then the copy operation will overwrite the original contents of the file without warning. To avoid this use the -i (interactive copy) option.

Target is a directory
If the target is a directory, the source file(s) will be created within the directory, and retain the same file name(s).

Recursive copy
cp -R can be used to recursively copy all files, subdirectories, and the files in those subdirectories to a new directory.
For example:
cp -R /home/team01/mydir /home/team01/newdir

The mv command
The mv command moves files and directories from one directory to another or renames a file or directory. If you move a file or directory to a new directory, it retains the base file name. When you move a file, all links to other files remain intact, except when you move it to a different file system. When you move a directory into an existing directory, the directory and its contents are added under the existing directory.
When you use the mv command to rename a file or directory, the target can specify either a new file name or a new directory path name.

Moving files
As a result of the mv command, you will still have the same number of files as you did before. Furthermore, all the attributes remain the same. The only things that change are the file name and location.

Command arguments
The source can be a file or a list of files. If the source is a list of files, then the target must be a directory.
The target can be a file or a directory. Warning! If the target is the name of a file that already exists and if you have the correct permissions set for that file and directory, you will overwrite the file and never get an error message. To avoid this, use mv -i, an interactive move which prompts you if there are duplicate names.

The cat command
The cat command displays the contents of all the files that are specified as arguments to the command.
Too much output?
The cat command does not paginate the output. If it is longer than a screen, the file will scroll until the bottom of the file is reached. Thus, you may only be able to read the last full screen of information.
Line numbers
To display all the lines of a file, with numbers displayed beside each, use the -n flag.

Displaying files
The pg command reads the file names specified and displays the files one page at a time. Each screen is followed by a prompt. Press <Enter> to display the next page down and h to get help information.
The more command works in much the same way as the pg command; it displays continuous text one screen at a time. It pauses after each screen and prints the word More at the bottom of the screen. If you press Enter, it displays an additional line. If you press the <space bar>, it displays the next screen of text.

Search function
Both pg and more support searching through the file for patterns. more also supports search pattern highlighting.

The wc command counts the number of lines, words, and bytes in a named file:
$ wc [-c] [-l] [-w] filename
Options:
-c counts the number of bytes
-l counts lines
-w counts words

Counting file contents
When files are specified with the wc command, their names will be printed along with the counts. If options are not used, the order of the output will always be lines, words, and characters.

Activity with Hints
__ 1. Log in to the system with your teamxx ID and password.
login: teamxx (at the login prompt)
Password: teamxx (default password same as user name)
__ 2. Execute the wc command and count lines in file .profile.
$ wc -l .profile
__ 3. Execute the wc command and count the bytes in file .profile.
$ wc -c .profile
__ 4. Execute the ls -la command on the file .profile. Compare this number with the
output of in the previous step.
$ ls -la .profile

The ln command
ln source_file target_file
? Allows files to have more than one name in the directory structure
? Both files reference the same i-node
? Cannot be used with directories, cannot span file systems
The ln command in its simplest of forms allows one file to have two or more different names in the directory structure. These multiple references are also known as hard links. No copy of the file takes place; each reference in the directory points to the same i-node.
All other characteristics of the original file are reflected in the new file reference. That is, permissions, ownership, size, and modification time all remain the same. Any changes to either file will be reflected in the other.
When using the ln command, the source is the existing file, and the target is the new file reference (or link) to be created.
These types of file references can only be created within the same AIX file system (or partition).

ln –s source_file target_file
? Creates an indirect reference to a file (symbolic link)
? Name references the original file’s name and path
? Can be used with directories and span file systems
The ln command also allows for the creation of indirect references to files. These are called symbolic links, and are created using the -s option.
When a symbolic link is created, the directory entry references the name of the source file, rather than the i-node. They can be used with directories as well as files, and can span physical file systems.
In the ls -l output above, the symbolic link is visible in the file permission bits; the first character is an l (lowercase l). Also, in the link file name, you can see the reference to the source file.

Methods of removing entries
The rm command removes the entries for the specified file or files from a directory. By default, there is no confirmation before the entry is deleted. To include a confirmation, use the -i (interactive) option.
The -r option permits recursive removal of directories and their contents if a directory is specified. Use this option with care, as it does not require the directory to be empty in order for this option to work.

Printing Files
qprt - queue files to the printer
qchk – display the current status of a print queue
qcan – cancel a print job (specify job number)

Print subsystems
AIX supports two printing subsystems: the System V Printing Subsystem and the AIX Printing Subsystem.

Printing files
The printer queue mechanism of either subsystem allows multiple users to use the same printer without a user having to wait for the printer to be available.
To queue a file for printing there are a number of commands available (to remain compatible with other versions of UNIX). They are qprt, lp, lpr. The command qprt has the most facilities.
To specify a printer (other than the default) use the -P option to the qprt command. For example, to send a file to queue lp1 use:
$ qprt  -P  lp1  filename
To obtain the job number of your print request use the -#j option with the qprt command at the time of submission.

Displaying queue information
The qchk command by default will only list information about the default queue. To obtain a listing for all the queues defined on your system use the -A option or use the lpstat command.
The qcan command can be used to cancel one file in a queue when used with the -x option. It can also be used to cancel all your jobs in a particular queue when used with the -X option; that is:
$ qcan -X -P lp0

---------------------------------------------------------------------------------------------

Unit 6.  File Permissions

$ ls -l
drwxrwxr-x 2  team01 staff  1024   Aug 12 10:16 c
drwxrwxr-x 2  team01 staff   512   Feb 18 09:55 doc
-rwxrwxr-x 1  team01 staff   320   Feb 22 07:30 suba
$ ls -l
drwxrwxr-x 2  team01 staff  1024   Aug 12 10:16 c
drwxrwxr-x 2  team01 staff   512   Feb 18 09:55 doc
-rwxrwxr-x 1  team01 staff   320   Feb 22 07:30 suba
-rwxrwxr-x 2  team01 staff   144   Feb 22 16:30 test1

ls command output
(1)       (2) (3)    (4)  (5) (6) (7)
drwxrwxr-x 2 team01 staff 1024 Aug 12 10:16 c
drwxrwxr-x 2 team01 staff 512 Feb 18 09:55 doc
-rwxrwxr-x 1 team01 staff 320 Feb 22 07:30 suba
-rwxrwxr-x 2 team01 staff 144 Feb 22 16:30 test1
The fields from the ls -l command are as follows:
  - Field 1 shows the file/directory and permission bits
  - Field 2 is the link count
  - Field 3 shows the user name of the person who owns entry
  - Field 4 shows the name of the group for which group protection privileges are in effect
  - Field 5 shows the character count of the entry
  - Field 6 shows the date and time the file was last modified
  - Field 7 shows the name of the file/directory
The -d option used with the -l option of the ls command is another very useful option. The -d option will display only the information about the directory specified. Directories are treated like ordinary files.

For an ordinary file:
r => Can look at the contents of a file
w => Can change or delete the contents of a file
x => Can execute the file (r is also needed if a script)
For a directory:
r => Can list the files within a directory (ls)
w => Can modify/remove files in the directory
x => Can change into the directory and access the files within (cd)

File permissions
The visual describes the three permission categories, and the associated permission bits that can be set for each.
For files, the permission bits are straightforward. For shell scripts, the r bit is required with the x to make the file executable. Compiled (binary) programs only require the x.
For directories, the x bit is required to access any of the files or subdirectories within it. This implies that the x bit is required on all directories above it as well.
The w bit on a directory overrides any permissions on the files within that directory. Thus, if a user has write access to a directory, they can remove ANY files or directories within it, regardless of the individual file’s permissions.

Changing Permissions
chmod mode  filename
+ : add permissions
- : remove permissions
= : clears permissions and sets to mode specified
u = owner of the file
g = owner's group
o = other users on the system
a = all

Symbolic notation
With symbolic notation, you are specifying changes relative to the existing permissions on a file or directory by adding or deleting permissions. You can check what the permissions are currently set to by using the ls -l command.
You can specify multiple symbolic modes separated with commas. Do not separate items in this list with spaces. Operations are performed in the order they appear from left to right.
When you use the Symbolic mode to specify permission modes, the first set of parameters selects the permission field, as follows:
u File owner
g Group
o All others
a  User, group, and all others. This has the same effect as specifying the ugo options. The a option is the default permission field. If the permission field is omitted, the default is the a option.
The second set of flags selects whether permissions are to be taken away, added, or set exactly as specified:
- Removes specified permissions
+ Adds specified permissions
=  Clears the selected permission field and sets it to the mode specified. If you do not specify a permission mode following =, the chmod command removes all permissions from the selected field.
The third set of parameters of the chmod command selects the permissions as follows:
r Read permission
w Write permission
x Execute permission for files; search permission for directories.

Warning messages
Sometimes the file permission will generate a safety prompt, rather than totally preventing you from completing the operation. For example, if you are the owner of a file, you have no permissions on that file (for example 000), and you try to remove it, the system will ask you if you want to override the protection setting on the file that you wish to remove. You may respond yes at this point, and the system will remove your file. The same will happen if you are a member of the group.

System defaults
The real default permissions for a file and directory are 666 and 777 respectively. The umask value is then subtracted from these values. The default umask is 022, which leaves you with values of 644 for a file and 755 for a directory.

Understanding permissions
umask is a command which sets the umask value by accepting an octal permission string as an argument. If an argument is not provided then umask will display the existing umask value.
The chmod command works by applying a permissions mask onto a file. umask, on the other hand, works by taking away these permissions.
The default setting of the umask is 022. For tighter security, you should make the umask 027 or even 077.
A umask of 022 specifies that the permissions on a new file will be 644 or on a new directory will be 755. A umask of 000 would give 666 permissions on a file (read/write access to all) or 777 on a directory (read/write/execute access to all).
Execute permissions are never set when ordinary files are created.

Function/Permissions Required
Command Source Directory Source File Target Directory
cd x N/A N/A
ls r N/A N/A
ls -l r, x N/A N/A
mkdir x
w (parent)
N/A N/A
rmdir x
w (parent)
N/A N/A
cat, pg, more x r N/A
mv x, w NONE x, w
cp x r x, w
touch x, w * NONE N/A
rm x, w NONE N/A

File permissions
This table can be used as a reference to ensure that the correct permissions are set on files and directories to accomplish the desired activity.
* w permission is also needed in the source directory when using the touch command to create a zero-length file. w permission is not necessary if using the touch command on an existing file for the purpose of updating the modification date.

---------------------------------------------------------------------------------------------

Unit 7.  The vi Editor

The vi editor
It is important to know vi for the following reasons:
  - It is the only editor available in maintenance mode on IBM System p
  - Standard editor across all UNIX systems
  - Command line editing feature
  - Used as default editor for some programs
 
Modes of operation
The vi editor has two modes of operation. Command mode allows the user to perform operations on the text, such as cut, paste, cursor movement, and replacement. These operations are all invoked by one character “commands.” Text mode (also known as insert mode) allows the user to enter text; all characters typed are inserted into the file.
There is no way to tell which mode the editor is in, other than pressing a key on the keyboard. If the key you press is inserted into the file, the current mode is text mode. If the key performs an action, the current mode is command mode.
Switching from command mode to text mode is done with one of the insert text commands, which will be covered later. Returning to command mode is done by pressing the <Esc> key.

Advanced features
The vi editor has many advanced features, such as flexible search and replace (using standard regular expressions), undo, and user-defined editing functions (called macros).
It is important to remember that the vi editor edits ASCII text files directly; it does not format the text in any way, as a word processor would do.

Introduction to vi functions
This unit covers only a subset of the vi functions. It is a very powerful editor. Refer to the online documentation for additional functions. Refer to the Command Summary in the appendices for a reference guide on using vi.

Editor startup
When the editor starts up, it needs to use work space for the new or existing file you are going to edit. It does this by using an editing buffer. When a session is initiated, one of two things happens:
  - If the file to be edited exists, a copy of the file is put into a buffer in /var/tmp by default.
  - If the file does not exist, an empty buffer is opened for this session.
The tilde characters represent empty lines in the editor.
The editor starts in command mode.

Adding text to a file
a append text after the cursor
A append text to the end of the line
i insert text at the cursor
I insert text at the start of the line
o open a new line under the current line
O open a new line above the current line
To type text into a file, the following commands can be used:
Each of these commands places the session into text mode. Any characters entered will be placed into the file.
To exit from text mode, press the <Esc> key.

Exiting the editor
To get into command mode, or to ensure that you are in command mode, press <Esc> before carrying out any commands.
These commands will exit the editor. Each will exit differently.
:q  quits without saving. This option will only work if you have not made any changes. If you have made changes, then to force an exit out of the editor, use ! with the q command.
:w  writes changes
:x  saves and exits
:wq  writes changes and quits
<Shift+zz> writes changes and quits
The “:” subcommand will place the cursor at the bottom of the screen.

Moving within a file
Note that for all the uppercase specified commands, the <shift> key must be used.
The following commands describe different techniques for moving around within a file.

Moving within a line
To move within a line make sure you are in command mode and:
<left-arrow> or h one character left
<right-arrow> or l one character right
0 move to beginning of line
$ move to end of line

Moving to a word
To move to a word:
w next small word
W next big word
b back to previous small word
B back to previous big word
e end of next small word
E end of next big word

Moving within the screen
To move within the screen:
<up-arrow> or k one line up
<down-arrow> or j one line down
H top line on screen
M middle line on screen
L last line on screen

Scrolling the screen
To scroll the screen:
<ctrl-f> scroll forward
<ctrl-b> scroll backward

Moving within the file
To move within the file:
1G go to the first line
45G go to line number 45
G go to the last line

To delete a single character: x
To delete to the end of the current word: dw
To delete to the end of the line: d$
To delete to the start of the line: d0
To delete the whole line: dd
To delete a range of lines: :20,40d
Undo the last change: u

Changing text
The command :g/ the /s// the one and only /g finds every occurrence of the string the and replaces it with the one and only. Notice that it would not replace the the on the first line of text. Remember about spaces: there was no space between the the and the new line character.
The first g tells the system to search for the first occurrence of the string on every line in the file.
The s stands for substitute. The next two slashes direct the editor to use the search string used in the preceding command, in this example the string the and replace it with the string the one and only.
The last g stands for global and directs the change to be made at every occurrence across each line being searched.
The R command will place you in text mode and allow you to overtype the existing text beginning at the current cursor position. The r command will place you in text mode and allow you to overtype only the letter at the current cursor position; after replacing that one letter you are place immediately back into command mode.
The c command can be used to specify the scope of what you want to replace, so that if you want to replace two words spanning of total of 10 characters, you can replace them with a very long string, such as 20 characters, and not overwrite the words which follow those two words.

How to copy, cut, and paste
To copy into a temporary buffer:
yy places the current line into a buffer
To cut (or move) text:
dd delete the current line (and store it in the undo buffer)
10dd delete the next 10 lines (and place them in the undo buffer)
To put text back:
p puts text back after the cursor or on the next line
P puts text back before the cursor or on the previous line
The u command will UNDO your last command if you make an error. So, if you delete something in error, immediately type the u command to retrieve it.

Cutting and copying multiple lines
Multiple lines can cut or copied by specifying a number either in front of the dd or yy command, or between the letters of the command.
10dd (or d10d) Cut 10 lines from the cursor position down into the buffer.
15yy (or y15y) Copy 15 lines from the cursor position down into the buffer.

Executing a single command from within vi
  - :!ls will create a shell.
  - All files in the current directory are listed. Press Enter to exit the shell and return to the vi session or,
  - While still in command mode, issue the :r snacks command. The contents of the file snacks are read into the vi file. By default, it will appear after the current line.
By default the data is placed at the current line. If you have line numbering set to on, you can precede the :r with a line number to place the contents of the file at any point in the file.

Executing multiple commands from within vi
If you need to run a series of commands without returning to vi after the first command is executed, enter :sh. When you have run all the commands, press <Ctrl-d> to exit the shell and return to vi.

Changing vi behavior
vi has many modes of operation. Some of these will affect the way text is presented, while others will make editing easier for novice users. Here are some examples:
:set all    Display all settings.
:set    Display settings different than the default.
:set autoindent    Sets autoindent on.
:set noautoindent    Turns autoindent mode off.
:set number    Enables line numbers.
:set nonumber    Turns line numbers off.
:set list    Displays non-printable characters.
:set nolist    Hides non-printable characters.
:set showmode    Shows the current mode of operation.
:set noshowmode    Hides mode of operation.
:set tabstop=4    Sets tabs to 4-character jumps.
:set ignorecase    Ignores case sensitivity.
:set noignorecase    Case-sensitive.
:set wrapmargin=5    Sets the margin for automatic word wrapping from one line to next. A value of 0 turns off word wrapping.

Options file
The file .exrc will be searched for in the current directory first. If found, then it will be read for settings as above.
If no .exrc was found in the current directory, the HOME directory is searched next. Finally, the built-in defaults are used.
.exrc contents are “set” options, but without the initial colon (:).

Editing the command line
Normally, you can only edit the command line using the backspace key (<Ctrl-h>) to back up and erase input or the interrupt key (<Ctrl-x>). The command line editing feature of the Korn shell allows you to use the same keys as the vi editor to edit the command line and correct mistakes. Many of the editing facilities of these editors are available.

Enabling command line editing
To enable command recall, you can enter the command set -o vi. Once set up, previous commands can be recalled by first pressing the Esc key and then pressing the k to go “up a line.” The list of commands is read from the .sh_history file.
The command line editor can also be set to use the commands from the emacs editor. It is set the same way as vi: set -o emacs

Editing commands
You can then edit the line as you would any line of text in a vi editing session. Only single letter commands will work, including the search capabilities.

Executing commands
When you have edited the line, press Enter, and it will be processed by the shell.

Disabling command line editing
To turn off the command recall facility enter $ set +o vi. Preceding any of the flags with a + (plus) rather than a - (minus) turns off the option.

vi:Full-screen, full-function editor
view:Read only form of vi, changes cannot besaved unless overridden with a force (!)
vedit:Beginner’s version of vi, showmode is on by default
ex, ed:Subset of vi working in line mode, canaccess the screen editing capabilities of vi
edit:Simple form of ex

---------------------------------------------------------------------------------------------

Unit 8.  Shell Basics

Shell features
The shell is the primary interface between the user and the operating system. The standard shell in AIX is the Korn shell.
The shell interprets user commands to start applications and use the system utilities to manage user data.
The shell enables multiple processes to be running in the background simultaneously to the foreground process with which the user is interacting.
The shell can be used as a comprehensive programming language by combining sequences of commands with the variables and flow control facilities provided by the shell.

Metacharacters
We will introduce the meaning of each of the metacharacters during the course of this unit.
Because the metacharacters have special meaning to the shell, they should not normally be used as any part of a file name.
The “-” symbol can usually be used in a filename provided it is not the first character.
For example, if we had a file called -l then issuing the command ls -l would give you a long listing of the current directory because the ls command would think the l was an option rather than -l being a file name argument. Some AIX commands provide facilities to overcome this problem.

Available metacharacters
!  "  $  %  ^  &  *  (  )  {  }  [  ]  #  ~ ;  '  <  >  /  ?  '  \  |

Wildcards
The wildcard ? is expanded by the shell to match from any single character in a file name. The exception is that the ? will not match a dot “.” as the first character of a file name (for example, in a hidden file).
The wildcard * is expanded by the shell to match zero to any number of characters in a file name. The single * will be expanded to mean all files in the current directory except those beginning with a dot. Beware of the command rm * which could cause serious damage removing all files.
Since the shell is interpreting the wildcard metacharacters and always substitutes filenames, filename substitution is only useful for commands that use filename option values or arguments. For example, the command: mail team* would not expand to a list of users starting with “team.”

Inclusion lists
The position held by the brackets and their contents will be matched to a single character in the file name. That character will either be a member of a list or range, or any character which is not a member of that list or range if the ! character is used at the start of the inclusion list.

Command redirection
The shell is the primary interface between the user and the operating system. The standard shell in AIX is the Korn shell.
Three files are automatically opened for each process in the system. These files are referred to as standard input, standard output, and standard error.
When an application works with a file, it opens the file using the path to the file, but once the file is open the application uses a numerical identifier, called a file descriptor, to identify which file to read from or write to. The numbers shown on the foil are the standard file descriptors for: STDIN (0), STDOUT (1), and STDERR (2).
Standard input, sometimes abbreviated to stdin is where a command expects to find its input, usually the keyboard.
Standard out (stdout) and standard error (stderr) are where the command expects to put its output, usually the screen. These defaults can be changed using redirection.

Three descriptors are assigned by the shell when the program starts:
Standard in: < 0
Standard out: > 1
Standard error: 2> 2

AIX file descriptors
A file descriptor number is what a program uses when it needs to identify a file which it will be read from or writing to. The file descriptors will differ depending on the command or utility that is currently running. Each AIX command opens its own set of file descriptors in order to keep track of the data files, input, output, and error messages.

Special files
Remember that in AIX, not all file names refer to real data files. Some files may be special files which in reality are a pointer to some of the devices on the system. An example would be /dev/tty0.

Redirection
In the redirection example, the file letter can be created using an editor or word processing application. It is then used as standard input to the mail program rather than typing from the keyboard. This would make it much easier to format the letter or correct any typing mistakes.
With redirection and the mail command, you will not get the normal prompts for Subject: or Cc:. You must use the following syntax:
mail -s “My Subject” -c user1,user2 recipient
The symbol < tells mail to take input from the file instead of the keyboard.
The mail program handles standard out differently than other commands.

Standard output redirection
Redirection allows standard output to go to somewhere other than the screen (default).
In the example, standard output has been redirected to go to the file named ls.out.
The file descriptor table in this example will hold the following values:
0 (unchanged) STDIN
1 (changed) ls.out
2 (unchanged) STDERR
Using ordinary redirection can overwrite an existing file. To avoid this, use >> (no space between them) to append the output to an existing file.
The file descriptors for the append example will be as follows:
0 (unchanged) STDIN
1 (changed) whos.there
2 (unchanged) STDERR

Other uses for cat
You already learned in an earlier activity that you can create files with the cat
command.
For the cat > newfile example, the file descriptors will hold the following information:
0 (unchanged) STDIN
1 (changed) newfile
2 (unchanged) STDERR

Notes:
STDERR redirection
Error messages from commands would normally be sent to the screen. This can be changed by redirecting the STDERR to a file.
When redirecting output, there can be no spaces between the 2 and the >.
The file descriptor table for the first error redirection example will contain the following:
0 (unchanged) STDIN
1 (unchanged) STDOUT
2 (changed) errfile
and for the second:
0 (unchanged) STDIN
1 (unchanged) STDOUT
2 (changed) /dev/null

Special file
The special file /dev/null is a bottomless pit where you can redirect unwanted data. All data sent there is just thrown away.
/dev/null is a special file. It has a unique property as it is always empty. It is commonly referred to as the bit bucket.

Combined redirection example
One may redirect multiple file descriptors on a single command. Normally the order in which you do the redirections is not important, unless you are using association.

Association example
In the first example, file descriptor 1 is associated with the file specified, outfile. Then the example associates descriptor 2 with the file associated with file descriptor 1, outfile.
If the order of the redirection is reversed as in the second example, then file descriptor 2 would be associated with the terminal (standard out) and file descriptor 1 would be associated with the file specified outfile.

Order of redirection in associations
With the association examples, the order in which redirections are specified is significant. For association, here is an example of ls:
ls -l / > ./list.file 2>&1
0 (unchanged) STDIN
1 (changed) ./list.file
2 (changed) ./list.file
And here is an example of how not to do association:
ls -l / 2>&1 > ./list.file
0 (unchanged) STDIN
1 (changed) ./list.file
2 (unchanged) STDOUT
In the second association example, the errors are redirected to the same place as standard out. But standard out at this point has not been redirected yet, so the default value will be used which is the screen. So, the error messages will be redirected to the screen. Remember that by default error messages are sent to the screen.

Pipes
A sequence of one or more commands separated by a vertical bar "|" is called a pipe.  The standard output of each command becomes the standard input of the next command.

Command pipes
Two or more commands can be separated by a pipe on a single command line. The requirement is that any command to the left of a pipe must send output to standard output. Any command to the right of the pipe must take its input from standard input.
The example on the visual shows that the output of who is passed as input to wc -l, which gives us the number of active users on the system.

Filters
A filter is a command that reads from standard in, transforms the input in some way, and writes to standard out.

Filter uses
A command is referred to as a filter if it can read its input from standard input, alter it in some way, and write its output to standard output. A filter can be used as an intermediate command between pipes.
A filter is commonly used with a string of piped commands, as in the example above.
The ls -l command lists all the files in the current directory and then pipes this information to the grep command. The grep command will be covered in more detail later in the course, but in this example, the grep command is used to find all lines beginning with a d (directories). The output of the grep command is then piped to thewc -l command. The result is that the command is counting the number of directories.
In this example, the grep command is acting as a filter.

Split Outputs
The tee command reads standard input and sends the data to both standard output and a file.

tee command
The tee command is a filter that can be used to capture a snapshot of information going through a pipe. tee puts a copy of the data in a file as well as passing it to standard output to be used by the next command. tee does not alter the data.

Grouping commands
Placing multiple commands separated by a “;” on a single line produces the same result as entering each command on a separate command line.

Line Continuation
The backslash (\) followed by a new line character can be used to continue a command on a separate line.
A secondary prompt character ">" is issued by the shell to indicate line continuation.
$ cat /home/mydir/mysubdir/mydata \
> /home/yourdir/yoursubdir/yourdata

Continuing the command line in shell
The Enter key preceded by a backslash (\<Enter>) can be used to continue a command on a separate line.
Do not confuse the continuation prompt > with the redirection character >. The secondary prompt will not form part of the completed command line. If you require a redirection character you must type it explicitly.

Unit Summary
Wildcards, * and ?, provide a convenient way for specifying multiple files or directory names.
The wildcard notation [ ] is like using the ? but it allows you to choose specific characters to be matched.
Three files automatically opened for redirection are standard in, standard out, and standard error.
I/O redirection alters the default input source or output destination of a command.
A pipe passes the output of one command directly to the input of another command.
A filter takes input from standard in, transforms it, and sends the output to standard out.
tee takes input and routes it to two places, standard out and a file.
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值