Some Linux commands

Source: Internet
Author: User
Tags file copy ftp commands ftp site terminates ftp client file transfer protocol ftp transfer

The main advantage of computer network is that it can realize the sharing of resources and information, and the user can access information remotely. Linux provides a powerful set of network commands to serve users, which can help users log on to remote computers, transfer files, and execute remote commands.

This chapter describes the following common commands for network operations:

FTP Transfer files

Telnet Log on to the remote computer

R-Using various remote commands

Netstat view the status of your network

nslookup querying the corresponding domain name and IP address

Finger query A user's information

Ping queries whether a machine is working

Remote file transfer using the FTP command

The FTP command is the user interface of the standard file transfer protocol. FTP is a simple and effective way to transfer files between computers on a TCP/IP network. It allows users to transfer ASCII files and binaries.

During an FTP session, users can connect to another computer by using the FTP client program. From there, users can move up and down the directory, list directory contents, copy files from the remote machine to the local machine, and transfer the files from the local machine to the remote system. It is important to note that if the user does not have access to that file, they cannot obtain the file from the remote system or transfer the file to the remote system.

In order to use FTP to transfer files, the user must know the valid user name and password on the remote computer. This combination of username/password is used to confirm the FTP session and to determine what access the user can make to the file to be transferred. In addition, the user obviously needs to know the name or IP address of the computer on which the FTP session is made.

The function of the FTP command is to transfer files between the local machine and the remote machine. The general format of the command is as follows:

$ FTP host name/IP

WHERE "hostname/IP" is the host name or IP address of the remote machine you want to connect to. On the command line, the hostname is an option, and if you specify a host name, FTP will attempt to connect to the remote machine's FTP service, and if you do not specify a hostname, FTP will give you a prompt waiting for the user to enter the command:

$ ftp

FTP >

At this point, after entering the open command with the hostname or IP address at the ftp> prompt, you will attempt to connect to the specified host.

Whichever method is used, if the connection succeeds, you need to log on to the remote machine. If the user has an account on the remote machine, they can use the account via FTP and need to provide a password. The read and write permissions of the user account on the remote machine determine what files the user can download on the remote machine and in which directory the uploaded files are placed.

Many FTP sites have special accounts that you can use if you do not have a dedicated login account for the remote machine. The login name for this account is anonymous (also known as anonymous FTP), and when you use this account, you need to enter an email address as your password.

If the remote system provides an anonymous FTP service, users can log in to a special directory for public use by using this service. Typically two directories are available: Pub directory and incoming directory. The pub directory contains all the files that the site uses for public use, and the incoming directory holds files uploaded to that site.

Once the user has successfully logged on to the remote site using FTP, a "ftp>" prompt will be given. You can now freely use the commands provided by FTP, you can use the help command to get a list of available commands, or you can specify a specific command name after the help command to get a description of this command.

The most commonly used commands are:

LS lists the current directory of the remote machine

CD changes the working directory on the remote machine

LCD changes working directory on local Machine

ASCII set file transfer mode to ASCII mode

Binary set file transfer mode to binary

Close terminates the current FTP session

Hash displays a # number each time the data in the data buffer is transferred

Get (Mget) transfers the specified file from the remote machine to the local machine

Put (mput) transfers the specified file from the local machine to the remote machine

Open Connect Remote FTP site

Quit disconnecting from the remote machine and exiting FTP

? Show local Help information

! Go to the shell

The following is a brief introduction to common FTP commands.

Start an FTP session

The Open command opens a session with a remote host. The general format of the command is:

Open Host name/IP

If you are connecting to more than one site during an FTP session, usually only FTP commands with no parameters are used. If you want to connect to only one computer during the session, specify the remote host name or IP address on the command line as the parameter for the FTP command.

Terminating an FTP session

The close, disconnect, quit, and bye commands are used to terminate a session with a remote machine. The close and Disronnect commands close the connection to the remote machine, but the user is left in the FTP program on the local computer. The Quit and bye commands both shut down the user's connection to the remote machine, and then exit the FTP program on the user's computer.

Change Directory

The CD [directory] command is used to change the directory on the remote machine during an FTP session, and the LCD command changes the local directory so that the user can specify where to find or place the local file.

Remote directory List

The LS command lists the contents of the remote directory as if it were using the LS command in an interactive shell. The general format of the LS command is:

ls [directory] [local file]

If a directory is specified as a parameter, LS lists the contents of the directory. If you give the name of a local file, the directory list is placed in the file you specified on the local machine.

Getting files from a remote system

The Get and Mget commands are used to obtain files from the remote machine. The general format of the GET command is:

Get file name

You can also give the local file name, which is the file name of the file you want to get when it is created on your local machine. If you do not give a local file name, then use the original name of the remote file.

The mget command gets more than one remote file at a time. The general format of the Mget command is:

Mget File Name list

Use a space-delimited list of file names with wildcards or wildcard characters to specify the files to get, and each file in it requires the user to confirm the transfer.

Sending files to a remote system

The put and Mput commands are used to send files to the remote machine. The general format of the put command is:

Put file name

The mput command sends multiple local files at once, and the general format of the Mput command is:

Mput File Name list

Specify the file to send by using a space-delimited list of file names with wildcards or wildcard characters. For each of these files, the user is asked to confirm that they are sent.

Changing the file transfer mode

By default, FTP transfers files in ASCII mode, and users can specify other modes. The function of the ASCII and Brinary commands is to set the mode of transmission. Transferring files in ASCII mode is good for plain text, but in order to avoid the destruction of binary files, users can transfer files in binary mode.

Check transport status

When transferring large files, you may find it useful to have FTP provide feedback about the transport situation. The hash command causes FTP to print a # character on the screen after each transfer of data in the data buffer. This command can be used when sending and receiving files.

Local commands in FTP

When you use FTP, the character "!" Used to route a command to the command shell on the local machine. If the user is in an FTP session, it is useful to have the shell do something. For example, a user would create a directory to hold the received file. If you enter!mkdir New_dir, then Linux creates a directory named New_dir in the user's current local directory.

The typical dialog process for downloading a binary data file from a remote machine Grunthos is as follows:

$ ftp Grunthos

Connected to Grunthos

Grunthos FTP Server

Name (GRUNTHOS:PC): Anonymous

33l Guest Login OK, send your complete e-mail address as password.

Password:

Guest 1ogin OK, access restrictions apply.

Remote system type is UNIX.

FTP > CD Pub

CWD command successful.

FTP > ls

PORT command successful.

L50 opening ASCII mode data connection for/bin/1s.

Total LL4

Rog1

Rog2

226 Transfer Comp1ete.

FTP > Binary

The type set to I.

FTP > Hash

Hash mark Printing on (1024x768 bytes/hash mark).

FTP > Get ROG1

PORT command SUCCESSFU1.

Opening BINARY mode data connection for ROGL (l4684 bytes).

# # # # # # # # # # # # #

226 Transfer complete.

14684 bytes received in 0.0473 secs (3e + kbytes/sec)

FTP > Quit

22l Goodbye.

To access a remote computer by using the Telnet command

The user uses the Telnet command to telnet. This command allows the user to communicate with the remote computer using the Telnet protocol, and the user can log on to the remote computer over the network as if they were logged on to the local machine to execute the command.

In order to log on to the remote computer via Telnet, you must know the valid user name and password on the remote machine. While some systems do provide login functionality for remote users, there are few features that can be used in this case, for security reasons, to restrict the guest's operational rights. When remote users are allowed to log on, the system typically places these users in a restricted shell to prevent the system from being compromised by malicious or careless users.

Users can also use Telnet to log on to their computer from a remote site, check e-mail, edit files, and run programs as if they were logged on locally. However, the user can only use the terminal-based environment rather than the X-wndows environment, Telnet only provides terminal emulation for the normal terminal, and does not support graphical environments such as X-Wndow.

The general form of the Telnet command is:

Telnet host name/IP

WHERE "hostname/IP" is the host name or IP address of the remote machine you want to connect to. If this command succeeds, it will get the login: Prompt from the remote machine.

The process of logging in using the Telnet command is as follows:

$ telnet host name/IP

Start the Telnet session.

Once Telnet is successfully connected to the remote system, the login information is displayed and the user is prompted to lose the user name and password. If the user name and password are entered correctly, they will be able to log on successfully and work on the remote system.

You can enter many commands after the Telnet prompt to control the Telnet session, which is described in detail in the Telnet online Help manual.

The following is an example of a Telnet session on a Linux computer:

$ telnet Server. Somewhere. Com

Trying 127.0.0.1 ...

Connected to serve. Somewhere. Com.

Escape character is '?] '.

"Turbolinux Release 4. 0 (Colgate)

Kernel 2.0.18 on an I486

Login:bubba

Password

Last Login:mon Nov L5 20:50:43 for localhost

Linux 2. 0.6. (Posix).

Server: ~$

Server: ~$ Logout

Connection Closed by foreign host

$

After the user finishes the remote session, be sure to use the logout command to exit the remote system. Then Telnet reports that the remote session was shut down and returned to the user's local machine at the shell prompt.

R-Series Commands

In addition to FTP and Telnet, you can use the R-series commands to access remote computers and Exchange files on the network.

Using the R-Series commands requires special attention, because if the user is not careful, it can cause a serious security breach. After the user issues an R-series command, the remote system checks the file named/etc/hosts.equiv to see if the user's host is listed in the file. If it does not find the user's host, check the remote machine with the same name as the user's home directory named. Rhosts file to see if the host of the user is included. If the user's host is included in any of these two files, the user does not have to provide a password to execute the R-series command.

Although it may be convenient for users to not have to type a password every time they visit a remote machine, it can also pose a serious security issue. We recommend that users carefully consider the security implications of the R-command before establishing the/ETC/HOSTS.EQUIV and. rhosts files.

Rlogin command

Rlogin is an abbreviation for "Remote login" (telnet). This command is similar to the Telnet command, allowing the user to start an interactive command session on the remote system. The general format of the rlogin is:

rlogin [ -8EKLDX] [-e char] [-K realm] [-l username] Host

Generally the most commonly used formats are:

Rlogin Host

The meanings of the options in this command are:

8 This option always allows 8-bit input data channels. This option allows the sending of formatted ANSI characters and other special codes. If this option is not used, the parity bit is removed unless the end and startup characters of the remote are not OR.

-E stops taking any characters as escape characters. When used with the-8 option, it provides a full transparent connection.

-K turns off all Kerberos acknowledgments. Use this option only if you are connected to a host that uses the Kerberos acknowledgment protocol.

-L allows Rlogin sessions to run in Litout mode. For more information, please refer to the TTY online help.

-D open socket debug for TCP sockets that communicates with the remote host. For more information, please consult the online Help for setsockopt.

-E Sets the escape character for the rlogin session, the default escape character is "~", and the user can specify either a literal character or an octal number in \nnn form.

-K requests that rlogin obtain a Kerberos license for the remote host within the specified zone, rather than obtaining a Kerberos license for a remote host within the remote host zone determined by Krb_realmofhost (3).

-X turns on DES encryption for all data transmitted through the Rlogin session. This affects response time and CPU utilization, but it can improve security.

RSH command

RSH is a "remote shell" abbreviation. This command launches a shell on the specified remote host and executes the command specified by the user on the rsh command line. If the user does not give the command to execute, RSH uses the rlogin command to log the user on to the remote machine.

The general format of the RSH command is:

RSH [-kdnx] [-K realm] [-l username] host [command]

The usual formats are:

RSH host [command]

command can be any Linux command from the shell prompt key person.

The options in the RSH command have the following meanings:

-K Close all Kerbero confirmations. This option is only used when connecting to a host that is confirmed with Kerbero.

-D open socket debug for TCP sockets that communicates with the remote host. To learn more, check out the online Help for setsockopt.

-K requests that rsh obtain a Kerberos license for the remote host within the specified zone, rather than obtaining a Kerberos license for a remote host within the remote host zone determined by Krb_relmofhost (3).

-L By default, the remote user name is the same as the local user name. This option allows you to specify a remote user name, and if a remote user name is specified, the Kerberos acknowledgment is used as in the Rlogin command.

-n redirects the input from the special device/dev/null.

-X turns on DES encryption for all transmitted data. This affects response time and CPU utilization, but it can improve security.

Linux puts the standard input into the RSH command and copies it to the standard input of the command to be executed remotely. It copies the standard output of the remote command to the standard output of rsh. It also copies the remote standard error to the local standard error file. Any exit, abort, and interrupt signals are sent to the remote command. When the remote command terminates, RSH is terminated.

rcp command

RCP stands for "Remote file copy". This command is used to copy files between computers.

The RCP command has two forms. The first format is used for file-to-file copies, and the second format is used to copy files or directories to another directory. The general format of the RCP command is:

rcp [-px] [-K realm] File1 file2

rcp [-PX] [-R] [-K realm] File directory

Each file or directory parameter can be either a remote file name or a local file name. The remote file name has the following form: [E-mail Protected]:path, where rname is the remote user name, Rhost is the remote computer name, path is the pathname of this file.

The various options for the RCP command have the following meanings:

-R recursively copies all the contents of the source directory to the destination directory. To use this option, the destination must be a directory.

-P attempts to preserve the modified time and mode of the source file, ignoring umask.

-K requests that RCP obtain a Kerberos license for the remote host within the specified zone, rather than obtaining a Kerberos license for a remote host within the remote host zone determined by Krb_relmofhost (3).

-X turns on DES encryption for all transmitted data. This affects response time and CPU utilization, but it can improve security.

If the path specified in the file name is not the full pathname, then this path is interpreted as relative to the home directory of the user with the same name on the remote machine. If the remote user name is not given, the current user name is used. If the path on the remote machine contains special shell characters, it needs to be surrounded by a backslash (\), double quotation mark ("), or single quotation mark (') so that all shell metacharacters can be interpreted remotely.

It is important to note that RCP does not prompt for a password, which executes the copy through the RSH command.

Excerpt from "Turbolinux"

Some Linux commands

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.