Common Linux commands

Source: Internet
Author: User
Tags scp command secure copy
Document directory
  • 1. wget
  • 2. SCP (mutual copy between servers)
  • 3. PS aux
  • 4. CP: Copy directory
  • 5. MV: Change the directory or file name
  • 6. Find: Find a file containing a keyword in a directory.
  • 7. RM: delete a directory
  • 8. Tail: view the last lines of the file.
  • 9. RZ and Sz: File Transfer between Linux and Windows
  • 10. MySQL: connect to the MySQL database
  • 11. crontab: scheduled execution of scheduled tasks in Linux
  • 12. Code indent settings in VIM
  • 13. Tar: extract and compress
  • 14. php: Execute the PHP File
  • 15. ">" and ">"
  • 16. Curl
1. wget

Wget is a free tool for automatically downloading files from the network. It supports downloading through HTTP, https, and FTP, and can use HTTP proxy.

Command Format: wget [Options] [url]

2. SCP (mutual copy between servers)

The SCP command is the most convenient and useful command in SSH. Imagine directly transferring files between two servers. Simply use SCP to solve this problem.

You can run it as root on a server.SCP servername:/home/FTP/pub/file1 ./In this way, the file/home/FTP/pub/file1 on the other server is directly transferred to the current directory of the machine.

You can also useSCP/tmp/file2 servername:/bootSend the/tmp/file2 file on the local machine to the/boot directory of another machine. The entire transfer process is still encrypted using SSH.

SCP isSecure copyIs used to copy remote files. Data transmission uses SSH and uses the same authentication method as SSH to provide the same security guarantee. Unlike RCP, SCP requires you to enter a password or password for verification.

The general format can be abbreviated,Target Location of SCP-r source file: Copy the source file to the target location. The-r option is used when copying directories.

(1) SCP-r live/zhaolincheung@db-feiyan.db01.baidu.com:/home/bugfixpcui/APP/search/Video/

Transfer the local live directory to the/home/bugfixpcui/APP/search/Video/directory of another zhaolincheung@db-feiyan.db01.baidu.com machine.

(2) SCP-r Ala-Common/zhaolincheung@db-feiyan.db01.baidu.com:/home/bugfixpcui/APP/search/Video/

Send the local Ala-common directory to the/home/bugfixpcui/APP/search/Video/directory on another zhaolincheung@db-feiyan.db01.baidu.com machine.

(3) SCP zhaolincheung@192.168.11.22:/home/ABC/file1.php ./

Copy the/home/ABC/file1.php file on the remote machine 192.168.11.22 to the current directory. After the command is executed, enter the password of the user zhaolinchueng.

3. PS aux

Common ps command parameter process view command, you need to master some of the most common command parameters. The three most common parameters are u, A, and X.
A displays all processes on the terminal, including those of other users. X shows the process without any control terminal. U user name.

4. CP: Copy directory

CP-r/usr/Xu/usr/Liu/copy all the files and Their subdirectories in the/usr/Xu directory to the/usr/Liu directory.

5. MV: Change the directory or file name

MV/home/ABC/home/ABCD

6. Find: Find a file containing a keyword in a directory.

Find.-Name '*. *' | grep "*.*"

7. RM: delete a directory

Rm-RF directory name

8. Tail: view the last lines of the file.

Tail file name: indicates the last 10 lines of the file.

There is a very useful parameter "-F". When this parameter is used, tail will not return the end signal unless we interrupt it on our own. On the contrary, it will wait for a while until it finds that the data is added to a new row after it is read for the last time, that is, it will track all updates of this file in real time at a certain time. Eg: tail-F File

Another parameter of tail is-N, which is used to view the last n rows. For example, tail-N 100 file indicates the last 100 rows of the file.

9. RZ and Sz: File Transfer between Linux and Windows

RZ-be: Upload windows objects to Linux. Running this command will pop up a file selection window, from the local selection file upload to the server.

SZ: download files from Linux to Windows. The file will be downloaded to the default download directory in secure CRT. For example:

SZ-be ui.tar.gz: Download ui.tar.gz to your local machine.

Note:

Configure the upload/download Directory: select a "session tag"> "session options"> "terminal"> "x/y/zmodem ", then you will see the upload and download directories, which can be set here.

10. MySQL: connect to the MySQL database

(1) The command format is as follows:Mysql-hhost-Uusername-Ppassword-pport

MySQL must have executable files in the usr/local/bin directory. Otherwise, you must use the MySQL command in the absolute path of the MySQL installation directory.

Use the absolute path:/MySQL installation directory/MySQL-hhost-uusername-ppassword-pport

For example:/usr/local/webserver/MySQL/bin/MySQL-hhost-uusername-ppassword-pport

(2) An example is provided:/usr/local/webserver/MySQL/bin/MySQL-h192.168.112.123-usean-prewq1234-p3306 -- default-character-set = utf8

MySQL database with host 192.168.112.123, username Sean, password rewq1234, and port number 3306. The default character set is UTF-8.

(3) After connecting to MySQL, you can use the following simple command to view the contained database, the table and table structure in the database.

Display All database commands: Show databases;
Use a database: use database;
Display the table structure in a database: Show create table table name;

11. crontab: scheduled execution of scheduled tasks in Linux

Run crontab-e.

The scheduled task file of the current user will be opened. You can enter the command to be executed here.

Give a reference link: http://blog.csdn.net/21aspnet/article/details/6798179

For example:

(1) first run crontab-e

(2) Enter: 0 5 *** CD/home/seanzhao; SH dingding_insert_db.sh

Run the dingding_insert_db.sh script in the/home/seanzhao directory at 05:00 every day.

When using crontab, you have encountered a problem: When writing the following code, the first line of the command can be executed, but the second line of the command is not executed, that is, the test1.php file is executed, however, the test2.php file is not executed.
0 5 ***/usr/local/PHP/bin/PHP/data/analys/PHP/test1.php
30 5 ***/usr/local/PHP/bin/PHP/data/analys/hive/test2.php
Later, change the second line to the following, that is, use CD to enter the directory of the file to be executed, so that both test1.php and test2.php are executed.
0 5 ***/usr/local/PHP/bin/PHP/data/analys/PHP/test1.php
30 5 * CD/data/analys/hive;/usr/local/PHP/bin/PHP test2.php

12. Code indent settings in VIM

The Code generally uses four indentations per level. You can enter the following in the vim command line:Set tabstop = 4;Set expandtabThese two commands are implemented.

In Linux, the default indentation of the tab is a tab (with 8 spaces ).Set tabstop = 4We set the tab to 4 spaces.

PassSet expandtabCommand to replace indentation with spaces when encountering a tab key.Set noexpandtabIndicates canceling the setting. For example, if you press a tab to indent a tab (equivalent to the length of four spaces) and set expandtab, when you press the tab key, it is Indented by four spaces instead of a tab, the space is also rolled back when you press the rollback key. That is to say: if the expandtab is not set, the tab is indented. If the expandtab is set, the Indented space is used instead of the tab.

Set shiftwidth = N: After you select a text segment from SHIFT + "V", Press SHIFT + "<", Shift + ">" to indent n spaces.

Give a reference link: http://www.it300.com/article-15251.html

13. Tar: extract and compress

Package (the compressed folder is abc.tar.gz: tar-zcvf abc.tar.gz *

Extract A directory to the current location: tar-zxvf abc.tar.gz

Difference: packaging is ZCVF (C indicatesCReate), decompress it to ZXVF (where X is EXTract ).

14. php: Execute the PHP File

Eg:/usr/local/PHP/bin/PHP/home/zhaolincheung/test. php: run the test. php file in the/home/zhaolincheung/directory.

15. ">" and ">"

>>: Append text; eg: tail-F file1> result.txt: add the content of file1to result.txt.

>: Indicates to overwrite the text. eg: tail-F file1> result.txt first clears the content in result.txt before writing the content to result.txt.

16. Curl

Curl URL: the parsed content of the URL is returned;

Eg: curl www.baidu.com: the source code of the www.baidu.com page is output to the standard screen.

Curl can also perform hosts ing to complete the/etc/hosts file function.

If we have the following requirement: Access http://bj.ganji.com/jobfairs/jobfairs_im_port.php via HTTP? Action = getims to obtain the returned data. However, our environment and bj.ganji.com are not in the same CIDR block. Therefore, we need to map a Domain Name and IP address, as shown below:

10.3.20.201 http://bj.ganji.com

However, if we do not want to change the/etc/hosts file, we can use the curl command in Linux to bind and obtain the file. You can perform hosts ing as follows:

Curl-h "Host: bj.ganji.com" http: // 10.3.20.201/jobfairs/jobfairs_im_port.php? Action = getims

So when users access http://bj.ganji.com/jobfairs/jobfairs_im_port.php? Action = getims is actually accessing http: // 10.3.20.201/jobfairs/jobfairs_im_port.php? Action = getims, and the returned data is output.

Reference: http://blog.csdn.net/gggxin/article/details/4394978

PHP also has curl extension module to achieve the same function, refer to: http://www.gosoa.com.cn/php-curl-curlopt_httpheader%E8% AE %BE%E7%BD%AEhost


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.