Linux Common commands 2 (remote file download + View file contents)

Source: Internet
Author: User
Tags file copy ftp client pscp scp command

One, the remote file download two ways: FTP command + SCP command FTP command:

Server if FTP server is installed, another Linux can use the FTP client program for remote copy of the file to read the download and write upload.

1. Connect to the FTP server
Format: FTP [hostname| ip-address]
A) under Linux command line input: FTP 192.168.26.66
b) The server asks your user name and password, enter the user name and the corresponding password, respectively, to be certified.

2. Download the file

The download file usually uses the get and mget two commands.
a) Get
Format: Get [Remote-file] [Local-file]
Transfer files from the remote host to the local host.
To get E:\rose\1.bmp on the server,
Ftp> get/rose/1.bmp 1.bmp (return)

b) mget
Format: mget [Remote-files]
Receives a batch of files from the remote host to the local host.
To get all the files under E:\rose\ on the server,
Ftp> Cd/rose
Ftp> mget * * (carriage return)

Note: The files are downloaded to the current directory of the Linux host. For example, the FTP command that runs under/root/yint, the files are downloaded to/root/yint.

3. Uploading Files

a) put
Format: Put Local-file [Remote-file]
Transfers a local file to the remote host.
If you want to transfer the local 1.bmp to the remote host E:\rose, and renamed to 333.bmp
Ftp> put 1.bmp/rose/333.bmp (carriage return)

b) mput
Format: Mput local-files
Transfers a batch of files from the local host to the remote host.
If you want to upload all BMP files in the local current directory to the server E:\rose
Ftp> cd/rose (carriage return)
Ftp> mput *.bmp (return)
Note: The upload file is from the current directory of the host. For example, the FTP command running under/root/test will only be uploaded to the server e:\rose under/root/test file Linux.

4. Disconnect the connection
Bye: Interrupts the connection to the server.
Ftp> Bye (carriage return)

SCP Command:

SCP is a secure file copy, SSH-based login. Suppose you want to copy a file named A.tar.tz under the local computer/home to/home/tmp on the remote server 192.168.0.2. And your account name is root on the remote server. You can use this command:
Scp/home/a.tar.tz [email protected]:/home/tmp/

If you copy the file from the remote machine to the current directory of the machine, use this command:
SCP [Email Protected]:/home/a.tar.tz
Copy files from the entire directory of the remote machine
scp-r [email protected]:/home/*./

download to Windows platform:

If you are downloading to the Windows platform using SCP, there are two ways to do this:

1. WINSCP tool, a graphical tool

2. Putty (PSCP)

The command is as follows:

Download:

   pscp [email protected]:/etc/hosts c:\temp\example-hosts.txt

Upload:

   pscp c:\documents\foo.txt [email protected]:/tmp/foo

In addition, if you use Xshell, you can also use the SZ and RZ commands to upload and download.

Second, view the file Contents command

Cat starts displaying content from the first line and outputs all content

The TAC displays the contents in reverse from the last line and outputs all the content

More according to the window size, one page of the actual file content

Less is similar to more, but its advantages can be a page forward, and the ability to search for characters

Head only shows the first few lines

Tail show only the last few lines

NL similar to cat-n, output line number when displayed

Tailf similar to Tail–f

1.cat and TAC

The function of cat is to output the contents of the file continuously on the screen from the first line. However, cat is not commonly used, because when a file is large, the number of rows is too high, and the screen cannot be fully allowed, only a subset of the content is visible.

Cat syntax: Cat [-n] File name (-N: Output with line number when displayed)

The function of the TAC is to output the content data to the screen backwards from the last line. We can find that the TAC is actually cat in turn written. This command is also not used.

TAC Syntax: TAC file name.

2.more and less (common)

The more function is to start the file from the first line, according to the Output window size, the appropriate output file content. When a page cannot be fully output, you can use "enter" to turn down the line, with the "SPACEBAR" to page down. To exit the view page, press the "Q" key. In addition, more can be combined with the pipe symbol "|" (pipe), for example: Ls-al | More

More syntax: more file names

Enter down n rows, need to be defined, default to 1 rows;

Ctrl F scrolls down one screen;

The space bar scrolls down one screen;

Ctrl-B returns to the previous screen;

= Output the line number of the current line;

: F output File name and line number of the current line;

V Call VI Editor;

! command to invoke the shell and execute the command;

Q Exit More

Less has the same function as more, but using more can not page forward, only backward.

Less can use the "PageUp" and "PageDown" keys to turn the front and back pages, which makes it easier to look.

Less syntax: less file name

Less has a feature that you can search for in the file you want, assuming you want to find in the passwd file there is no WebLogic string, then you can do this:

[email protected] etc]# less passwd

Then enter:

/weblogic

Enter

At this point, if there is a WebLogic string, Linux displays the character in a highlighted manner.

To exit the view page, press the "Q" key.

3.head and tail

Head and tail are typically used in cases where only the first few lines or the last few lines of the file need to be read. The head function is to display the first few lines of the file

Head syntax: Head [n number] file name (numbers show rows)

Tail functions just as opposed to head, showing only the last few lines of content

Tail Syntax: tail [-N number] file name

4.nl

The function of NL is the same as cat-n, which outputs the entire contents from the first line and displays the line number.

NL syntax: NL file name

5.tailf

The TAILF command is almost identical to the tail-f and should be more closely similar to tail--follow=name. When the file is renamed it can continue tracking, especially for log file tracking (follow the growth of a log files).  Unlike Tail-f, if the file does not grow, it will not go to access the disk file (it is similar to tail-f but does not access the file when it's not growing. This have the side effect of not updating the access time for the file, so a filesystem flush does not occur periodically When no log activity is happening.). TAILF is especially suitable for tracking log files on portable machines because it saves power because it reduces disk access (TAILF is extremely useful for monitoring log files on a laptop when logging was in Frequent and the user desires the hard disk spin down to conserve battery life.). The TAILF command is not a script, but a binary execution file compiled with C code, and some Linux installations do not have this command, this article provides a way to compile and install the TAILF command.

1. Tailf always reads from the beginning of the file at 1.1 points, while Tail-f starts at the end of the file.

2. When the Tailf check file grows, it uses the file name, which is called with the stat system, while TAIL-F uses the open file descriptor; Note: Tail can also be similar to the effect of tracking file names, but tail always uses fstat system calls. Instead of a stat system call, the result is: By default, when tail files are secretly deleted, tail is not known, and TAILF is aware.

Common parameters

Format: Tailf logfile

The dynamic trace log file logfile, initially prints the last 10 lines of the file.

Linux Common commands 2 (remote file download + View file contents)

Related Article

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.