Linux Basics (21-30)

Source: Internet
Author: User
Tags disk usage

1.Shell Overview What is a shell?
    • is a command-line interpreter that provides users with an interface system-level program that sends requests to the Linux kernel to run programs, which users can start, hang, stop, or even write programs with the shell.
    • Or a powerful language, easy to write, easy to debug, flexible. The shell is the scripting language that interprets execution, and you can call Linux system commands directly in the shell
Classification of shells
    • Bourne Shell, also known as B Shell Unix began to use it since 1979, and the main file name issh
    • C Shell, mainly in the BSD version of the UNIX system, because its syntax and C language similar to the name

The two main syntax types of the shell are Bourne and C, which are incompatible with each other. The former mainly includes sh, ksh, Bash, psh , the latter mainly includes csh, tcsh .

The standard shell for Linux is Bash ! Bashand sh are compatible with each other. By executing echo $SHELL , you can see which shell the current system supports

Linux-supported Shell

vi /etc/shellsYou can see all the shells currently supported by Linux
shFrom the Bash entrance to thesh
exitExit Current Shell
Use the bash command to create a child shell under an existing bash, as well as to use exit exit, call and exit are first-level coherent
A follow-up course will tell you what your current shell is.

2. Disk Management basic commands to view disk partition usage

df【选项】
Options:
-lShow only local disks (default)
-aDisplays disk usage for all file systems, including, for example,/proc/
-hThe most appropriate unit to display the disk capacity in 1024 binary
-HThe most appropriate unit to display the disk capacity in 1000 binary
-TShow disk partition type
-tDisplays the disk partitions for the specified type of file system, such asdf -t ext4
-xDo not display disk partitions for the specified type of file system

To count the file size on a disk

du【选项】
Options:
-bStatistics files in bytes
-kStatistics files in kilobytes
-mStatistics files in megabytes
-hStatistics files in the most appropriate units according to the 1024 binary
-HStatistics files in the most appropriate units according to the 1000 binary
-sSpecify the statistics target, for example du -s ~/desktop , to see the size of the Destop directory

3. Base line mode and command mode common commands in the bottom row mode

:wSave
:qExit
:!Ignore modification, Force exit
:lsList all open files
:n:Nfile forward, back
:15Quickly navigate to line 15th
/xxxFrom the cursor position, search backwards for XXX
?xxxFrom the cursor position, search forward XXX

Command mode common directives

hMove Cursor Left
jMove Cursor Down
kMove Cursor up
lMove Cursor Right
ctrl+fPage DOWN (front)
ctrl+bPage Up (back)
ctrl+dTurn down half page (down)
ctrl+uTurn up half page (UP)
ddDelete the cursor in the row
oInsert a row below the line where the cursor is located and switch to input mode
yyCopy the row where the cursor is located
pPaste below the line where the cursor is located
PPaste above the line where the cursor is located

4. Partition formatting
ls -l /dev/sdb* # 查看第二块磁盘的分区mkfs.ext3 /dev/sdb1 # 将第二块磁盘的第一个分区格式化为ext3文件系统mkfs -t ext3 /dev/sdb2 # 效果和上一个一样
5. Mount Partitions

Partition default mount directory Yes /mnt , mount point must first exist

mkdir -p /mnt/imooc # 建立sdb1的挂载点,即新建目录mount /dev/sdb1 /mnt/imooc # 完成挂载,可以开始存储数据umount /mnt/imooc # 完成卸载# monut命令,当系统重启之后就会失效,如果想永久挂载,需要编辑/etc/fstab文件vim /etc/fstab/dev/sdb1 /mnt/imooc ext3 defaults 0 0 # 在末尾添加,保存退出
6. Other user and user group commands

su【用户名】Quickly switch to the current user, or switch to the root user if you do not add a user name
whoamiDisplays the currently logged in user name
id【用户名】Displays the specified user information, including user number and user name; Primary group number and name, subordinate group list
groups【用户】Show the primary and secondary groups where the user resides
chfn【用户】Set up user profile, enter user data in sequence
finger【用户】Show User's details

7. Concepts of users and user groups

Users: People using the operating system
User group: A group of users with the same system permissions in the operating system

/etc/groupStore all user group information in the current system

cat /etc/groupWill find a lot of user groups, each line has a basic format a:b:c:d : A is the group name, B is the group password placeholder, c is the group number, D is the list of user names in the group, is empty does not mean that there is no user, when the group as long as a user, and the user name and group name can be omitted. The following points need to be noted:

    1. The root user group must have a group number of 0, such as ' root:x:0: '
    2. Group number 1-499 is reserved for the system software and services, such as the installation of MySQL, will automatically create a MySQL user group, the earlier installed software and services, the smaller the group number
    3. User group numbers created manually by users are starting from 500
    4. The master password placeholder is all represented by X, which is related to the evolution of system security, and the subsequent course will
/etc/gshadowStore password information for user groups in the current system

cat /etc/gshadow
Basic format a:b:c:d : A is the group name; b is the group password; C is the group manager; D is the list of user names in the group.

/etc/passwdStore information for all users in the current system

cat /etc/passwd
Basic format a:b:c:d:e:f:g : A is the user name, B is the password placeholder, c is the user number, D is the user group number, E is the user comment information, f is the user's home directory, and G is the shell type.

/etc/shadowStore password information for all users in the current system

cat /etc/shadow
Basic format a:b:c:d:e:f:g : A is the user name, B is the user login password, one-way encryption, and others are fragmented content, including the creation time, the last modification time and so on.

Originally only group and passwd two files, but later to consider the security issues, it has evolved shadow and Gshadow two files.

8. Basic commands for users and user groups
# commands related to user groups Groupadd Cloudedge# Create user Group Cat/etc/group# See if the last line has been added groupmod-n Hadoop cloudedge#-N stands for modifying group name Groupmod-g668 Hadoop#-G for modifying group number Groupadd-g888 Master #-G means specifying group numbers when creating user groups Groupdel Hadoop # Delete user group # user-related commands useradd-g Hadoop Jeff #- G represents the specified user group Useradd -d/home/jeff Jeff #-D represents the creation of the specified user's directory, by default Under Home Create a directory with the same name as the user name usermod-c HelloWorld Jeff #-C represents adding comment information to the user usermod -l Newjeff Jeff #-l for modified user name Usermod -d/home/ Newjeff Newjeff # Modify user's directory usermod-g Master Jeff #- G For change user group Userdel Jeff # delete user, but does not delete/home/jeff files userdel-r Jeff # completely remove touch/etc/nologin # as long as this empty file is created to prevent users outside the root user from deleting user information   
9. User and user group advanced commands
-l NewJeff # 锁定用户passwd -u NewJeff # 解锁用户passwd -d NewJeff # 无密码登录
Primary and secondary groups

Users can belong to multiple user groups at the same time, but must have a primary group, plus multiple satellite groups.

-a NewJeff Master # -a代表将用户添加到一个附属组,如果有多个附属组,可以相互之间用逗号隔开,但用户创建文件等操作都默认属于他的主用户组,如果要在附属组下进行,就要将身份临时切换到附属组newgrp Master # 注意这个命令的前提是你现在登录在NewJeff下!!需要用户自己执行!!# 此时可能需要你输入Master的组密码gpasswd -d NewJeff Master # 从用户组中删掉用户,即将用户的某个附属组去掉useradd -g group1 -G group2,group3 Jeff # 直接设置用户的主从用户组gpasswd hadoop # 设置用户组密码
MBR of 10.GPT partitioned partition mode
    • No more than 4 primary partitions
    • Single partition capacity 2TB Max
GPT of partition mode
    • The number of primary partitions is "almost" unlimited
    • Single partition capacity "almost" unlimited
    • However, a system in the GPT primary partition that is not suitable for installing the X86 architecture
Parted# can be either MBR partitioned or GPT partitioned# default is USING/DEV/SDA, which is the first hard drive, is the help that can switch other disks# View Help InformationSelect/dev/sdc# switch to the third disk Mklabel GPT# Specify partition table type, use GPT partition mode Mklabel MSDOS# or use MBR partition modePrint# View partition information for the current diskPrint all# View partition information for all disks# can now start partitioning, there are two types of interaction and command mode # first, interactive mode Mkpart # ask for a personalized partition name, default left blank # ask the partition's file system, default ext2 # ask for the starting point of the partition location, referring to the beginning of the first few megabytes, the input 0# ask the end point of the partition location, referring to the end of the first few megabytes, for example, want to give it 2G , give 2048# may appear an "unaligned" error, this time cancel is required, and then set the starting point starting from 1 or 2 # Then, Command mode Mkpart test 2000 3000 # Directly set the partition name and size, at this time there are two partitions # but if you set up a partition Mkpart next 2500 3500, will overlap with the previous partition, it will let you choose whether to accept the proposed partition size RM Span class= "Hljs-number" >3 # Delete partition, 3 is partition number  #继续添加分区, can exceed 4 limit, And without the primary partition, these concepts of logical partitioning unit GB # units converted to gbquit # exit partition tool, immediately effective  
 

Linux Basics (21-30)

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.