rz上传-sz下载文件:
[root@localhost ~]# rz -y
[root@localhost ~]# ls
anaconda-ks.cfg toonmecom_58c791.png
[root@localhost ~]# sz -y toonmecom_58c791.png
[root@localhost ~]#
[root@localhost ~]#
tree查看目录结构:
tree -L 1:只显示一层目录
tree -d :只显示目录
创建目录:
[root@localhost ~]# mkdir cc
[root@localhost ~]# ls
anaconda-ks.cfg cc
[root@localhost ~]# mkdir -p 1/{2,3,4,5}/{6,7,8,9}
[root@localhost ~]# ls
1 anaconda-ks.cfg cc
[root@localhost ~]# tree 1
1
├── 2
│ ├── 6
│ ├── 7
│ ├── 8
│ └── 9
├── 3
│ ├── 6
│ ├── 7
│ ├── 8
│ └── 9
├── 4
│ ├── 6
│ ├── 7
│ ├── 8
│ └── 9
└── 5
├── 6
├── 7
├── 8
└── 9
20 directories, 0 files
touch:创建文件
[root@localhost ~]# touch test
[root@localhost ~]# ls
anaconda-ks.cfg test
stat:
- 查看文件属性(大小、最近访问时间、最近修改时间、文件状态最近更改时间(属性、大小、权限))
[root@localhost ~]# stat test
File: ‘test’
Size: 0 Blocks: 0 IO Block: 4096 regular empty file
Device: fd00h/64768d Inode: 34191223 Links: 1
Access: (0644/-rw-r--r--) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2023-04-16 08:08:54.279402926 -0400
Modify: 2023-04-16 08:08:54.279402926 -0400
Change: 2023-04-16 08:08:54.279402926 -0400
Birth: -
ls:查看目录内容:
[root@localhost ~]# ls .
anaconda-ks.cfg test
cp:复制文件或目录或者重命名
[root@localhost ~]# ls
anaconda-ks.cfg test
[root@localhost ~]# cp test /tmp/
[root@localhost ~]# ls /tmp/
test yum.log
[root@localhost ~]# mkdir te
[root@localhost ~]# ls
anaconda-ks.cfg te test
[root@localhost ~]# cp -rp te /tmp/
[root@localhost ~]# ls /tmp/
te test yum.log
[root@localhost ~]# cp test test01
[root@localhost ~]# ls
anaconda-ks.cfg te test test01
alias:别名(临时)
[root@localhost ~]# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'
[root@localhost ~]# alias test='cat /etc/sysconfig/network-scripts/ifcfg-eth0'
[root@localhost ~]# test
TYPE=Ethernet
BOOTPROTO=static
DEFROUTE=yes
PEERDNS=yes
PEERROUTES=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=yes
IPV6_DEFROUTE=yes
IPV6_PEERDNS=yes
IPV6_PEERROUTES=yes
IPV6_FAILURE_FATAL=no
IPV6_ADDR_GEN_MODE=stable-privacy
NAME=eth0
DEVICE=eth0
ONBOOT=yes
永久生成:
[root@localhost ~]# echo "alias test='cat /etc/sysconfig/network-scripts/ifcfg-eth0'" >> ~/.bashrc
history:历史记录
[root@localhost ~]# history -c
[root@localhost ~]# history
1 history
[root@localhost ~]#
[root@localhost ~]# cat /etc/selinux/config
# This file controls the state of SELinux on the system.
# SELINUX= can take one of these three values:
# enforcing - SELinux security policy is enforced.
# permissive - SELinux prints warnings instead of enforcing.
# disabled - No SELinux policy is loaded.
SELINUX=disabled
# SELINUXTYPE= can take one of three two values:
# targeted - Targeted processes are protected,
# minimum - Modification of targeted policy. Only selected processes are protected.
# mls - Multi Level Security protection.
SELINUXTYPE=targeted
[root@localhost ~]# history
1 history
2 cat /etc/selinux/config
3 history
[root@localhost ~]# history -d 2
[root@localhost ~]# history
1 history
2 history
3 history -d 2
4 history
[root@localhost ~]#
查看系统版本:
[root@localhost ~]# cat /etc/redhat-release
CentOS Linux release 7.3.1611 (Core)
查看内核信息:
[root@localhost ~]# uname -r
3.10.0-514.el7.x86_64
查看、修改主机名:
[root@localhost ~]# hostname
localhost.localdomain
[root@localhost ~]# uname -n
localhost.localdomain
[root@localhost ~]# hostnamectl set-hostname Test_7
[root@localhost ~]# exit
logout
[root@test_7 ~]# hostname
test_7
[root@test_7 ~]# uname -n
test_7
查看cup信息:
[root@test_7 ~]# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 165
model name : Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
stepping : 2
microcode : 0xc6
cpu MHz : 2591.622
cache size : 12288 KB
physical id : 0
siblings : 1
core id : 0
cpu cores : 1
apicid : 0
initial apicid : 0
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch arat fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1
bogomips : 5184.00
clflush size : 64
cache_alignment : 64
address sizes : 45 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 165
model name : Intel(R) Core(TM) i7-10750H CPU @ 2.60GHz
stepping : 2
microcode : 0xc6
cpu MHz : 2591.622
cache size : 12288 KB
physical id : 2
siblings : 1
core id : 0
cpu cores : 1
apicid : 2
initial apicid : 2
fpu : yes
fpu_exception : yes
cpuid level : 22
wp : yes
flags : fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc eagerfpu pni pclmulqdq ssse3 fma cx16 pcid sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand hypervisor lahf_lm abm 3dnowprefetch arat fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid rdseed adx smap clflushopt xsaveopt xsavec xgetbv1
bogomips : 5184.00
clflush size : 64
cache_alignment : 64
address sizes : 45 bits physical, 48 bits virtual
power management:
查看内存信息:
[root@test_7 ~]# cat /proc/meminfo
MemTotal: 1867292 kB
MemFree: 1498552 kB
MemAvailable: 1602608 kB
Buffers: 7152 kB
Cached: 227244 kB
SwapCached: 0 kB
Active: 150728 kB
Inactive: 120288 kB
Active(anon): 36960 kB
Inactive(anon): 8340 kB
Active(file): 113768 kB
Inactive(file): 111948 kB
Unevictable: 0 kB
Mlocked: 0 kB
SwapTotal: 2097148 kB
SwapFree: 2097148 kB
Dirty: 0 kB
Writeback: 0 kB
AnonPages: 36564 kB
Mapped: 22712 kB
Shmem: 8680 kB
Slab: 42476 kB
SReclaimable: 18900 kB
SUnreclaim: 23576 kB
KernelStack: 3840 kB
PageTables: 3240 kB
NFS_Unstable: 0 kB
Bounce: 0 kB
WritebackTmp: 0 kB
CommitLimit: 3030792 kB
Committed_AS: 242048 kB
VmallocTotal: 34359738367 kB
VmallocUsed: 180208 kB
VmallocChunk: 34359310332 kB
HardwareCorrupted: 0 kB
AnonHugePages: 6144 kB
HugePages_Total: 0
HugePages_Free: 0
HugePages_Rsvd: 0
HugePages_Surp: 0
Hugepagesize: 2048 kB
DirectMap4k: 65408 kB
DirectMap2M: 2031616 kB
DirectMap1G: 0 kB
echo:显示输出
[root@test_7 ~]# echo "HelloWorld"
HelloWorld
[root@test_7 ~]# echo -e "Hello\tWorld"
Hello World
[root@test_7 ~]# echo -e "Hello\nWorld"
Hello
World
[root@test_7 ~]# echo "HelloWorld" >>test
[root@test_7 ~]# cat test
HelloWorld
[root@test_7 ~]# echo "HelloWorld" >>test
[root@test_7 ~]# cat test
HelloWorld
HelloWorld
[root@test_7 ~]# echo "Hello" ; echo "World"
Hello
World
[root@test_7 ~]# echo -n "Hello" ; echo "World"
HelloWorld
grep:过滤:
[root@test_7 ~]# ps -ef | grep sshd
root 1754 1 0 07:36 ? 00:00:00 /usr/sbin/sshd
root 2523 1754 0 08:25 ? 00:00:00 sshd: root@pts/0
root 2572 2525 0 08:32 pts/0 00:00:00 grep --color=auto sshd
#不区分大小写
[root@test_7 ~]# grep -i "World" test
HelloWorld
HelloWorld
Helloworld
#取反
[root@test_7 ~]# grep -v "world" test
HelloWorld
HelloWorld
#统计匹配的行数
[root@test_7 ~]# grep -c "world" test
1
#只显示匹配的内容
[root@test_7 ~]# grep -o "world" test
world
tr:替换或者删除字符,源文件不会改变
[root@test_7 ~]# tr "w" "L" <test
HelloWorld
HelloWorld
HelloLorld
[root@test_7 ~]# cat test
HelloWorld
HelloWorld
Helloworld
find:查找
[root@test_7 ~]# find /tmp/ -type f -name "test"
/tmp/test
[root@test_7 ~]# basename $(find /tmp/ -type f -name "test")
test
[root@test_7 ~]# ls -lh $(find /boot/ -type f -size "+20M" )
-rw-------. 1 root root 47M Apr 15 17:14 /boot/initramfs-0-rescue-7cd33356ef514d0b9069e22b49dae499.img
[root@test_7 ~]# find /tmp/ -type f -name test -exec rm -rf {} \;
[root@test_7 ~]# find /var/log/ -type f -name "boot.log*" -exec ls -l {} \;
-rw-r--r-- 1 root root 8234 Apr 16 07:35 /var/log/boot.log
[root@test_7 ~]# find /var/log/ -type f -name "boot.log*" | xargs -i ls -l {};
-rw-r--r-- 1 root root 8234 Apr 16 07:35 /var/log/boot.log
tar:打包目录
[root@test_7 ~]# tar -zcvf test.tar.gz test/
test/
test/1/
test/1/1/
test/1/2/
test/1/3/
test/1/4/
test/1/5/
test/1/6/
test/1/7/
test/1/8/
test/1/9/
test/1/10/
[root@test_7 ~]# ls
anaconda-ks.cfg test test.tar.gz
[root@test_7 ~]# tar xf test.tar.gz -C /tmp/
[root@test_7 ~]# ls /tmp/
test yum.log
date:时间
[root@test_7 ~]# date
Sun Apr 16 08:46:58 EDT 2023
[root@test_7 ~]# date +%F_%T
2023-04-16_08:47:14
查看用户密码文件:
[root@test_7 ~]# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
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
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
operator:x:11:0:operator:/root:/sbin/nologin
games:x:12:100:games:/usr/games:/sbin/nologin
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin
nobody:x:99:99:Nobody:/:/sbin/nologin
systemd-bus-proxy:x:999:997:systemd Bus Proxy:/:/sbin/nologin
systemd-network:x:192:192:systemd Network Management:/:/sbin/nologin
dbus:x:81:81:System message bus:/:/sbin/nologin
polkitd:x:998:996:User for polkitd:/:/sbin/nologin
tss:x:59:59:Account used by the trousers package to sandbox the tcsd daemon:/dev/null:/sbin/nologin
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
chrony:x:997:995::/var/lib/chrony:/sbin/nologin
useradd:创建用户
[root@test_7 ~]# useradd test
[root@test_7 ~]# echo "111" | passwd --stdin test
Changing password for user test.
passwd: all authentication tokens updated successfully.
[root@test_7 ~]# cat /etc/passwd | grep test
test:x:1000:1000::/home/test:/bin/bash
userdel:删除用户
[root@test_7 ~]# userdel -r test
[root@test_7 ~]# ls /home/
[root@test_7 ~]# cat /etc/passwd |grep test
[root@test_7 ~]#
更改创建用户时的家目录:
[root@test_7 ~]# cat /etc/default/useradd
# useradd defaults file
GROUP=100
HOME=/test
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
[root@test_7 ~]# mkdir /test
[root@test_7 ~]# useradd test01
[root@test_7 ~]# ls /test/
test01
[root@test_7 ~]# useradd -M -s /sbin/nologin test01
[root@test_7 ~]# cat /etc/passwd | grep test
test01:x:1000:1000::/test/test01:/sbin/nologin
查看inode总量:
[root@test_7 ~]# df -i
Filesystem Inodes IUsed IFree IUse% Mounted on
/dev/mapper/cl-root 8910848 56004 8854844 1% /
devtmpfs 230668 346 230322 1% /dev
tmpfs 233411 1 233410 1% /dev/shm
tmpfs 233411 423 232988 1% /run
tmpfs 233411 16 233395 1% /sys/fs/cgroup
/dev/sda1 524288 330 523958 1% /boot
tmpfs 233411 1 233410 1% /run/user/0
查看block总量,就是磁盘大小:
[root@test_7 ~]# df -h
Filesystem Size Used Avail Use% Mounted on
/dev/mapper/cl-root 17G 1.6G 16G 10% /
devtmpfs 902M 0 902M 0% /dev
tmpfs 912M 0 912M 0% /dev/shm
tmpfs 912M 8.5M 904M 1% /run
tmpfs 912M 0 912M 0% /sys/fs/cgroup
/dev/sda1 1014M 139M 876M 14% /boot
tmpfs 183M 0 183M 0% /run/user/0
硬链接、软连接:
#在同一个分区、文件系统中,具有相同的inode号的就是硬链接文件
[root@test_7 ~]# ln test test02
[root@test_7 ~]# ls -i
33574983 anaconda-ks.cfg 33626678 test 33626678 test02
#软连接
[root@test_7 ~]# ln -s test test03
[root@test_7 ~]# ls -i
33574983 anaconda-ks.cfg 33626678 test 33626678 test02 33626681 test03
charrt:文件属性
#文件不能删除、改名、写入、添加内容
[root@test_7 ~]# mv test test01
mv: cannot move ‘test’ to ‘test01’: Operation not permitted
[root@test_7 ~]# rm -rf test
rm: cannot remove ‘test’: Operation not permitted
[root@test_7 ~]# lsattr test
-----a---------- test
#文件不能删除,修改
[root@test_7 ~]# chattr +i test
[root@test_7 ~]# lsattr test
----i----------- test
[root@test_7 ~]# echo "11111" >> test
-bash: test: Permission denied
[root@test_7 ~]# rm -rf test
rm: cannot remove ‘test’: Operation not permitted