Common Linux commands
System Basics
- Use the environment variable of the root user to switch to the root user
su -
- Show current working path
pwd
- Display the default language and keyboard layout of the current system
localectl
- Display All languages supported in the system
localectl list-locales
- Set the default system language to Chinese.
localectl set-locale LANG=zh_CN.gb2312
- Restart the machine
reboot
- Shutdown
poweroff
- Exit the Current shell
logout/exit
Command help
command --help
man command
info command
- List brief usage information of commands (when using
whatisWhen an error is reported, runmandbCommand to generate an index file)whatis command
Routine commands
- Display or change date
date
- Show Calendar
cal
- Count the number of lines or characters of text and other related information
wc
- Find the absolute path of the command
which
- List the number of recently used commands (rehl saves 1000 by default)
history number
- The first 10 lines of text are displayed by default. to display more lines, you can add or subtract numbers.
head [+- number]
- The last 10 lines of text are displayed by default. to display more lines, you can add or subtract numbers.
tail [+- number]
- Display text content from top to bottom
cat
- Display text content from bottom up
tac
- Switch the working path
cd
- Show directory content
ls
- When copying a file or directory, add
-rOption indicates recursive Replicationcp
- Rename/move a file or directory
mv
- Delete a file or directory. When deleting a directory, add
-rOption indicates recursion, plus-fOption indicates force deletion and no reminderrm
- Create directory, recursively create and add
-pOptionmkdir
- Create an empty file or update the timestamp
touch
- List Directory trees
tree
- File Verification
sha1sum sha224sum sha256sum sha384sum sha512sum
- Verify File
md5Valuemd5sum
- View text content on screen
less
Users, groups, and permissions
- Print user identity information
id
- Change
userUser Passwordpasswd user
- Add User
useradd
- Change User Information (uid, gid, and groups)
usermod
- Delete a user
userdel
- Add Group
groupadd
- Delete Group
groupdel
- Change User Permissions, groups, and IDs
change
- Change the user and group of the file to student.
chown student.student file
- Change the group to which the file belongs
chgrp
- Change File Permissions
chmod
- Mask mode change
umask
Network Configuration
- Miscellaneous
Files related to network configuration are stored in/etc/sysconfig/network-scripts/ifcfg-*/etc/hosts # static IP address to the name resolution file/etc/hostname # host name configuration file Interface Name rule ethx # Ethernet interface wlanx # wireless network interface pppxx # PPPOE dialing Interface
VIEdit the configuration file to configure the networkConfigure static IPv4 addresses (vi manually edit the configuration file) cat/etc/sysconfig/network-scripts/ifcfg-DEVICE = # enter the physical Nic name BOOTPROTO = none # Address Allocation type {dhcp | none | static} IPADDR = 1.2.3.4 # IPv4 address PREFIX = 24 # NetmaskGATEWAY = 1.2.3.254 # GWDNS1 = 1.2.3.254DNS2 = 1.2.3.253ONBOOT = yes # configure whether this interface is enabled at startup # systemctl restart network configure dynamic IPv4 addresses (vi manually edits the configuration file) cat/etc/sysconfig/network-scripts/ifcfg-DEVICE = # enter the physical Nic name BOOTPROTO = dhcp # Address Allocation type {dhcp | none | static} ONBOOT = yes # configure this whether the interface is enabled at startup # systemctl restart network configure DNS Client # cat/etc/resolv. confsearch redhat.com # search domain nameserver 1.2.3.4nameserver 4.3.2.1 configure the static IP address to the resolution list of the name. When no DNS server exists in the Intranet, you can edit the hosts file to resolve the IP address to the name # cat/etc/hosts10.1.1.1 server1 server1.example. com10.1.1.2 server2 server2.example.com change host name # cat/etc/hostnameserver.example.com
Decompression Problems
- Tar
cCreate
tList
xExtract
fFile Name
CDecompress the package to the specified directory.
zUsegzipCompression
jUsebzip2Compression
JUsexzCompress
- Package
tar cvf filename.tar /path
- Package and compress it into gzip format
tar czvf filename.tar.gz /path
- Decompress the package to the specified folder.
tar xvf filename.tar /path
- View the compressed Package content but do not understand the pressure
tar tvf filename.tar
Software Package Management
yumCommon commandsYum install a B c d # install software package a B c d (with the-y option added, you can leave the prompt "continue" when installing the software package) yum remove a B c d # uninstall software package a B c dyum groups list # view installed software groups and available software groups yum groups install "Infiniband Support" # install software group yum groups remove "Infiniband Support" # uninstall the software group yum info a B c # view information about the software package a B c d, such as size and version... yum update a B c d # update the software package a B c dyum update # update the yum provides file or directory of all the software packages that can be updated as a whole # Check which rpm package provides the yum search tree for the file # search for a tree package yum history # view the yum running history from the Repository
rpmCommon commandsRpm-qa # query all RPM packages installed on the local machine rpm-qa -- last # query all RPM packages installed on the local machine in chronological order rpm-qf files or directories # Check which rpm files are installed on the local machine the rpm-Va package name provided by the package # verify the integrity of the RPM package, you can also leave it empty, verify the RPM-qd package name of all rpm packages # Check which RPM-ql package names are attached to the rpm package # Check which files are released by the RPM package under which rpm-qc package name # view the RPM-e package name in the configuration file attached to the rpm package # uninstall the RPM package, multiple packages are separated by spaces. rpm-e package name -- nodeps # The dependency between RPM packages is not checked, directly uninstall the RPM-ivh package name # install one or more rpm-Uvh Package Names # upgrade one or more RPM packages
File System Problems
- Device File naming rules
Naming rules for device files in Linux/dev/sda # The first serial Hard Disk/dev/hda # The first parallel hard disk/dev/vda # The first virtio Driver Based on KVM one Virtual Disk/dev/xvda # Virtual Disk/dev/cdrom # CD/DVD Device Based on Xen virtualization technology, this file is usually linked to/dev/sr0, that is, the first CD/DVD device, and the second optical drive device, that is,/dev/sr1, and so on/dev/vgname/lvname # logical volume Disk/dev/sda1 # The first partition of the first serial Hard Disk/dev/hda1 # Remarks on the first partition of the first parallel hard disk: when there are more than 24 disks in Linux, for example, from/dev/sda>/dev/sdz, the redundant disks will continue with/dev/sdaa, /dev/sdab df # display file system usage du # Count file size mount # mount a partition to a directory, or display the mounting status
File Search
- Run
updatedbCreate an index database and then executelocate filename
findSearchFind/-name ccie # traverse all subdirectories from/partition, and find/-type d-name ccie # traverse all subdirectories from/partition according to the file name, then, only find/-size 10 M in the directory named ccie # traverse all subdirectories from/partition, find/-perm 0755 # retrieve all subdirectories from/partition, find the file with the permission of 0755 and find/-user student # traverse all subdirectories from/partition, and then find the file of student.
Services and processes