Linux Command Learning Notes

Source: Internet
Author: User
Tags gz file rsync vps server

manipulating files and directories:
Copy

$ cp file1 file2$ cp -r dir1 dir2

Move

$ mv file ..$ mv file dir/

Rename

$ mv file1 file2$ # dir2如果存在,则为移动操作

Remove

$ rm file$ rm -r dir

To create a file:

$ touch a.txt$ >a.txt

To create a directory:

$ mkdir dir

To view files:

#一般file#查看文件类型:filea.txt#创建和查看隐藏的文件/文件夹:$ touch .a.txt  或者 mkdir .dir$ ls -a#分页查看文件:file#ctrl ++:缩小  ctrl --:放大  j:向下滚屏 k:向上滚屏  /:字符查找 n:查找下一处 gg:文件头 G:文件尾 q:退出

* Wildcard characters :

$ #删除所有的html文件$ # 看所有以a开头的文件

Packaging and compression:

 #zip文件  $ zip-r name< Span class= "Hljs-preprocessor" >.zip  dir$ unzip Name.zip  #.tar.gz file  $ tar zxvf name.tar  .gz  $ tar zcvf name.tar  .gz  dir#.tar.bz2 file  $ tar jxvf name< Span class= "Hljs-preprocessor" >.tar  .bz  2$ tar jcvf name.tar  .bz  2 dir  

REDIRECT :
three important documents:
Everything under Linux is a file.
File Descriptor: 0 Standard input file 1 standard output file 3 standard error output file
How to redirect:
Output redirect:> files are emptied >> appended to a file before each redirect
Output error Redirect: 2>
Enter the redirect character:<
Pipe Line: The cornerstone of the Linux command line
Pipe Line command: | Pass the result of the preceding symbol to the command following the symbol as its input

Users and Permissions:
By default, there is no write permission in the other places (Ctrl + A can go directly to the beginning of the command) only if you have write permission under your home directory/home/usrname/
Three basic permissions:
READ: R write: W perform: X
Multi-user mode: Owner group World
File mode:

$ #对文件查看权限信息$ #对目录查看权限信息

Having write permission on a directory means that the files inside can be created, deleted, renamed, and so on, but having permission to write to a file does not have these operations permissions
Having execute permission on a directory means that you can CD into this directory, and the directory will generally have execute permissions when it is created.
chmod command:
For each of the three user modes, each file permission can be changed by 1, and 0 means there is no permission.

$ 111110110# owner有rwx group和world只有rw权限

Process:
Get Process Number:
PID indicates the process number
Linux under the rough can be thought that each time a user executes a new program, the system will open a new process
PS Command: The role is to report the current process status on the system
PS aux |less View process number of all processes $ ps aux |grep vim find vim process number
Alt + TAB to switch directly from each open program
Background execution:
Add & symbols in the back to allow the program to execute in the background
If you have already opened the program, the remedy is to use CTRL + Z to pause the program, go back to the command line, and then enter the BG command, like Add &. Then knock FG back to the front desk, Crtl + C off
Kill

$ kill pid号   # 程序在正常运行的时候有用,相当于加了 -2$ kill -9 pid  # 当程序跑飞了,强制终止

What to do if the program runs stuck to the command line interface:
Linux runs at the same time 7 Workbench, knock Crtl + ALT + F1 to the first workbench here to enter the command to kill the process, and then knock Crtl + ALT + F7 back to the original workbench

Find:
Locate: Locating files at the system global scope
Locate does not locate the file in the entire file system, but locates the file from a database, which is why the locate executes quickly.
There is also a updatedb command that updates files in the file system to database, but UpdateDB is typically performed once a day. Causes locate not to find those files that are newly created.
Remedy: $ sudo updatedb and then locate
Find: Locating files within a directory scope

$ #列出目录下的所有文件$ find dir  # 只看目录下的所有文件$ find dir  # 只看目录下的所有目录$ ‘{}‘‘;‘  # xxx可以是各种系统命令,对找到的文件进行操作$ ‘{}‘‘;‘  # 在找到的所有文件中查找hello字符串,并且打印所在的文件的文件名

Grep:

$ #查找hello字符串$ #并且显示出行号$ #显示出行号,并忽略大小写

ACK grep: A command specifically designed for programmers to find in code
To move a binary file to ~/bin, the command can be used throughout the system: $ rm xxx ~/bin
If a command is too long, you can go to the ~/bin directory $ ln -s xxx y can give xxx an alias y after using y is quite with xxx

Network operation:
Remote operation:
The program on your own computer to put on the server, you can spend 10$ every month to buy a VPS server, the server installed on the Ubuntu server system.
SSH: Can be considered the Internet on the two machine interconnection of a protocol, requires the server to open 22 ports, such as the HTTP protocol needs to open 80 ports. In addition to opening 22 ports, the server side and client are required to install the appropriate SSH software.
Both Ubuntu Desktop Edition and Ubuntu Server Edition are installed by default.
Buy the server, will give an IP, can give this IP binding a domain name.
You can connect to a server like this on desktop: you $ ssh 服务器上的用户名@域名或者ip can enter a password and then work on the server.
Ctrl+d can exit the server.
Each time you enter a password, you can enter it locally $ ssh-keygen and then you can get the public key (Id_rsa.pub) and the private key (Id_rsa) under. ssh. Still running under. SSH $ ssh-copy-id 服务器上的用户名@域名或者ip . Do not enter a password in the future.
Tmux is a good remote operation to prevent off-network and misoperation interrupt communication, the data is not saved by the software.
Data transfer:
Rsync: For local and remote synchronization of data. If SSH is available, rsync can be used.
upload using:

$ rsync -r 本地目录 服务器上的用户名@域名或者ip:服务器上路径

You can upload the local directory to the server path. Note The local directory cannot be followed by A/
The download only needs to swap the position of the above two parameters
How to synchronize locally added files:

$ rsync -av mydir/ 服务器上的用户名@域名或者ip:服务器上路径/mydir/

Here the V parameter is to show the execution process a parameter is to preserve more complete file information
How to synchronize locally both add and delete files:

$  rsync -av --delete mydir/ 服务器上的用户名@域名或者ip:服务器上路径/mydir/

To prevent accidental deletion of some files, you can do this first:

$  rsync-av--deletemydir/服务器上的用户名@域名或者ip:服务器上路径/mydir/  --dry-run

Report only the information before performing a true sync operation.

Software Installation:
Manual Installation:
Download the compiled code after the decompression:
The resulting directory is placed in a non-interfering place, preferably in a hidden directory

echo$PATH#可以查看环境变量PATH,它的值是一系列由:隔开的目录。

Just put the executable file in any directory under path, you can become a system executable command.
You can also create a link without moving the executable program itself: $ ln -s 本来的可执行程序目标位置以及名字
Download the source code to compile and install yourself:
Unzip and switch to the source directory

./configuremakemake install

Deb Pack: Debian package
Manual Installation issues: Installation dependencies can cause inconvenience to the installation process, and when you install software, you forget where the files are installed, and uninstalling the software becomes a nightmare.
Deb Package = program itself + Config file + install location + dependencies
Happycasts The 14th issue explains how to make a program from the source code into a deb package
Install a program for the Deb package: $ sudo dpkg-i deb package

$ #可以查看所有安装过的chrome deb包$ dpkg -L#看包安装了哪些文件$ dpkg -S#看一个文件来自那个包

Install from Apt-get Warehouse:
The bottom of the apt-get is wrapped in dpkg.
Open source software is generally in the form of source packages on GitHub or the Free Software Foundation, Ubuntu will regularly make these source packages into the Deb package, and on Ubuntu own server to build a software warehouse apt repo, and then upload the Deb package to the software warehouse.
It's easy to install the software under Ubuntu, and $ apt-get install 软件名 it's ready to install.
Uninstalling the Software: $ sudo apt-get remove 软件名
Delete the configuration file together: $ sudo apt-get purge 软件名
When you do not know the exact name of the package, you can use: $ apt-cache search 貌似的软件名|less
Apt-get will also automatically help install dependent files

Script Programming Tips:
Specify the parser:
Bash is generally used as a parser, so in the first line add: #!/usr/bin/env bash indicates that the following statement is parsed with bash
But not only bash can parse, Python ruby, and so on can parse the script #!/usr/bin/env python indicates the parsing with Python
statement is the command:
The command in the command line, placed in the script, is called a statement
Commands can be listed directly in the script or wrapped into a function that executes the command by calling the function name:
say_hello(){ echo "hello" }Then call Say_hello call echo "Hello" command
command is sensitive to whitespace, so script statements are sensitive to whitespace
Position Parameters:
The script can also enter parameters when running, accept parameters in script $ #表示参数的个数 $0 script file name \ $1–\ $n User-supplied parameters
The script does not execute in the current shell:
Instead of executing in the current shell, the script opens a new shell and executes the script inside.
Do not execute scripts in the current shell, using source xx.sh
Loop control:

cd$1forin `ls`do   ****命令done

The output pwd of the command can be retrieved from the script.
Remote execution:
Written in the script:

$ ssh -t 远程用户名@ip或者域名  ‘要执行的脚本或者命令‘

Confirm execution:

echo"Want to continue? (Y/n)"read AAAif ["${AAA:-y}""y"];then     #调用函数else    echodone, bye.fi

Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Linux Command Learning Notes

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.