Linux Shell Study Notes

Source: Internet
Author: User
Tags file copy

Chapter 2 shell Basics

 

1. Which two files are used during shell initialization?

/Etc/profile, which contains the shell initialization information required by all users in the system

. Profile, whether it is in the user's starting directory. The starting directory is the directory in which the user logs in.

 

2. Why do we need to set path and manpath?

Before executing the shell command, locate the location of the command. The role of path is to locate this location.

Manpath is used to set the online help manual location

 

3. The first line of code in the script #! What is the purpose of/bin/sh?

Make sure to run the script with SH. Otherwise, the current shell will be used to execute the script regardless of the shell.

 

4. What commands do I need to access online help?

Man command

 

Important Concepts

1. shell not initialized: it is not initialized when the shell is just started. This means that the important parameters required for proper Shell Running are not yet defined.

2. Shell initialization: After the shell is started, it will go through an initialization phase to set some important parameters. This is actually a two-step process. The shell reads

File/etc/profile and./Profile

3. Start Directory: the user's start directory is the directory in which the user logs on

 

 

Chapter 3 File Operations

Unix has three basic types of files:

1. Common files

2. Directory

3. Special files

A common file is a file containing data, text, or program instructions in the system.

 

3.1 Column file name

$ Ls # column directory

This output indicates that there are many different items in the current directory, but it does not tell which files and folders are used.

 

$ LS-F # column directory.-F indicates that the folder is marked by a slash.

 

$ LS-L # list directories in one row to facilitate awk text filtering.

 

 

3.1.1 hide a file

In Linux, files starting with (.) are invisible.

For example:

. Profile, Bourne shell (SH) initialization script

. Kshrc, KoRn shell (Ksh) script Initialization

. Cshrc, C shell (CSH) script Initialization

. Rhosts, remote shell configuration file

All files not starting with (.) are considered visible.

To list invisible files, you only need to use the-A option.

$ LS-A # column directory, including hidden files

 

 

3.2 Browse File Content

The column file name is very important, but the shell script also needs to browse the file content.

 

3.2.1 use the cat command to browse the File Content

$ Cat hosts # display the content of the hosts file

You can declare more than one file:

$ Cat hosts users # the content of the two files is displayed.

 

Parameter-N, indicating the row number of the output result.

Parameter-B, ignore empty rows.

 

3.2.2 use WC to count words

You can use this command to count the number of lines, words, and characters in the file.

Format: WC [Options] files

$ WC. Hosts

If not selected, the statistical summary of the number of rows, number of words, and number of characters is output.

The returned result is: 7 14 179. Hosts

Number of file lines, number of words, number of characters, and file name

 

It supports statistics on multiple files at the same time.

$ WC test1.php test2.php

The returned results are formatted as line breaks and output statistics in sequence.

 

-L: Number of Statistics rows

-W: Number of words

-C: Number of statistical characters

 

3.3 operation files

Several Methods to operate files:

1. Copy an object

2. Rename the file

3. delete an object

 

3.3.1 CP file copy command

$ CP source destination

Source: The copied file name.

Destination: copy name

For example, copy test1.php and put it to a file named test2.php.

$ CP test1.php test2.php

 

1. Common Errors

The CP command is not output unless it has an error. It includes two common errors:

1. The source file is a directory

2. The source file does not exist.

 

2. Interaction Mode

If the target file already exists, no error message is generated. In this case, the target file is automatically overwritten. This may lead to potential risks.

To avoid this situation, you need to use option-I to prompt for interactive operations. Y indicates overwriting, and N indicates canceling.

 

3. copy the file to another directory.

If the target file is a directory, the copied name is the same as the source file name and is copied to the target directory.

$ CP test1.php/var/www/html/

The file test1.php will be generated in/var/www/html.

 

4. Multiple inputs

$ CP test1.php test2.php test3.php/var/www/html/

Use the last parameter as the target file and copy test1.php, test2.php, and test3.php to the/var/www/html/directory.

But if it is a source file with multiple directories, an error will occur.

 

-R option, copy between Directories

 

3.3.2 renaming a file

$ MV source destination

Source: Source File Path

Destination: New File Name

If the target file name already exists, the system will prompt whether to delete it and rename it.

-I option: Interactive Mode

 

3.3.3 RM delete an object

$ Rm files

Delete one or more file lists

1. Common Errors

The declared file does not exist.

The declared file is a directory.

 

Because the files deleted by RM cannot be recovered, you can use the-I option to use the interactive mode, prompting you to delete each file.

You can use the-r option to delete the file directory.

 

If the interactive mode exists in all the commands above, you can use the-F option to block the prompt.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.