Linux Fundamentals 02

Source: Internet
Author: User
Tags gz file scream file permissions

* * Linux Basic Operations common commands (ii) * * Username and host name

When you enter the Linux terminal, you will see a picture of the following style:

where [[email protected]] in square brackets z indicates the user name of the current system login operation, after @ z01 represents the current hostname, each person's situation is different, the default hostname is: localhost

So let's start by looking at how to modify the hostname in CentOS 7

* View/Modify host Name

View: hostname,

To switch to the root user:

Temporary modification mode: hostname + name, for example: hostname z01

Persistent modification mode: Vi/etc/hostname, directly modify the hostname configuration file, similar to the changes in Notepad, modified to save the exit can be completed.

Temporary modifications are restored after the system restarts, and persistent modifications are not invalidated by a system restart. Persistent modifications require a reboot of the system, using the reboot command.

* * Users and user groups

* Using the command: cat/etc/passwd to view the current user and user groups, the following appears:

Here we take the last line of data as an example, because this line represents the current user, namely:

Z:x:1000:1000:z:/home/z:/bin/bash

Explain:

(1): User name.

(2): password (already encrypted)

(3): UID (User ID), operating system's own

(4): GID group identification.

(5): User's full name or local account

(6): Start directory

(7): The shell used for login is the tool to parse the login command.

* * User Action

Create User: Useradd username

Delete User: Userdel-r username (-R for complete deletion with user directory)

Create user group: Groupadd groupname

Delete user group: Groupdel groupname

Modify user password: passwd username

Echoing input: Echo

For example:
echo ' 123456 ' | passwd--stdin username

This instruction means: Change the password to 123456, and display the password

Switch User: Su username or su-username

(Plus "-", means to switch users, along with environment variables, working directory to switch, no "-" reverse)

* * Directory/file permissions

The file or directory permissions is something, please Baidu by yourselves. No more nonsense, directly show how to operate the permissions.

First, use the LS-L command to view sub-file/subdirectory permissions in the current directory.

1. Structure and letter meaning

Drwxr-xr-x

This series of letters can be split into:

D

Rwx

R-x

R-x

Four sections, which are explained in turn below

2, the letter means (R meaning is readable, W is writable, X is executable,-for the non-meaning, that is, if the letter replaced-that is)

First paragraph: D: Represents the data directory, a placeholder

Second paragraph: rwx: representing the owner (USER,U)

Third paragraph: r-x: Indicates the owning group (GROUP,G)

Fourth paragraph: r-x: Other people (Other,o)

R: Reading, such as command, Cat,haed,more,tail

W: Write, like command, MKDIR,TOUCH,VI,VIM,RM,CP,MV, etc.

X: Execute, such as command, CD

3, number representation, add operation

For example: d755

R: denoted by the number 4

W: denoted by the number 2

x: denoted by the number 1

4. Modify Permissions

chmod, for example:

Add to:

chmod u+x Program

CHOMD 777 Program

chmod g+x,o+x Program

Explanation: U+x means, owner, add new "executable (x)" permissions, and so on.

Bulk operations:

CHOMD u+rwx,g+rwx,o+rwx zz1.txt Zz2.txt

Explanation: Modify the permissions for the Zz1.txt and zz2.txt files for this: u+rwx,g+rwx,o+rwx

5. Modify the File/directory owner

Scream Hint: Modify the owner, as far as possible under the root permission to operate.

Modify Owner:

Chown ROOT/HOME/XXX/ABC, Explanation: Change the ABC owner to root

Modify the owning group:

Chgrp ROOT/HOME/XXX/ABC, Explanation: That is, modify the ABC belongs to the group root

Colleagues modify the owner and the owning group:

Chown ROOT:ROOT/HOME/XXX/ABC, Explanation: Modify the ABC owner and the owning group as root

* * Power off restart command

1, Shutdown: Init 0, shutdown to end other processes, and then shut down the machine

2. Restart: init 6, reboot execute the shell shutdown script of other programs before restarting

* * pipe, append/overwrite 1, pipe, "|", which means that the output of the previous command is passed to the following command for processing

For example:

cat/etc/passwd | More

2, filtering, "grep", means filtering filter

For example:

cat/etc/passwd/| grep ' Root '

Explanation: View all rows with the root keyword

Again for example:

Ifconfig | grep ' 192.168 '

Explanation: View all content with 192.168 keywords

(Scream hint: Not all commands can be placed behind the pipe symbol)

3. Append/Overwrite

Append: >>, append the result of the previous command output to a file later

Overwrite: To overwrite the result of the previous command output to a file in the back

For example:

CAT/ETC/PASSWD >> Zz.txt

4. Statistical commands

Statistics command: WC, statistic word, character, line number, etc., support pipe character

For example:

Ifconfig | Wc-l

Explanation: See how many rows there are

Show Process: PS, shows the current system running process, similar to Task Manager

For example:

Ps-ef | Wc-l

Explanation: See how many processes are currently

* * Search Command

Search command: Find, which consumes a lot of system resources. To illustrate the command directly:

File name lookup:

Search all: Find/-name VMS

Fuzzy query filenames with keywords: find/etc/-name *vm*

Look for keywords beginning with: find/etc/-name init*

* Number: wildcard character, match any string

Number: Matches a single character, for example: find/etc/-name init???

(Scream tip: If you don't want to be case-sensitive, search by file name, use-iname)

---------------------------------------useless split-line---------------------------------------------

File Size lookup:

Size: Search by file size (a chunk size of 512byte in Linux)

Specify the way: +,-, no symbol means equals

For example:

100M File Lookup:

Find/-size + number of blocks (i.e. 100M divided by 512byte, remember conversion units, i.e.: 100 * 1024 * 1024/512)

Owner/Owning Group lookup

For example:

find/root/-user Root

find/root/-group Root

File Type Lookup

find/etc/-name init*-type f: Find Files

find/etc/-name init*-type d: Find directory

* * Disk Management (switch to root user operation) 1, fdisk-l: To view all the equipment in the system, 2, SDA represents the first hard disk in the System 3, SDA1,SDA2 represents the first disk, the second partition 4, the hard disk interface: SATA,SAS,IDE,SCSI, etc.

(Scream: HDA is the name of the hard disk using the IDE interface, SDA is the SATA hard disk interface name, all the hard drives are called SDA in the 2.6.19 kernel)

(Scream hint: IDE, integrated Drive electronics, integrates the body and the controller)

(Scream hint: SATA, i.e. serial ATA, i.e., serial Advanced technology Attachment)

The specific meaning of the difference and explanation please Baidu, not this chapter focus

5, Cylinders: Magnetic column, simple understanding: Magnetic column is the basis for partition of hard disk. Can be divided into a number of different sizes of the cylinder, and the beginning of these cylinders is a single partition, in Linux is sdb1,sdb2 .... In Windows, C, D, and so on. 6. Set Partition: Fdisk/dev/sdb Set the second drive 7, add a new partition:

For example:

n Add a new partition

8. Primary and extended partitions

In general, the number of primary partitions + Expand the number of partitions <= 4

Enterprise Usage General: 3 primary partition + 1 expansion or 2 main + 1 expansion

(Scream hint: The extended partition cannot be used directly, the extended partition needs to be logically partitioned, and the primary partition can be used directly after formatting)

9. Format the partition

File system: ext1,2,3,4

Usage: MKFS.EXT4/DEV/SDB5

10. Mount (Temporary Mount)

Usage: mount/dev/sdb5//mnt (i.e. mount point, access to disk's unique entry, mount point must exist)

To see if the Mount: df-h

11. Mount (Permanent mount)

Usage:

Vi/etc/fstab

Add to:

/dev/sdb5/mnt EXT4 Defaults 0 0

* * Man help command

1. View the command's Help information

2. View the Help information for the configuration file

For example:

Man LS, that teaches you how to use the LS command

* * sudo permissions 1, operation of the object is System command 2, switch to the root user, using the command: Visudo3, Root all= (all) all

Explain:

Root: User

All= (All): Managed host address (identity used)

All: Authorized Commands

4, Whereis shutdown, view shutdown command location, 5, configure shutdown sudo permissions

Z All=/usr/sbin/shutdown-r now

Once the configuration is complete, it can be used under normal users:

sudo shutdown-r now

6. Configure sudo permissions for all commands

Z all= (All) Nopasswd:all

(Scream Hint: nopasswd:all: no password)

* * Unzip the command compression format:. gz

Compression: gzip can only compress files and cannot compress directories

Decompression: Gunzip

(Scream hint: Source files are not preserved after decompression)

Compression format:. tar

Compression: Can compress files or directories

Parameters:

-C: Create a compressed file (create)

-x: Unlock a compressed file

-T: View the files inside the Tarfile

-F: Use file name, immediately after F to receive the file name, no additional parameters

For example:

TAR-CVF Zzzz.tar desktop/

Gzip Zzzz.tar

Explanation: Compress the Desktop directory to Zzzz.tar file, and then use gzip compression Zzzz.tar to zzzz.tar.gz file

Unzip: Tar

For example:

TAR-ZXF zzzz.tar.gz-c desktop/

Explanation: Unzip the zzzz.tar.gz file to the Desktop directory

* * Linux configuration JDK environment variable 1, linux JDK download:

Link: http://pan.baidu.com/s/1jIQGem6 Password: Enyj

2. Create two directories under the/opt/directory

Modules and Software

3, using FileZilla client this software upload JDK compression package to/opt/software/directory 4, decompression: TAR-ZXF jdk-8u121-linux-x64.gz-c/opt/modules/, that is extracted to/opt/ Modules/Directory 5, modify the configuration file: Vi/etc/profile

At the end add:

# #JAVA_HOME

java_home=/opt/modules/jdk1.8.0_121

Export classpath=.: $JAVA _home/jre/lib/rt.jar: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar

Export path= $PATH: $JAVA _home/bin

6, make the configuration file effective: Source/etc/profile7, check whether the configuration is successful:

Java-version and Javac

(Scream hint: Because the CentOS 7 has its own openjdk, at this time the java-version display is not the version you configured, so at this point, we explain how to uninstall the system comes with the OPENJDK) * * Uninstall the Open JDK1, view the own open Where to install the JDK

Rpm-qa | grep ' Java '

2. Delete the installation package with the Java keyword in turn, i.e.:

RPM-E--nodeps java-xxx.xxx.xxx.xxx

(Scream hint:--nodeps means forced action)

* * Clone virtual machine

1. Shut down the system that needs to be cloned in the virtual machine, namely:

2, click on the tab bar: Virtual machine-management-cloning, the following dialog box appears:

3. Next, select "Current status in virtual machine", i.e.:

4. Select Create complete clone, i.e.:

5, the new virtual machine name, out of the default interface is this:

Modify the name and location, for example:

6, click Finish, there appears the following interface, a little to wait, on the cloning success:

7. After cloning is complete, start the virtual machine, because it is cloned, so the same as the first virtual machine, then we need to modify the following:

(Scream Hint: Remember to switch to root user operation)

* Hostname hostname, modification method:

Vi/etc/hostname

* Modify Network Configuration

vi/etc/sysconfig/network-scripts/ifcfg-eno16777736,

Change the IP address in the red box from the 192.168.122.200 of the first virtual machine to 192.168.122.202, because this is the third one I cloned, maybe you cloned the second, you can instead of repeating. It is recommended that you increment in a certain order. Remember to save the exit after you have modified it.

* Modify Linux Host Mappings

Command: vi/etc/hosts, modify to:

If this option is not set by the z01 virtual machine, it can be set manually. method as above.

* Modify the hosts hostname mapping in Windows system, that is, add the last bar,

(Scream Hint: Hosts file location: C:\Windows\System32\drivers\etc)

Because I directly cloned 2 sets out, configure the way is the same, after learning to clone one, and then clone one can.

* Restart the virtual machine

With the root user, restart the virtual machine with the reboot now command, and after the reboot is complete, you can connect to the virtual machine using the SECURECRT software.

* * Summary

Operation command you only need to operate once (it is necessary), because behind the development process may be repeated use, the mind to leave an impression, need to use the time of repeated review, will naturally remember, understanding will be more transparent.

Personal micro-Blog: http://weibo.com/seal13

QQ Big Data Technology Exchange Group (ADS do not enter): 476966007



Z The best
Links: Https://www.jianshu.com/p/b70e16e32c50
Source: Pinterest
Copyright belongs to the author. Commercial reprint please contact the author for authorization, non-commercial reprint please specify the source.

Linux Fundamentals 02

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.