2. Basic Linux Command Learning 02

Source: Internet
Author: User
Tags delete key

C:\abc\a.txt Windows notation (backslash)
/abc/a.txt Linux notation (slash)
Relative path Expression method
Cat A.txt If you do not add any path description, the default is the file under the current directory
Cat./a.txt explicitly indicates that a.txt is a relative path in the current directory.
Cat.. /a.txt clearly indicates that a.txt in the previous level of the directory, which is also a relative path to the wording
Cat./.. /a.txt clearly indicates that A.txt is in the previous level directory, which is also a way of writing relative paths (as with the previous equivalent)
Cat.. /2/a.txt A.txt in 2 subdirectories of the previous level directory
Absolute path, the absolute path always starts at the root directory

Normal user's home directory is usually under/home/
Root user's home directory in/directory
The common Unix/linux system directory is as follows:
The root directory of the/:unix/linux system, containing all directories and files for the Unix/linux system.
/etc: A configuration file for system devices and management.
/sbin: Store The running program required to start the system.
/bin: This directory contains commonly used command files.
/usr/local: Store the user's post-installation application files.
/root: Super User home directory.
/dev: Interface Device file directory, save the peripheral device code. (The Unix/linux system maps each device to a file, which is the device file.) )
/home: The common user's host directory, which is usually set to a separate partition.
There are up to 4 IDE devices on a PC, either a disk or a CD/DVD device. (PC-mounted hard drives are generally IDE drives: inexpensive, slow to read and write, not hot-swappable)
In Unix/linux, for IDE disks, "HD" is used, and a lowercase letter is used after "HD" to indicate the disk number.
The disk number is followed by a partition number, denoted by an Arabic numeral. The primary partition number is sequentially 1~4, and the logical partition number on the extended partition starts at 5.

SATA and SCSI disks are used in conjunction with the "SD" representation. The name of the common storage device is represented as shown in the table. (The hard drive installed on the server is usually a SCSI drive)

Naming rules for Unix/linux files:
(1) The file name can be up to 256 characters long, can be composed of a~z, A~z, 0~9 、.、-、 _, and other symbols.
(2) file names are case-sensitive.
(3) The file does not have an extension concept.
(4) Use "/" as a delimiter between the root directory and the directory layer.
(5) Support relative path and absolute path.
In the Unix/linux operating system, you must also distinguish between file types, which can be used to determine whether a file belongs to an executable file, a text file, or a data file.
Files can have no extension in the Unix/linux system.
Typically, there are 5 types of files commonly used in Unix/linux systems: Normal files, directory files, device files, pipe files, and linked files.
A.txt,a.txt is the same in Windows
A.txt,a.txt is not the same in Linux
It's not the same in Linux.

Modify access permissions for a file or directory
Method One: Use the chmod command and parameters:
chmod [parameter] file or directory name
chmod o+w a.txt Add Write permission to other users
chmod u-r a.txt permission to be read by the owner
U: The owner of the file or directory, with the maximum read and write access to the file.
G: A group, that is, all users with the same group ID as the file group.
O: Represents another user, usually with browse permission only.
A: Indicates the above so the user.

Law II: How to use numbers:
RWX rwx rwx corresponds to 111 111 111
---------corresponds to 000 000 000


RW-R-----rwx rwx rwxr-x-w---x
110 100 000
6 4 07 7 75 2 1
chmod 640 1chmod 777 1chmod 521 1
For a directory,
If you do not have R permissions, you cannot use the LS command to view the contents of the directory (Read permissions)
If you do not have W permissions, you cannot delete or add files to the directory (write permissions)
If you do not have X permissions, then you cannot use the CD command to enter this directory (Execute permissions)

Modify the owner of a file
Using the Chown user name file or directory name
Example: Chown root a.txt

Modify all groups of files
CHGRP user name file or directory name
Example: Chgrp root a.txt

VI is the command mode by default,
Press I or a in command mode to enter input mode
Press ESC to enter command mode in input mode
In command mode, press: W file name
In command mode, press: Q
VI command is not appended with the file name, the default is to turn on VI, but does not automatically open any files, if you enter a character in VI, then you need to execute the W command, followed by the file name
VI filename If the file exists, then open the file, if the file does not exist, then create the file, then execute the w command, there is no need to write the file name
: Wq Save and exit, cannot be written as: QW
Open a file with VI, after modifying the content, if it is not used: w save, directly with: Q exit will prompt failure.
If you want to not save the exit, then use: q!
As with many graphic-based editors, VI also provides undo functionality, which is necessary for an editor to provide undo functionality.
The user can enter "u" in command mode to undo the last operation.
The insertion mode of VI
A insert text to the right of the cursor position
I insert text at the current cursor position
o Open a new line below the cursor position
o Open a new line above the cursor position
I insert text at the beginning of the cursor
A cursor at the end of the line insert text
Exit VI
ZZ Save exit
: Wq Save Exit
: X Save exit
: w filename saved to the specified file
: Q Exits, if the file is modified but not saved, you will be prompted not to quit
: q! exit, do not save
:! command to temporarily exit VI, execute the corresponding command
VI Removal function
In the vi input mode, the user can use the BACKSPACE (BACKSPACE) to delete the contents of the front of the cursor and delete the current character using the Delete key.
In addition, the VI command mode also provides several keys to delete a character or to delete a whole row.
x Delete the character that the current cursor contains
X Delete one character before cursor
D Remove the character from the beginning of the cursor to the end of the line
DD Delete the line where the cursor is located
DG deletes all characters from the beginning of the cursor to the end of the file
J Merge Two Lines
The line positioning function of VI
Ctrl + F Scrolls forward one screen
Ctrl + B Scrolls backward one screen
G to the beginning of the last line of the file, G must be uppercase
: $ to file last line end
MG to the specified line, M is the target line number,
: Set NU Displays line number (this command is important)
: Set Nonu Displays line numbers (this command is important)
/content Find specified content
VI's text lookup function
/String Lookup specified string
n Looking for the next
n back to the previous one
? Looking for the previous
/^ string to find lines starting with a string
/string $ find lines ending with a string
/a.b find string A to any character B
The text substitution function of VI
R replaces the current cursor character
: R file name loads the contents of another file at the cursor's current location
: Start line number, cutoff line number S/source string/target string/g Replace string within the specified line number range (example shown below)
1,$ s/start/end/g starting from the first line to the end of the file, replace the string start with the end
Set Instructions for VI
: Ignore case when set IC is searched
: Set Noic search without ignoring case
: Set NU Displays line number
: Set Nonu does not display line numbers

Little Practice Steps:

1. Enter root to create a user ABC (Note: User password is required after user creation)
useradd-d/HOME/ABC abc-m-s/bin/bash-s representative Specifies a shell (this bash shell is more comfortable and prettier)
useradd-d/HOME/ABC abc-m-s/bin/sh-s delegate specifies a shell (default sh shell)
2. Exit root, log in to user ABC
3, with VI write a C language Hello World (Note: The file is called A.C if the source code file is c, the extension must be. c)
3, compile this program (compile C language source code file)
Gcc-o a a.c-o A: means to specify that the compiled program is named a. That is, to compile A.C this source file, the compiled executable program is named a
4. Run this program
Linux does not look for executable programs in the current directory by default;
./A explicitly tells the operating system that a is under the current directory.

How do I set syntax highlighting?
The terminal type in SECCURECRT is VT100 or xterm by default, we want to choose Linux. The character set must be UTF8.
How do I set the default VI to show line numbers automatically when it is turned on?
The first step is to go back to the user's home directory of the method CD without adding a carriage return
The second step, go back to the main directory, generate a file called. VIMRC, the filename must be preceded by a.
Step three, enter set Nu in. VIMRC
Fourth step, save exit
Shell a Linux character interface will have many different Shell,shell is the human-computer interaction mode of the character interface
SH is the oldest and most basic Unix shell
If you do not specify a shell when creating a user, the default shell is sh when you log in to this user.
The shell itself is a program, usually in the/bin directory

GCC is the operating system that comes with Linux, because the Linux operating system itself is compiled with GCC.

Windows does not bring GCC, how do you use GCC under Windows systems?
Method one, go directly to the GCC official website to download the installation version;
Method Two, QT will be installed with a GCC version when installing QT, GCC generally in the QT installation directory
Locate the installation path for Gcc.exe under Windows, and then put this path in the Windows System environment variable path, at the end of path, with the installation path of GCC;

How to set up a Linux system to find executable programs in the current directory
1, go back to the user's home directory CD
2. In the user's home directory, open the file. Profile (in Ubuntu System),. Bash_profile (under Redhat, CentOS System)
3, at the end of the. profile file, add a row of export path= $PATH:. Note that this is case sensitive.
4, Save exit
5, execute source. Profile (Redhat System) source. Bahs_profile
Note: All of the above changes are only for a specific user, such as User a modified, but User B will not take effect, such as root modification, then other users will not take effect.

Ifconfig Display Network parameters
Ifconfig–a Displaying network configuration information

Eth0 Network Interface Name
Link EnCap Link Encapsulation protocol
Hwaddr the MAC address of the network interface
Inet Addrip Address
Bcast Broadcast Address
Mask Subnet Mask
Up network interface Status ID, up is enabled, down is disabled
Broadcast broadcast identity, identifying whether the network interface supports broadcast
Running transport identity, which identifies whether the network interface has started transmitting packet data
Multicast multicast identity to identify whether the network interface supports multicasting
MTU,METRICMTU: Maximum transmission Unit, unit: byte. Metric: metric, used for RIP to establish network routing
Rx bytes receive Data byte statistics
TX bytes Send data byte statistics
Route Network Routing settings
Route can add, modify, and display routing information
Netstat This command monitors network status, including interface settings, IP routing, statistics of various network protocols
Ping test Remote host connectivity
Ping sends a ECHO_REQUEST request to the remote host via the ICMP protocol, expecting the host to reply to the echo_reply message
The ping command checks to see if a TCP/IP connection is established with the remote host.

General server will be placed in the computer room, many times we usually through a certain software to connect to the server remotely, and then go to work.

How do I transfer the ABC.C file on the server to Windows?
1. Right-click on the CRT Link dialog box to open the Select connection sftp session
2, in the SFTP to enter the remote path and the local path, as follows:
First, use the command pwd to view the directory of Linux that is connected remotely
CD 1 Enter the 1 directory of Linux that is connected remotely
LCD \test into the local window directory
3, get ABC.C from the remote directory to get the file abc.c, put into the local directory test
How to transfer the AAA.C file under Windows to a Linux server?
1. Right-click on the CRT Link dialog box to open the Select connection sftp session
2. Using the command sftp> put AAA.C
3. Use cat AAA.C under CRT to view AAA.C

How to use the http.tar.gz source code file under Windows?
Step 0: Right-click on the Link dialog box on the CRT to open the Select connection sftp session
Step one: Upload the Windows file to Linux first
Put http.tar.gz
Step two: Back to the original command line interface decompression
Gzip-d http.tar.gz (get. tar file)
TAR-XVF Http.tar (get HTTP directory)
Step three: Enter the HTTP directory
Step four: Compile the source code
Step five; switch to the root user
Step Six: Start the program with the root user
./myhttp Start

When seen as follows:
Listen success
Myhttp begin
The representative program started successfully (although not written, but we will successfully deploy someone else to write the program Ah!). )

Open Windows Explorer
can be searched Oh!
Then right-click on the Link dialog box on the CRT to open the clone in the new window
Go to [email protected]:~/desktop/haha/01/http$ directory, edit a a1.c file (content is Hello World)
After compiling with the Gcc-o a.cgi a1.c
Run results using./a.cgi
Again in Windows Explorer enter Enter to get the Hello World displayed on the page
But, it's a little ugly, so we can add some stuff.

#include <stdio.h>
int main ()
printf ("printf ("printf ("<font color=red size=48>");
printf ("Hello aheng\n");
printf ("</font>");
printf ("return 0;


2. Basic Linux Command Learning 02

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.