Linux (ii)

Source: Internet
Author: User
Tags aliases parent directory uppercase letter filezilla secure copy ssh server asymmetric encryption dns spoofing

Files and directories Common command target
    • View Catalog Contents
      • ls
    • Switch directories
      • cd
    • Create and delete operations
      • touch
      • rm
      • mkdir
    • Copying and moving files
      • cp
      • mv
    • View File Contents
      • cat
      • more
      • grep
    • Other
      • echo
      • REDIRECT > and>>
      • Pipeline|
01. View Directory Contents 1.1 Terminal practical Tips 1> Auto-complete
    • 文件 目录 命令 After the first few letters of the hit//, press the tab key
      • If there is no ambiguity in the input, the system will automatically complete
      • If there is another 文件 / 目录 / 命令 , press the tab key again, the system will prompt for possible commands
2> have used the command
    • Press the / cursor key to switch back and forth between commands that have been used
    • If you want to exit the selection and do not want to perform the currently selected command, you can pressctrl + c
1.2 lsCommand description
    • lsis the abbreviation of the English word list, its function is to list the contents of the directory, is one of the most commonly used commands, similar to DOS dir commands
Features of files and directories under Linux
    • A Linux file or directory name can have 256 a maximum of one character
    • .the file to begin with is a hidden file and needs to be displayed with the-a parameter
    • . Represents the current directory
    • .. Represents the previous level of the directory
1.3 ls Common options
Parameters meaning
-A Displays all subdirectories and files in the specified directory, including hidden files
-L Display file details in a list
-H Display file size in a humane way with-l
How file size is represented in the computer (popular science)
Unit English meaning
Bytes B (Byte) As a digital unit in a computer, typically a 8-bit binary number
Thousand K (Kibibyte) 1 KB = 1024x768 B, Kbytes (1024 = 2 * * 10)
Trillion M (Mebibyte) 1 MB = KB, Million bytes
Thousand trillion G (Gigabyte) 1 GB = 1024x768, 1 billion bytes, gigabytes
Too T (Terabyte) 1 TB = 1024x768, trillion bytes, MBytes
Take P (Petabyte) 1 PB = 1024x768 TB, petabyte bytes, Pat Byte
Ai E (Exabyte) 1 EB = 1024x768 PB, exascale bytes, Ai byte
Ze Z (Zettabyte) 1 ZB = EB, 10 trillion bytes, ze byte
Yao Y (Yottabyte) 1 YB = 1024x768 ZB, 100 million bytes, Yao byte
Use of the 1.4 LS wildcard
wildcard characters meaning
* Represents an arbitrary number of characters
? Represents any one character, at least 1
[] Indicates that any one of the character groups can be matched
[ABC] Match any of A, B, c
[A-f] Match any one of the characters from a to F range
02. Switch Directories 2.1 cd
    • cdis a shorthand for the English word change directory, which is a function of changing the current working directory and is one of the most commonly used commands for users.

Note: All Linux directories and file names are case-sensitive

Command meaning
Cd Switch to the current user's home directory (/home/user directory)
CD ~ Switch to the current user's home directory (/home/user directory)
Cd. Remains unchanged in the current directory
Cd.. Switch to Parent directory
CD- Can switch back and forth between the last two working directories
2.2 Absolute path and relative path
    • Absolute path to/or ~ as the path at the beginning, indicating the specific directory location starting from the root directory/home directory
    • The relative path does not take the path indicated by/or ~ as the beginning, indicating the directory location relative to the current directory
03. Create and DELETE operations 3.1 touch
    • Create a file or modify a file time
      • If the file does not exist, you can create a blank file
      • If the file already exists, you can modify the last modified date of the file
3.2 mkdir
    • Create a new directory
Options meaning
-P Directory can be created recursively

The name of the new directory cannot be the same as the existing directory or file in the current directory

3.3 rm
    • Delete a file or directory

Use rm the command with caution because the file cannot be recovered after deletion

Options meaning
-F Forced deletion, ignoring nonexistent files without prompting
-R To delete the contents of a directory recursively, this parameter must be added when deleting a folder
04. Copying and moving Files 4.1 tree
    • treecommand to list the file directory structure in a tree view
Command corresponding English function
Tree [directory Name] Tree List the file directory structure in a tree view
Options meaning
-D Show only Directories
4.2 cp
    • cpThe function of a command is to copy the given file or directory to another file or directory, which is equivalent to a DOS copy command
Command corresponding English function
CP Source File Destination file Copy Copy files or directories
Options meaning
-I. Prompt before overwriting files
-R If the given source file is a directory file, the CP will recursively replicate all subdirectories and files in that directory, and the destination file must be a directory name
4.3 mv
    • mvCommands can be used to move files or directories, or to rename files or directories
Command corresponding English function
MV Source File Destination file Move Move files or directories/files or directories to rename
Options meaning
-I. Prompt before overwriting files
05. Viewing the contents of a file 5.1 cat
    • catCommands can be used to view file contents, create files, merge files, append file contents, etc.
    • catDisplays all content at once, suitable for viewing text files with less content
Command corresponding English function
Cat file name Concatenate Ability to view file contents, create files, merge files, append file contents, and more
Options meaning
-B Number of non-null output lines
-N Numbering all lines of the output

Linux also has one nl command and cat -b the effect is equivalent

5.2 more
    • moreCommands can be used to display the contents of a file on a split screen, displaying only one page at a time
    • Suitable for viewing text files with more content
Command corresponding English function
More file names More Split-screen display of file contents

moreoperating keys to use:

Operation Keys function
Space key Show the next screen of the man page
Enter One row of the scroll manual page
B Roll back one screen
F Roll forward one screen
Q Exit
/word Search Word string
5.3 grep
    • grepcommand is used to search for specified content in text
Command corresponding English function
grep search text file name Grep Search for text file contents
Options meaning
-N Display matching lines and line numbers
-V Display all lines that do not contain matching text (equivalent negation)
-I. Ignore case
    • grepAllow the text file to pattern lookup, so-called pattern lookup, also known as regular expression, in the employment meeting detailed explanation
    • Two common modes of finding
Parameters meaning
^a Beginning of line, searching for lines beginning with a
ke$ End of line, search for lines ending with Ke
06. Other 6.1 echo 文字内容
    • echoThe text specified in the parameter is displayed in the terminal and is typically used in conjunction with redirection
6.2 Redirects >And >>
    • Linux allows command execution results to be redirected to a file
    • Output/append content that should be displayed on the terminal to the specified file
# 将文本hello输出到test.txt中$ echo hello > test.txt

which

    • >Represents the output, overwriting the original contents of the file (the original content is deleted)
    • >>Represents an append that appends content to the end of an existing file
6.3 Piping |
    • Linux allows the output of one command to be piped as input to another command
    • Play the role of connecting two commands

Common commands for piping mates are:

    • more: Split screen display content
    • grep: Queries the specified text based on the result of the command execution
# 查询当前目录中名称包含test的目录/文件$ ls -lh | grep test
Remote management of common command targets
    • Shutdown/Restart
      • shutdown
    • viewing network card information
      • ifconfig
      • ping
    • Telnet and copy files
      • ssh
      • scp
01. Shutdown/Restart 1.1 shutdown
    • shutdowncommand to safely shut down or reboot the system
Command corresponding English function
Shutdown option Time Shutdown Shutdown/Restart
Options meaning
-R Restart

Tips:

  • Do not specify options and parameters, default = 1 minutes after shutting down the computer
  • When maintaining the server remotely, it is best not to shut down the system, but should reboot the system
    • Common command Examples
# 重新启动操作系统,其中 now 表示现在$ shutdown -r now# 立刻关机,其中 now 表示现在$ shutdown now# 系统在今天的 20:25 会关机$ shutdown 20:25# 系统再过十分钟后自动关机$ shutdown +10# 取消之前指定的关机计划$ shutdown -c
02. View NIC Information 2.1 network-related NIC
    • NIC is a hardware device dedicated to network communication
    • Network devices (computers, mobile phones, etc.) with a network card to connect
IP Address
    • An IP address is an identifier configured for a networked device by a network card, for example:192.168.123.132

    • An identity card equivalent to a network device that distinguishes different devices in the network

    • In the same network environment, the IP address is unique, the IP address is the same, resulting in IP address conflicts, which can not be properly networked

Domain name
    • Consists of a string of names separated by dots, for example:www.itcast.cn
    • Is the alias of the IP address, user-friendly memory
Port number
    • IP Address: Locate the computer on the network by IP address
    • Port number: You can find the application running on your computer by port number

    • To access a specified service on a computer on the network, you must know the IP address and port number of the other

    • List of common service port numbers:

Serial Number Service Port number
01 SSH Server 22
02 Web Server 80
03 HTTPS 443
04 FTP Server 21st

Hint: Detailed information about the network, in the Employment class meeting detailed explanation!

2.2 ifconfig
    • ifconfigYou can view/configure your computer's current network card configuration information
Command corresponding English function
Ifconfig Configure a network interface View/Configure your computer's current network card configuration information
# 查看网卡配置信息$ ifconfig# 查看网卡对应的 IP 地址$ ifconfig | grep inet

Tip: A computer may have a physical network card and multiple virtual network cards, in Linux the name of the physical network card is usually ensXX expressed as

    • 127.0.0.1Known as the local loopback/loopback address, commonly used to test the native NIC is normal
2.3 ping
Command corresponding English function
Ping IP Address Ping The connection to the destination IP address is detected as normal
# 检测到目标主机是否连接正常$ ping IP地址# 检测本地网卡工作正常$ ping 127.0.0.1
    • pingGenerally used to detect whether the network between the current computer and the target computer is unobstructed, the higher the value, the slower the speed
  • pingWorks like a submarine sonar, and ping This command is the sound of sonar.
  • Network administrators are also often ping used as verbs--ping computer x to see if he is open

Principle: The machine on the network has a unique IP address, we send a packet to the destination IP address, the other side will return a packet, according to the returned packet and time, we can determine the existence of the target host

Tip: In Linux, to terminate the execution of a terminal program, the vast majority of them can be usedCTRL + C

03. Telnet and Copy files 3.1 ssh(key) 1) SSH Foundation
    • There are many tools in Linux that can be used for remote login, such as Telnet, SSH, VNC, etc.
    • SSH is generally used as the main way to connect remote server, through SSH client we can connect to remote machine running SSH server.

    • An SSH client is a Secure Shell(SSH) software program that uses protocols to connect to a remote computer
    • SSHis currently a more reliable protocol that provides security for Telnet sessions and other network services
      • Use SSH 协议 can effectively prevent information leakage during remote management
      • SSH 协议can also prevent DNS spoofing and IP spoofing by encrypting all transmitted data
    • SSHAnother advantage is that the transmitted data can be compressed, so it can speed up the transmission
2) Simple use of SSH client
Command corresponding English function
SSH User name @ip Secure Shell Telnet
# 使用ssh客户端远程登录到指定的计算机$ ssh [-p port] [email protected]
    • useris the user name on the remote machine, and if it is not specified, the current user
    • remoteIs the address of the remote machine, which can be a ip/domain name, or an alias that will be mentioned later
    • portis the port that the SSH server listens to, the default port number of the SSH servers is 22 , the default port number is used if not specified

Tips:

  • Use exit to exit the current user's login
  • At work, the port number of the SSH server is probably not 22, if you encounter this situation you need to use the -p option to specify the correct port number, otherwise it will not connect to the server properly
3) Installation of the SSH client under Windows
    • sshThis terminal command can only Linux be UNIX used on or under the system
    • If you are in the Windows system, you can install PuTTY or the XShell client software

    • PuttyHttp://www.chiark.greenend.org.uk/~sgtatham/putty/latest.html

    • XShellHttp://xshellcn.com

It is recommended to download the official installation program from the official website.

3.2 scpMaster
    • SCP is secure copy a command that is used to remotely copy files under Linux
    • You can copy local content to a remote computer or copy the contents of a remote computer to a local

Command corresponding English function
SCP User name @ip: file name or path user name @ip: file name or path Secure copy Remotely copying files
Options meaning
-R If the given source file is a directory file, SCP will recursively replicate all subdirectories and files in that directory, and the destination file must be a directory name
-P If the port of the remote SSH server is not 22, you need to specify the port with the uppercase letter-p option
    • Its address format is basically the same as SSH, and it is important to note that the port is specified in uppercase -P instead of lowercase.
    • Path after the ': ' of the IP address if it is not an absolute path, use the user's home directory as the reference path
 # copy 01.py files from the local current directory to desktop/01.pyscp-p Port 01.py [email protected]:D esktop/01.py # copy the desktop/01.py file under the remote home directory to the local current directory 01.pyscp-p port [email protected]:D esktop/< Span class= "Hljs-number" >01.py 01.py# Plus-r option to transfer folders # Copy the demo folder under the current directory to the remote home directory desktopscp-r demo [email protected]:D esktop# copy Desktop from the remote home directory to the demo folder under the current directory Scp-r [email protected]:D esktop demo     span>      

Attention:

  • scpThis terminal command can only Linux be UNIX used on or under the system
  • If Windows you can install it in the system, use the PuTTY pscp command-line tool or install it FileZilla FTP for file transfer
FileZilla
    • Official website: https://www.filezilla.cn/download/client
    • FileZillaWhen transferring files, use FTP 服务 rather than SSH 服务 , so the port number should be set to21
3.3 SSH Advanced (Know)
    • Password-Free Login
    • Configure aliases

Tip: The SSH configuration information is stored in the directory under the user's home directory .ssh

1) password-free login steps
    • Configuring the Public Key
      • Execute ssh-keygen to generate SSH key, all the way to enter
    • Upload public key to server
      • Execution ssh-copy-id -p port [email protected] , allowing the remote server to remember our public key

Asymmetric encryption algorithm

  • Data encrypted with public key requires decryption with private key
  • Data encrypted with the private key needs to be decrypted with the public key
2) Configure aliases

Input every time ssh -p port [email protected] , the time will feel very troublesome, especially when user , remote and port all have to input, but also bad memory

And the configuration alias can let us further lazy, for example, in ssh ubuntu order to replace such a long string, then the local computer to ~/.ssh/config append the following content:

Host ubuntu    HostName 服务器ip地址    User python    Port 22

Once you've saved it, you can use it to ssh ubuntu log in remotely. scp






Linux (ii)

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.