Linux notes 1-commonly used commands

Common system work commands

man view command format and parameters, etc.

man wc view wc command format

[root@bogon ~]# man wc
WC(1)                                            User Commands                                           WC(1)

NAME
       wc - print newline, word, and byte counts for each file

SYNOPSIS
       wc [OPTION]... [FILE]...
       wc [OPTION]... --files0-from=F

date View time

[root@bogon ~]# date "+%Y-%m-%d %H:%M:%S"
2020-10-19 10:28:29
[root@bogon ~]# date
Mon Oct 19 10:28:32 EDT 2020

wget downloads content from the network

[root@bogon ~]# wget www.baidu.com
--2020-10-19 10:29:55--  http://www.baidu.com/

elinks opens a plain text browser

Can browse and other operations like a browser

System status monitoring command

ifconfig

View network status information

uname

View system kernel, name, version, processor type, etc.

[root@bogon ~]# uname
Linux
[root@bogon ~]# uname -a
Linux bogon 3.10.0-1127.el7.x86_64 #1 SMP Tue Mar 31 23:36:51 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

If you want to see the detailed version information of the system, see the redhat-release file

[root@bogon ~]# cat /etc/redhat-release
CentOS Linux release 7.8.2003 (Core)

uptime is used to view the load of the system

The smaller the load value, the better

[root@bogon ~]# uptime
 10:43:02 up  8:31,  2 users,  load average: 0.00, 0.01, 0.05
[root@bogon ~]# watch -n 1 uptime
Every 1.0s: uptime                                                                       Mon Oct 19 10:43:37 2020

 10:43:37 up  8:32,  2 users,  load average: 0.00, 0.01, 0.05

free View content usage in the system

[root@bogon ~]# free
              total        used        free      shared  buff/cache   available
Mem:        3861300      215764     3307148        3692      338388     3422640
Swap:       2097148           0     2097148

who View the user status of the login person's host

[root@bogon ~]# who
root     tty1         2020-10-19 02:12
root     pts/0        2020-10-19 09:47 (192.168.204.1)

last view all system login records


[root@bogon ~]# last
root     pts/0        192.168.204.1    Mon Oct 19 09:47   still logged in   
root     pts/0        192.168.204.1    Mon Oct 19 02:33 - 06:59  (04:26)    
root     tty1                          Mon Oct 19 02:12   still logged in   

history view executed commands

[root@bogon ~]# history
    1  ls
    2  ping www.baidu.co
    3  ping www.baidu.com
    4  curl www.baidu.com
    5  ifconfig
    6  ping 192.168.204.0
    7  ping 192.168.154.0

History commands will be saved in the .bash_history directory of the user's directory,
clear the user's local command record history -c

Directory switching and file viewing commands

cd switch directory

pwd print current working path

ls View which files are in the directory

[root@bogon ~]# ls
anaconda-ks.cfg  index.html  res.txt  root  root.tar.gz  test  test2.txt  test.txt  tstd
[root@bogon ~]# pwd
/root
[root@bogon ~]# cd ..
[root@bogon /]# pwd
/

more View longer files

more -2 test.txt View test.txt and show 2 lines in advance

[root@bogon ~]# more -2 test.txt 
df
asdf

head View the first * line of the file

[root@bogon ~]# head -10 test.txt
df
asdf
adf
asdsf
a

tail displays the file after * line

[root@bogon ~]# tail -n 10 -f  test.txt
a
df

od View number format file

[root@bogon ~]# od -t c test.txt
0000000   d   f  \n   a   s   d   f  \n   a   d   f  \n   a   s   d   s
0000020   f  \n   a  \n   d   f  \n   a  \n   d   f  \n   a  \n   d   f
[root@bogon ~]# od -t o test.txt  --八进制
0000000 14102463144 01231462163 01231462141 16331071541
0000020 01230205146 14102463144 01231462012 14631005141
[root@bogon ~]# od -t x test.txt       //16进制
0000000 610a6664 0a666473 0a666461 73647361
0000020 0a610a66 610a6664 0a66640a 66640a61

tr command is used to convert characters in text files

Convert lowercase to uppercase in the contents of the file as follows

[root@bogon ~]# cat test.txt|tr [a-z] [A-Z]
DF
ASDF
ADF
ASDSF
A

wc counts the number of lines, words, bytes, etc. of the file

[root@bogon ~]# wc -c res.txt  --统计字节长度 
767 res.txt
[root@bogon ~]# wc -w res.txt -- 统计单词数
25 res.txt
[root@bogon ~]# wc -l res.txt    -- 统计行数
16 res.txt
[root@bogon ~]# wc -L res.txt   -- 最长行的 长度
68 res.txt

diff compares the difference between two files

[root@bogon ~]# diff test.txt test2.txt
2c2
< asdf
---
> asdfdd
5c5

File and directory management

touch tmpfile creates a blank file

touch -d "2 days ago" tmpfile  修改文件的操作时间
[root@bogon ~]# mkdir -m755 -p -v tmpdir/dir1/dir2/dir3/dir4
mkdir: created directory ‘tmpdir/dir1/dir2/dir3/dir4’创建多级目录 tmpdir/dir1/dir2/dir3/dir4
[root@bogon ~]# cd !$   //!$ 代表上一条命令的参数
cd tmpdir/dir1/dir2/dir3/dir4  

cp copy file or directory
mv move file or directory
rm delete file or directory -r delete folder -f pre-delete without prompt message -i ask
rmdir before delete delete empty directory
dd command is used to copy file format of specified size dd [ parameter]

User and user group management

useradd [options] user name is used to create a new user
id user name user id
passwd [user name] set user password
userdel delete all user forms -f force delete users, directories and files -r delete users, directories and files at the same time
usermod modify User attribute
groupadd is used to create groups

[root@bogon ~]# useradd hadoop
[root@bogon ~]# id hadoop
uid=1000(hadoop) gid=1000(hadoop) groups=1000(hadoop)
[root@bogon ~]# passwd hadoop
Changing password for user hadoop.
New password: 
BAD PASSWORD: The password is shorter than 8 characters
Retype new password: 
passwd: all authentication tokens updated successfully.
[root@bogon ~]# userdel -rf hadoop
[root@bogon ~]# useradd hadoop
[root@bogon ~]# id hadoop
uid=1000(hadoop) gid=1000(hadoop) groups=1000(hadoop)
[root@bogon ~]# usermod -g root hadoop
[root@bogon ~]# id hadoop
uid=1000(hadoop) gid=0(root) groups=0(root)
groupadd group1

Pack and compress commands

The tar command is used to pack and compress or decompress
tar [options] [files]

[root@bogon ~]# tar -zvcf  tmpdir.tar.gz tmpdir  压缩
 [root@bogon ~]# tar -zvxf tmpdir.tar.gz    解压

File query search command

grep to search text content

grep /sbin/nologin /etc/passwd Search for lines that appear in the string /sbin/nologin in
/etc/passwd grep /sbin/nologin /etc/passwd >> res.txt Write the search results to the res.txt file

[root@bogon ~]# grep /sbin/nologin /etc/passwd
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
......
[root@bogon ~]# 

find file search

find [search path] Find condition operation
find /etc -name "host*" -print Search all files beginning with host in the /etc directory

[root@bogon ~]# find /etc -name "host*" -print
/etc/host.conf
/etc/hosts
/etc/hosts.allow
....

Pipe operator

The function of the pipe operator "|" is to use the standard output of the previous command as the standard input of the next command, format: command a|command b
grep /sbin/nologin /etc/passwd | wc -l from the /etc/passwd file Find the line containing /sbin/nologin and count the number of lines

[root@bogon ~]# grep /sbin/nologin /etc/passwd | wc -l 
16

Guess you like

Origin blog.csdn.net/zhangxm_qz/article/details/109215691