table of Contents
One, Linux directory
The main directory trees are /, /root, /home, /usr, /bin, etc. The following is a typical Linux directory structure.
Description:
/ Root directory
/bin stores the kernel and files needed for startup
/dev In Linux, devices are all in the form of files. The devices here can be hard disks, keyboards, mice, network cards, terminals, and other devices. By accessing these files, you can access the corresponding devices.
/etc stores system configuration files
/home Home directory of ordinary users, user data is stored in its home directory
/lib stores the necessary runtime libraries
/mnt stores a temporary mapping file system, usually used for mounting
/proc stores storage process and system information
/root super user's home directory
/sbin store system management program
/tmp stores temporary files
/usr stores application programs, command program files, program libraries, manuals and other documents
/var System default log storage directory
Two, commonly used commands
Enter the system by default, [root@local_host~]#, where # represents the current root user, and $ represents the current normal user
cd [path]: go to the [path] directory; cd / return to the root directory; cd ~ return to the current user directory; cd ../ return to the previous directory; cd ./ current directory
ls: view the current directory; ls ./ view all files and directories in the current directory; ls -a view all files, including hidden files, and files beginning with.
ll: View the current directory (detailed information: permissions, creation time, size, etc.)
pwd: view the current directory
mkdir: create a directory; create a multi-level directory plus -p
rmdir: delete an empty directory; rm: delete a directory or file, usage rm -rf [folder/file name] (-r means recursion, -f means mandatory)
cp: copy files; usage cp [name of file to be copied] [name of new file], if it is a directory, you need to add parameter -r
mv: Rename or move files/directories, use mv old.txt new.txt
touch: create a file, use touch text.txt if the file exists, it means to modify the current file time
useradd: create a user; userdel: delete a user
groupadd: create a group; groupdel: delete a group
find: Find a file or directory, use find /home -name "test.txt"; find is followed by the directory to be searched, -name specifies the name of the file to be searched, and the name can use * to indicate all. find /home -name "*.txt" finds all files or directories ending with .txt in the /home directory.
vi: modify a file, vi has three modes: command line mode, text input mode, and last line mode
By default vi opens a file, first in command line mode, then press i to enter text input mode, you can edit the content in the file; after writing, press ESC to enter command line mode, and then enter: enter the last line mode, such as input: wq Means to save and exit, enter: q! Indicates exit without saving.
cat: View the contents of the file (view all)
more: View the content of the file (view by page); the above can be used at the same time, such as cat test.txt | more, the text content is displayed by page, and | is a pipe symbol, used to input the input before | as the input of the subsequent command.
Echo: Echo, print what you type; echo ok >test.txt overwrite the content of test.txt with ok characters,> means append and cover; >> means append;
Three, authority management
In the Linux system, the root user has the highest authority and can execute any commands and operations. In the system, the user's authority level is distinguished by UID. UID is equal to 0, which means that this user has the highest authority, that is, the administrator. The UIDs of other users increase sequentially, and the independent UID of each user can be viewed through the /etc/passwd user password file.
The permissions of each file or directory include a user's permissions, a group's permissions, and other people's permissions.
[root@yang test]# ls -l
总用量 0
-rw-r--r-- 1 root root 0 3月 15 21:54 1.txt
Here the first root means that the owner of the file is the root user, and the second root means that the group to which the file belongs is the root group, and other users are not marked here by default.
Each Linux file has four access permissions: readable (r), writable (w), executable (x) and no permissions (-). Use the ls -l command to view the permissions of a file or directory, and display the first field (10 characters) of the data.
The first digit indicates the file type,-indicates the file, d indicates the directory, and every third digit is a group;
The first group: 2-4 digits represent the authority of the file owner, that is, the user authority, referred to as u
The second group: 5-7 digits indicate the permissions of the members of the group to which the file owner belongs, group permissions, referred to as g
The third group: 8-10 digits represent the permissions of users outside the owner's group, other permissions, referred to as o
In the above 1.txt file, the root user has read and write permissions, the root group has read permissions, and others have read permissions. rwx can be represented by numbers, represented as r(4), w(2), x(1), for example, 1.txt permissions can be represented as 644
If you want to change the read and write permissions of a file, you can use the command chmod:
chmod o+w 1.txt or chmod 646 1.txt //Users outside the owner’s group add write permissions
If you want to change the owner or group of a file, you can use the command chown:
chown -R test:test 1.txt
Four, network configuration
The Linux server default network card configuration file is under /etc/sysconfig/network-scripts/, and the named names are generally ifcfg-eth0, ifcfg-eth1, eth0 represents the first network card, eth1 represents the second network card, and so on.
[root@yang ~]# cd /etc/sysconfig/network-scripts/
[root@yang network-scripts]# ls
ifcfg-eth0 ifdown-ppp ifup-eth ifup-sit
ifcfg-lo ifdown-routes ifup-ippp ifup-Team
ifdown ifdown-sit ifup-ipv6 ifup-TeamPort
ifdown-bnep ifdown-Team ifup-isdn ifup-tunnel
ifdown-eth ifdown-TeamPort ifup-plip ifup-wireless
ifdown-ippp ifdown-tunnel ifup-plusb init.ipv6-global
ifdown-ipv6 ifup ifup-post network-functions
ifdown-isdn ifup-aliases ifup-ppp network-functions-ipv6
ifdown-post ifup-bnep ifup-routes
To modify the IP of the network card, you can use the command: vi /etc/sysconfig/network-script/ifcfg-eth0. The configuration here is automatically obtained by dhcp and can be modified to static. Modify the parameters as follows
BOOTPROTO=static
IPADDR=192.168.1.2
NETMASK=255.255.255.0
GATEWAY=192.169.1.10
[root@yang network-scripts]# cat ifcfg-eth0
# Created by cloud-init on instance boot automatically, do not edit.
#
BOOTPROTO=dhcp
DEVICE=eth0
HWADDR=fa:16:3e:f1:3c:fb
ONBOOT=yes
TYPE=Ethernet
USERCTL=no
The detailed network card parameters are as follows:
DEVICE=eth0 #Physical device name
ONBOOT=yes #[yes|no] (restart the network card whether to activate the device)
BOOTPROTO=static #[none|static|bootp|dhcp] (not applicable protocol|static allocation|BOOTP protocol|DHCP protocol)
TYPE=Ethernet #Network card type
IPADDR=192.168.1.2 #IP address
NETMASK=255.255.255.0 #Subnet mask
GATEWAY=192.169.1.10 #Gateway address
Restart the network card after the configuration is complete: /etc/init.d/network restart
The ifconfig command checks the IPs of all network cards of the current server. Specify a network card separately, ifconfig eth0
After the network card configuration is completed, if you configure DNS, vi /etc/resolv.conf, add the following two items, you do not need to restart the network card after the configuration is complete, and DNS takes effect immediately
nameserver 202.106.0.20 #Main DNS
nameserver 8.8.8.8 #Backup DNS
Common Linux remote tools, putty, secureCRT, xshell, xmanger, etc.
Garbled characters in ssh remote: # LANG=UTF-8
to add on:
Linux partition: Similar to windows partition, Linux is usually partitioned as root partition/, swap partition. Linux stipulates that each hard disk device has at most 4 primary partitions.
Linux file system types: ext2, ext3, ext4, etc. (windows file system types: nfts, fat32).