Linux basic Commands (2)

Source: Internet
Author: User
Tags bz2 convert domain name to ip address domain name server file permissions

A grep find cut


1.grep searching for a string

-N Display Line number
-R Recursive Sub-directory

"^string" line starting with string
Line with "string$" ending in string
"^string$" searches only string rows that do not contain other characters

* All files in the current directory

Common usage:
grep "string" *-n-r
grep "string" *-nr

2.find looking for a file

Find-name file name (starting with the current directory, looking for the specified file in all subdirectories)

For example:
Find-name file.c
Find-name *file*

3.cut splitting a substring

-d Specifies the separator
-f Specifies the desired area

Cut-d ":"-F 1
Cut-d ""-F 1,2,4


Two cat, head, tail, more, less

Function: View the contents of a file

1.cat

Cat File = Displays the contents of the file to the terminal

2.head

Head file = 10 lines from the beginning of the file header
Head-n File = Displays n rows from the beginning of the header

2.tail

Tail File = + Displays the last 10 lines of the files
Tail-n File = + Displays the last n rows of the files

Question: How do I display a specified line in a file?
Answer: Head-line File | Tail-1

3.more,less
Local display, display down with the ENTER key

Problem: Extracting user information from/etc/passwd file, outputting user information to terminal, Name:uid:gid?
head-34/etc/passwd | Tail-1 |cut-d ":"-F 1,3,4

Question: How do I determine the line number where the user is located?
cat/etc/passwd | Cut-d ":"-F 1 (extract user name) | grep "^linux$"-n | Cut-d ":"-F 1

Three-pack compression for files or directories

Gzip and bzip2 and XZ to file compression
gzip File = file.gz
bzip2 file = file.bz2
XZ file = File.xz

Gunzip bunzip2 UNXZ Unzip the file

Note: Only for file operations

--------------------------------------------------
Working with Directories

Command: Tar

C Create
X release
Z GZ format
J bz2 Format
J XZ Format
V Display procedure
F Specify the file name

1. Package the catalog without compression
TAR-CVF Dir.tar dir

2. Package and compress the catalog
TAR-CZVF dir.tar.gz dir
TAR-CJVF dir.tar.bz2 dir
TAR-CJVF Dir.tar.xz dir

3. Decompression operation
TAR-XZVF dir.tar.gz
TAR-XJVF dir.tar.bz2
TAR-XJVF DIR.TAR.XZ

Attention:
<1>f must be on the last side of the combination
&LT;2&GT;TAR-XVF dir.tar.x automatically according to the format of the compressed package to select the appropriate decompression method for decompression


Four file permissions, file owner, group modified

1.chmod Modify permissions for the specified file

chmod u/g/o/a +/-r/w/x file
chmod 666 File

2.chown Modify file owner or group
Chown User name File
Chown User name: Group name file

3.CHGRP Modify the group in which the file resides

CHGRP Group name File

Question: How do I modify permissions or the owner or group of all files, including subdirectories?
Answer: Chown root *-R (change all file owner names to root, including subdirectories)

Links to five files

(1) Soft link
It is a file type, similar to a Windows shortcut, used to record the path of the destination file

Ln-s destination file (normal file or directory file) soft connect file

(2) Hard links
Essence: Aliases A file, does not create a new file, does not occupy disk space

ln destination file Hard Connection file

Attention:
(1) Hard links cannot operate on directories
(2) Hard links cannot cross file systems
(3) in the Linux operating system only if a file is opened 0 and the number of hard links is 0, this time indicates that the file does not exist to be deleted

Question: How do I automatically delete files when they are closed?
Answer: Open the file once, turn this file hardware into 0


Six User Management

(1) AddUser user name

/ETC/PASSWD information for users of the storage system
/etc/shadow User Password
/etc/group information about the storage System group
/etc/skel when creating a new user, copy the configuration file from this directory to the user's home directory

(2) Temporarily switch users

SU User name

(3) Withdrawal of temporary users
Exit

(4) Adding a user to a specified group

Usermod-a-G Group name User name

(5) Delete a user
Deluser User name--remove-home (delete the user's user home directory when deleting users)

(6) Modify user password
sudo passwd user name

Seven HDD Management

(1) View hard disk information in the system
sudo fdisk-l

(2) View the usage of the partition
sudo df-h

(3) Manually mount your own device
Mount: Maps information from a block device to a specified directory
sudo mount/dev/device file name mount Directory

(4) Cancel the mounted directory
sudo umount mount directory

Eight network management

1. Network Fundamentals

(1) IP: The unique designation of the host in the network
(2) Composition: Network number (host network) + host number (network host number)
(3) means: dotted decimal
(4) IPV4 (32bit,4byte), IPv6 (128bit,16byte)
(5) Classification

1000 0000
1011 1111

1100 0000
1101 1111
Network number + host number The highest bit specifies the first byte range
A 1 + 3 0 [0-127]
B 2 + 2 10 [128-191]
----------------------------------------------------------
C 3 + 1 110 [192,223]

Number of hosts: 1byte [0-255]

192.168.0.0 (representing network) 192.168.0.255 (broadcast address)
---------------------------------------------------------
D multicast 1110 [224,239]
E not used

Problem: Intra-LAN, inter-host communication, compliance with what?
Answer: The network number is the same, the host number is different

(6) Subnet mask
Get Network Number = submask & Destination IP Gets the network number to determine if the target host and the current host are on the same network

(7) Gateway
The host IP address that can communicate with the external network can be used as the gateway, and the IP address of the router as the gateway
If the current host is not on the same network as the target host, the data sent to the target host is sent to the gateway, and the gateway forwards the packet to the extranet

(8) Dns
Domain name resolution, convert domain name to IP address

Www.baidu.com-IP

Free use of the domain name server:
8.8.8.8
114.114.114.114

2. View IP Address
ipconfig (Windows)/ifconfig (Linux)

Temporarily modify IP Address
sudo ifconfig eth0 IP address

3.ping Test Network is connected

Ping the destination host IP address or domain name

Ping 192.168.0.1
Ping www.baidu.com
Ping 192.168.0.42

Nine environment variables

1. View the environment variables in the system
Env

2.PATH Environment variables
When the shell executes a command, it is searched from the path saved by the PATH environment variable, or the prompt command is not found if the search is executed.

Question: How can I get my application to execute under any path?
Reply:
(1) Copy it to the path where the PATH environment variable is saved
Or
(2) Add your own path to the environment variable


3. Add Environment Variables Permanently

When the shell program is running, the following files are automatically executed:
/ETC/BASH.BASHRC Valid for all users
The. bashrc file in the user's home directory is valid only for the current user

We just need to add the changes to the environment variables to any one of these configuration files.


Linux basic Commands (2)

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.