XShell Command-User Manual for New Workplace

1. Why learn Xshell

Xshell is a powerful secure terminal simulation software. It supports SSH1, SSH2, and the TELNET protocol of the Microsoft Windows platform. It is generally used in the Windows interface to access servers in different remote systems, so as to achieve remote control. The purpose of the terminal.
When learning Linux, although XShell is not necessary, we can enter commands through the centos terminal interface to complete the learning. But XShell can link our Windows system with your Linux system, which is convenient for us to operate the Linux system in the Windows environment.
For programmers, it is especially important to be able to use XShell proficiently in formal work. We often need to connect to our company's server through XShell, and we can use it to view the implementation logic of specific functions in the background code, but more often we XShell is mainly used to view the log file printed when the program is running to locate the cause of the program error. . How to use XShell commands at this time has become the focus of our study. Next, I will introduce some very useful commands of XShell.

2.XShell use

2.1 Connect to the server

XShell has two ways to connect to the server:

  1. Directly click on the new connection on the interface and fill in the relevant information.
    Insert picture description here
    After clicking OK, you need to fill in the user name and password. After the connection, the [root@******] style in the following interface appears, which proves that the connection is successful.
  2. Use ssh command to connect
ssh [options] [user@]host [command]

Among them, host is the name of the OpenSSH server (remote system) you want to connect to, and it is the only required parameter. The host can be the name of a local system, the FQDN of a system on the Internet (see the glossary) or an IP address. Command ssh host to log in to the remote system host, and the username used is exactly the same as the username being used on the local system. If the user name you want to log in is different from the user name being used on the local system, then user@ should be included. Depending on the server settings, a password may also be required. If the command parameter is not provided, ssh will let you log in to the host. The remote system displays a shell prompt and can then run commands on the host. The command exit will close the connection with the host and return to the prompt of the local system.

2.2 Using XShell

After XShell is connected, the buddies who have just entered may feel that their eyes are blackened. What should I do next?
Don't be afraid, I will demonstrate the use of some of the most basic commands here to help friends familiarize themselves with the use of XShell commands. First of all, we want to know which files we have, then we can use the ll or ls -l command to view, ls can also be used, but it will be inconvenient to display all the files horizontally, ls -l and ll have the same effect, obviously ll is simpler.
Insert picture description here
How do we enter the file we want to see after seeing the file? In a graphical system like windows, we can use double-click to open the file we need to open. In Xshell, we need to use: cd file name . To enter files in multi-level directories, the name of each level directory must be written (you can use the tab key to complete) with a slash "/" in the middle.
After we enter the catalog, how do we know that our current location is the place we want to enter? At this time , the function of the pwd command comes. Its main function is to check the current path.
Insert picture description here
If you enter, there will be a return. When you need to return, we need to use: cd …/ This command, we can also add the upper-level file directory we need to enter after …/ to directly enter.
Insert picture description here
Next is how to edit the file and view the file. If there is a d.xml file in the d directory, we need to edit or view it. The command to view is cat d.xml; the command to edit is vi d.xml, and then press i to enter the modification mode, or just watch, if we suddenly don’t want to modify, press ESC and write in the command line :q! Then press Enter to touch editing. If we need to save after editing, we also need to press ESC, and then enter :wq to press Enter.
in conclusion:Edit the file vi, press i to edit, save and finish editing ESC :wq Enter without saving and finish editing ESC :q! Enter
Insert picture description here
This is just a small part of the XShell commands, if you need to learn more, you can use the other commands I summarized below Continue to experiment and discover more fun of learning XShell~

3.XShell command

3.1 Basic operation

View catalog

ls          --列出当前目录下所有文件名
ls -l       --列出当前目录下所有文件的一个长列表
ls -la      --列出当前目录下所有文件的一个长列表,包括以句点开头的隐藏文件
ls a*       --列出当前目录下以字母a开头的所有文件
ls -l *.doc --列出当前目录下以.doc结尾的所有文件

Enter the catalog


cd ../  或者  cd /      --进入根目录下
cd ..                   --当前目录的上一级目录
cd ../..                --切换到上两级目录
cd ~                    --切换用户目录,如果是root用户,则切换到/root下
cd /home/bin            --进入当前目录的/home/bin目录下

View the current path: pwd

Create catalog

mkdir 001  --在当前目录下建立001目录
mkdir -p /001/002/003  --在当前目录下嵌套建立指定目录(要带上当前目录)

Find package/text

find -name *.rpm 在当前目录中查找rpm包
grep aaa /home/bin/file1 --在file1文件中查询包含aaa的所有行

Pack/Unzip

打包文件
tar -cvf file1.zip file1   --将file1打包成file1.zip格式,此处可以打包成任意格式,即后缀可以为任意的,.aaa,.bbb,.zip,.tar 等
解包文件
tar -xvf file1.zip         --解压包file1.zip,如果当前目录已经有文件了,覆盖原文件,否则正常显示

Text manipulation

文本复制:Ctrl+Insert
文本粘贴:Shift+Insert
3.2 File operations

File upload/download

文件上传:rz 回车
文件下载:sz file1
//提示:如果连接linux虚拟机上,rz命令不起作用,需要安装一个rz和sz的程序:yum install -y lrzsz

File copy

cp file1 file1.bak --把文件file1复制为新文件file1.bak
cp file1 /home/bin --把file1文件从当前位置复制到/home/bin目录下
cp *   /home/bin   --把当前文件下所有文件复制一份到/home/bin目录下

File move

mv * /home/bin   --把当前目录下的所有文件移动到/home/bin目录下
mv file1 /home/bin --把file1文件从当前位置下移动到/home/bin目录下

File deletion

rm file1,file2,...    --删除当前目录文件file1,file2等
rm *   --删除当前目录下所有非隐藏文件,不删除目录,除非指定了-r(递归参数)
rm -rf /home 删除home目录及它所包含的所有内容
rm -r /home 删除home目录,会让你确认是否删除目录下的文件
rm -i a* 

File rename/create

mv file1 file2  --把file1名称改为file2
touch a.html --在当前目录创建一个空的a.html文件

View file content

more file1 --查看file1文件的内容,支持分页显示
less file1 --查看file1文件的内容
cat file1  --显示file1文件的内容
tail -f file1   --查看file1的内容
tail -100 file1 --查看file1的后100行内容

Edit file

vi file1 --编辑file1文件内容
 
esc      --退出vi模式,跳入命令模式
 
:w       --保存,但不退出vi模式
:w!      --强保存,但不退出vi模式
 
:wq      --保存,并退出vi
:wq!     --强保存,并退出vi
:q       --不保存,退出vi
:q!      --不保存,强制退出vi
:e!      --放弃所有修改,从上次保存文件开始再编辑
Ctrl+Z   --将vi暂停(挂起)
ctrl+c   --进入命令模式
3.3 System commands
man rm  --显示rm命令的使用说明
w       --显示登录用户的详细信息,类似于who
who     --显示登录用户
last    --显示最近登录的用户
 
date    --显示当前时期和时间
 
su      --切换root用户
su zy   --切换到zy用户
 
clear   --清屏
 
free    --查看系统内存和Swap分区情况
 
reboot  --重启虚拟机
shutdown -r now --停止服务后重启计算机
shutdown -h now --停止服务后关闭计算机
halt     -关闭计算机
 
tips:如果操作中有特殊的符号,比如()等,记得加\转义一下,如你要删除file1_(1).html,要写成 rm file1_\(1\).html

Guess you like

Origin blog.csdn.net/ly_6699/article/details/107686089