Linux Command learning notes, linux learning notes

Source: Internet
Author: User
Tags create directory gz file ssh server vps server

Linux Command learning notes, linux learning notes

Operation files and directories:
Copy:

$ cp file1 file2$ cp -r dir1 dir2

Move:

$ mv file ..$ mv file dir/

Rename:

$ Mv file1 file2 $ mv dir1 dir2 # If dir2 exists, it is a move operation.

Remove:

$ rm file$ rm -r dir

Create a file:

$ touch a.txt$ >a.txt

Create directory:

$ mkdir dir

View files:

# $ Cat file # View file Type: $ file a.txt # create and view hidden files/folders: $ touch .a.txt or mkdir. dir $ ls-a # view the file by PAGE: $ less file # ctrl ++: zoom down ctrl --: Zoom in j: Scroll down k: Scroll up/: character search n: find the next gg: File Header G: file tail q: Exit

* Wildcard:

$ Rm *. html # delete all html files $ echo a * # view all files starting with

Packaging and compression:

# Zip file $ zip-r name.zip dir $ unzip name.zipw.tar.gz File $ tar zxvf name.tar.gz $ tar zcvf name.tar.gz File $ tar jxvf name.tar.bz2 $ tar jcvf name.tar.bz2 dir

Redirection:
Three important files:
Everything in linux is a file.
File descriptor: 0 standard input file 1 standard output file 3 standard error output file
Redirection method:
Output redirection character:> clear the file before each redirection> append the content to a file
Output Error redirection: 2>
Enter the redirection character: <
Pipe line: the cornerstone of linux Command Line
Pipeline line command: | pass the result before the symbol to the command after the symbol as its input

Users and permissions:
By default, the write permission is only available in the home directory/home/usrname/. The write permission is not available in other places (ctrl + a can be directly directed to the beginning of the command line)
Three basic permissions:
Read: r write: w execute: x
Multi-user mode: owner group world
File mode:

$ Ls-l a.txt # view permission information for files $ ls-ld dir # view permission information for directories

Write Permission on a directory, which means you can create, delete, rename, and perform other operations on the files in it. However, you do not have the write permission on a file.
You have the execution permission on a directory, which means you can run cd to this directory. The directory generally has the execution permission when it is created.
Chmod command:
For each file permission in three user modes, 1 indicates that you have the permission to change, and 0 indicates that you do not have the permission.

$ Chmod 111110110 a.txt # The owner has the rwx group and world permissions only.

Process:
Get process Number:
PID indicates the process number.
In linux, We can roughly think that every time a user executes a new program, the system will start a new process.
Ps command: Used to report the current process status on the System
Ps aux | less view process numbers of all processes $ ps aux | grep vim find vim process numbers
Alt + Tab can be directly switched in each opened Program
Background execution:
Add the & symbol to the backend so that the program can be executed in the background.
If the program has been opened, the remedy is to pause the program with ctrl + z, return to the command line, and then enter the bg command, so that the addition is the same. Then knock fg and return to the front-end. crtl + c is disabled.
Kill:

$ Kill pid # It is useful when the program runs normally. It is equivalent to adding-2 $ kill-9 pid # force termination when the program runs.

What if the command line interface is stuck when the program runs:
Linux runs 7 workbench at the same time. Press crtl + alt + F1 to the first workbench, enter the command here to kill the process, and then press crtl + alt + F7 to return to the original workbench.

Search:
Locate: locates files globally.
Locate not locates the File in the entire File system, but locates the File from a database, which is also the reason for the fast execution of locate.
There is also an updatedb command that updates files in the File system to the database, but updatedb generally runs once a day. As a result, locate cannot find the newly created files.
Remedy:$ sudo updatedbAnd then locate
Find: locate the file within the Directory

$ Find dir # list all files in the directory $ find dir-type f # Only view all files in the directory $ find dir-type d # Only view all directories in the directory $ find dir-type f-exec xxx '{}''; '# xxx can be a variety of system commands to operate on the files found $ find dir-type f-exec grep hello '{}''; '-print # search for the hello string in all the files found and print the file name

Grep:

$ Grep hello # search for the hello string $ grep-n hello # and display the travel number $ grep-ni hello # Show the travel number and ignore the case sensitivity

Ack grep: a command specifically used by programmers to find in code
Move a binary file ~ /Bin:$ rm xxx ~/bin
If a command is too long, you can go ~ /Bin directory$ ln -s xxx yYou can give xxx an alias, y, and then use y, which is equivalent to using xxx.

Network Operation:
Remote Operation:
Programs on your computer need to be placed on the server. You can purchase a VPS server for $10 every month and install the ubuntu server System on the server.
Ssh: it can be considered as a protocol for interconnection between two machines on the Internet. The server needs to open port 22, just as the http protocol requires port 80. In addition to port 22, ssh software must be installed on the server and client.
Both ubuntu desktop and ubuntu server are installed by default.
When buying a server, you will be given an ip address, which can be bound with a domain name.
On the desktop, you can connect to the server as follows:$ Username @ domain name or ip address on the ssh serverAfter entering the password, you can operate on the server.
Ctrl + d can exit the server.
It is annoying to enter the password each time. You can enter the password locally.$ ssh-keygenThen, the Public Key (id_rsa.pub) and private key (id_rsa) can be obtained under. ssh ). Still running under. ssh$ Username @ domain name or ip address on the ssh-copy-id Server. Do not enter the password in the future.
Tmux is a good remote operation that prevents network disconnection and misoperations from Interrupting Communication, and data is not stored.
Data transmission:
Rsync: used for local and remote data synchronization. Rsync can be used if ssh is used.
Upload and use:

$ Rsync-r user name @ domain name or ip address on the local directory server: path on the server

You can upload the local directory to the server path. Note that the local directory cannot be followed/
DownloadYou only need to switch the positions of the above two parameters.
How to synchronize locally added files:

$ Rsync-av mydir/username @ domain name or ip address on the server: path on the server/mydir/

Here, the v parameter is used to display the execution process. The a parameter is used to retain more complete file information.
How to synchronize local added and deleted files:

$ Rsync-av -- delete mydir/username @ domain name or ip address on the server: path on the server/mydir/

To prevent accidental deletion of some files, run the following command first:

$ Rsync-av -- delete mydir/username @ domain name or ip address on the server: path/mydir/-- dry-run on the server

First, only the information is reported, and then the real synchronization operation is performed.

Software installation:
Manual installation:
Decompress the compiled code:
Put the obtained directory in a hidden directory.

Echo $ PATH # You can view the environment variable PATH. Its values are a series of directories separated.

You only need to put the executable file in any directory under PATH to become a system executable command.
You can also create a link instead of moving the executable program itself:$ Ln-s: original executable program target location and name
Download the source code, compile and install it by yourself:
Decompress and switch to the source code directory.

./configuremakesudo make install

Deb package: debian package
Manual installation: the installation dependency will cause inconvenience to the installation process. When there are many installed software, the installation will forget where the files are installed, which makes it a nightmare to uninstall the software.
Deb package = program itself + configuration file + installation location + dependency
HAPPYCASTS 14th explains how to pack a program from the source code into a deb package
Install the deb package of a program: $ sudo dpkg-I deb package

$ Dpkg-l | grep chrome # Check all installed chrome deb packages $ dpkg-L Package Names # Check which files are installed in the package $ dpkg-S file name # Check which one file comes from package

Install from apt-get Repository:
Dpkg is encapsulated in apt-get
Open-source software is generally stored on github or the Free Software Foundation in the form of source code packages. ubuntu regularly creates these source code packages into deb packages, build a software repository apt repo On the ubuntu server and upload the deb package to the software repository.
Installing software in ubuntu is very convenient,$ Apt-get install software nameYou can install it.
Uninstall software:$ Sudo apt-get remove software name
Delete the configuration file together:$ Sudo apt-get purge software name
When you do not know the exact package name, you can use:$ Apt-cache search looks like a software name | less
Apt-get will automatically help install dependent files

Script Programming Skills:
Specify the Parser:
Bash is generally used as the parser, so you must add the following in the first line :#! /Usr/bin/env bash indicates using bash to parse the following statement
But not only can bash be parsed, but python ruby and so on can all parse scripts #! /Usr/bin/env python indicates using python to parse
Statement is a command:
A command in a command line is called a statement in a script.
Commands can be directly listed in the script, or packaged into a function. Call the function name to execute the command:
say_hello(){ echo "hello" }Then, call say_hello to call the echo "hello" command.
The command is sensitive to spaces, so the script statement is sensitive to space exceptions.
Location parameters:
You can also enter parameters when the script is running. In the script, the $ symbol $ # is used to indicate the number of parameters. $0 indicates the script file name \ $1-\ $ n.
The script is not executed in the current shell:
The script is not executed in the current shell, but a new shell is opened and executed in it.
Execute the script in the current shell and use source xx. sh
Loop Control:

Cd $ 1for file in 'LS' do *** Command done

Export the exported command output in the scriptpwd
Remote execution:
Write in the script:

$ Ssh-t remote username @ ip or domain name 'script or command to be executed'

Confirm execution:

Echo-n "Want to continue? (Y/n) "read AAAif [" $ {AAA:-y} "=" y "]; then # Call the else echo Nothing done, bye. fi function.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

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.