As a developer, how can you not order Linux commands? Summarized a set of very practical Linux commands (based on CentOS 7.6), I hope to help everyone!
Hello everyone, let me introduce myself first. I'm on the code. You can call me Brother Code. I am also the most ordinary student who graduated from an ordinary undergraduate degree. I believe that most programmers or those who want to work in the programmer industry are I am a child of an ordinary family, so I also rely on my own efforts, from graduation to join a traditional company, to changing jobs without fail, and now working in a giant company in the Internet industry, I hope that through my sharing, I can help everyone
Brothers, collect this article, do you still use Baidu?
content
Software installation and management
System service management
systemctl
systemctl
Commands are combinations ofservice
andchkconfig
commands that can be used to manage the system.
- Output the status of each service in the system:
systemctl list-units --type=service
- Check the running status of the service:
systemctl status firewalld
- Shut down the service:
systemctl stop firewalld
- Start the service:
systemctl start firewalld
- Restart the service (regardless of whether the current service is up or down):
systemctl restart firewalld
- Reload configuration information without interrupting service:
systemctl reload firewalld
- Disable the service from starting automatically at boot:
systemctl disable firewalld
- Set the service to start automatically at boot:
systemctl enable firewalld
file management
ls
List all files in the specified directory, list /
the files in the directory:
ls -l /
pwd
Get the absolute path of the current working directory:
cd
Change the current working directory:
cd /usr/local
date
Display or modify the system time and date;
date '+%Y-%m-%d %H:%M:%S'
passwd
For setting user password:
passwd root
his
Change user identity (switch to superuser):
su -
clear
Used to clear screen information
man
Display help information for the specified command:
man ls
who
- Query what runlevel the system is in:
who -r
- Display the users currently logged in to the system:
who -buT
free
Display system memory status (in MB):
free -m
ps
- Display system process running dynamics:
ps -ef
- View
sshd
the running status of the process:
ps -ef | grep sshd
top
View instantly active processes, similar to the Windows Task Manager.
mkdir
Create a directory:
more
For viewing files in pagination, for example, viewing files with 10 lines per page boot.log
:
more -c -10 /var/log/boot.log
cat
Used to view files, such as viewing the Linux startup log file, and indicate the line number:
cat -Ab /var/log/boot.log
touch
For creating files, e.g. to create a text.txt
file:
touch text.txt
rm
- Delete Files:
rm text.txt
- Force deletion of a directory and its subdirectories:
rm -rf testdir/
cp
For copying files, such as test1
copying a directory to a test2
directory
cp -r /mydata/tes1 /mydata/test2
mv
For moving or overwriting files:
mv text.txt text2.txt
Compress and decompress
tar
- Archive the
/etc
files in a folder to a fileetc.tar
(without compressing it):
tar -cvf /mydata/etc.tar /etc
gzip
Compress the files/etc
in the folder to file withetc.tar.gz
:
tar -zcvf /mydata/etc.tar.gz /etc
bzip2
Compress the folder/etc
to a file with/etc.tar.bz2
:
tar -jcvf /mydata/etc.tar.bz2 /etc
- Paging to view the contents of the compressed package (gzip):
tar -ztvf /mydata/etc.tar.gz |more -c -10
- Unzip the file to the current directory (gzip):
tar -zxvf /mydata/etc.tar.gz
- Unzip the file to the specified directory (gzip):
tar -zxvf /mydata/etc.tar.gz -C /mydata/etc
Disk and Network Management
df
Check disk space usage:
df -hT
ie
View the size of files and folders in the current directory:
du -h --max-depth=1 ./*
ifconfig
Display the current network interface status:
netstat
- View current routing information:
netstat -rn
- View all valid TCP connections:
netstat -an
- View the listening services started in the system:
netstat -tulnp
- View system resource information in the connected state:
netstat -atunp
wget
Download files from the web
File upload and download
- Install upload and download tools
lrzsz
;
yum install -y lrzsz
- To upload a file, enter the following command
XShell
and a file upload box will pop up;
rz
- Download the file and enter the following command
XShell
to pop up the file save box;
sz fileName
Software installation and management
rpm
RPM is
Red-Hat Package Manager
the abbreviation, a general package management method under Linux, which can be used to install and manage.rpm
packages ending with it.
- Install the package:
rpm -ivh nginx-1.12.2-2.el7.x86_64.rpm
- Fuzzy search packages:
rpm -qa | grep nginx
- Find the exact package:
rpm -qa nginx
- Query the installation path of the package:
rpm -ql nginx-1.12.2-2.el7.x86_64
- To view summary information about the package:
rpm -qi nginx-1.12.2-2.el7.x86_64
- Verify that the package contents and installation files are consistent:
rpm -V nginx-1.12.2-2.el7.x86_64
- Update packages:
rpm -Uvh nginx-1.12.2-2.el7.x86_64
- Remove packages:
rpm -e nginx-1.12.2-2.el7.x86_64
yum
Yum is
Yellow dog Updater, Modified
the abbreviation. It can automatically download and install RPM packages online. It can automatically handle dependencies and install all dependent packages at one time, which is very convenient!
- Install the package:
yum install nginx
- Check for packages that can be updated:
yum check-update
- Update the specified package:
yum update nginx
- Find package information in the repository:
yum info nginx*
- List all installed packages:
yum info installed
- List package names:
yum list nginx*
- Fuzzy search packages:
yum search nginx
User Management
View user information
- View user information:
cat /etc/passwd
- The user information format is as follows (password filtered):
# 用户名:密码:用户标识号:组标识号:组注释性描述:主目录:默认shell
root:x:0:0:root:/root:/bin/bash
macro:x:1000:982:macro:/home/macro:/bin/bash
- View user group information:
cat /etc/group
- The format of user group information is as follows:
# 组名:密码:组标识号:组内用户列表
root:x:0:
docker:x:982:macro,andy
passwd
For setting user password:
passwd root
his
Change user identity (switch to superuser):
# 切换到root用户
su -
# 切换到macro用户
su macro
groupadd
To add a user group, use -g
the flag number that can set the user group:
groupadd -g 1024 macrozheng
groupdel
Delete user group:
groupdel macrozheng
useradd
Add a user, -u
set the flag number, and -g
set the main user group:
useradd -u 1024 -g macrozheng macro
usermod
Modify the user group to which the user belongs:
usermod -g docker macro
userdel
To delete a user, use -r
to delete the user home directory:
userdel macro -r