Linux基本操作
本章内容根据学习程度持续更新完善!!!(更新频率:暂定这几周更新每两天更新!!!加油)
1、Linux基本操作
文件操作:
1、文件的显示
ls:显示当前目录下的文件和目录
ls -a:显示当前目录下的所有文件和目录,包括隐藏文件和目录。
ls -l:显示当前目录下文件盒目录的详细信息。
ls -h:以合适的单位显示当前目录下的文件和目录的大小
ls -alh 或 ls -a -l -h:三者不分前后顺序
例:ls /bin:查看根目录下,bin文件夹里的所有内容;
2、目录的跳转
cd:打开某个文件夹,后跟文件夹名或文件夹的路径
cd - :跳转到上一次操作,只在最后两步之间来回跳转。
cd ~:跳转到当前路径的家目录下,例如/home/hadoop
pwd:显示当前的绝对路径
cd ..:跳转到当前路径的上一层
.:表示当前路径
..:当前路径的上一层
../../..:当前路径上三层
2、文件搜索
grep:从文件中搜索内容。
grep -n 't':显示所有带‘t’的内容,不区分大小写,显示行号
常用快捷键操作:
1、实用操作命令
CTRL+C :取消
Cntrl+D:中断
clear:清空当前的屏幕,只是将当前页面内容上移,并没有删除。
Tab:用来自动补全输入
touch:在当前文件夹中创建文件,Linux没有文件名后缀的形式,例test.txt只是一个文件名。
\:反斜杠,转义字符。例 ls *a 显示*a文件夹里的文件和目录
| (管道):连接两个命令。例 ls -alh|more
cat:查看文件内容,如果文件内容较多,可用鼠标滚珠查看,一扫而过。
cat 文件名 > 文件名:实现将文件的内容复制到另一个文件
cat 多个文件名 > 文件名:实现多个文件的合并。
cat /etc/motd : 登录后提示:
[22:57:21 root@centos8[ ~]# cat /etc/motd
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
佛祖保佑 iii 永不死机
[22:57:23 root@centos8[ ~]#
cat /etc/issue : 看文本文件
cat /proc/cpuinfo :跟lscpu一样查询当前设备CPU,不过显示更加详细
[23:01:33 root@centos8[ ~]#
[23:01:34 root@centos8[ ~]#lscpu
Architecture: x86_64
CPU op-mode(s): 32-bit, 64-bit
Byte Order: Little Endian
CPU(s): 4
On-line CPU(s) list: 0-3
Thread(s) per core: 1
Core(s) per socket: 2
Socket(s): 2
NUMA node(s): 1
Vendor ID: GenuineIntel
CPU family: 6
Model: 158
Model name: Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Stepping: 10
CPU MHz: 2592.001
BogoMIPS: 5184.00
Hypervisor vendor: VMware
Virtualization type: full
L1d cache: 32K
L1i cache: 32K
L2 cache: 256K
L3 cache: 12288K
NUMA node0 CPU(s): 0-3
Flags: fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush mmx fxsr sse sse2 ss ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc cpuid 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 cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xsaves arat flush_l1d arch_capabilities
[23:01:35 root@centos8[ ~]#cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 158
model name : Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
stepping : 10
microcode : 0xaa
cpu MHz : 2592.001
cache size : 12288 KB
physical id : 0
siblings : 2
core id : 0
cpu cores : 2
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 ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc cpuid 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 cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xsaves arat flush_l1d arch_capabilities
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf
bogomips : 5184.00
clflush size : 64
cache_alignment : 64
address sizes : 43 bits physical, 48 bits virtual
power management:
processor : 1
vendor_id : GenuineIntel
cpu family : 6
model : 158
model name : Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
stepping : 10
microcode : 0xaa
cpu MHz : 2592.001
cache size : 12288 KB
physical id : 0
siblings : 2
core id : 1
cpu cores : 2
apicid : 1
initial apicid : 1
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 ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc cpuid 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 cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xsaves arat flush_l1d arch_capabilities
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf
bogomips : 5184.00
clflush size : 64
cache_alignment : 64
address sizes : 43 bits physical, 48 bits virtual
power management:
processor : 2
vendor_id : GenuineIntel
cpu family : 6
model : 158
model name : Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
stepping : 10
microcode : 0xaa
cpu MHz : 2592.001
cache size : 12288 KB
physical id : 1
siblings : 2
core id : 0
cpu cores : 2
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 ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc cpuid 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 cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xsaves arat flush_l1d arch_capabilities
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf
bogomips : 5184.00
clflush size : 64
cache_alignment : 64
address sizes : 43 bits physical, 48 bits virtual
power management:
processor : 3
vendor_id : GenuineIntel
cpu family : 6
model : 158
model name : Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
stepping : 10
microcode : 0xaa
cpu MHz : 2592.001
cache size : 12288 KB
physical id : 1
siblings : 2
core id : 1
cpu cores : 2
apicid : 3
initial apicid : 3
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 ht syscall nx pdpe1gb rdtscp lm constant_tsc arch_perfmon nopl xtopology tsc_reliable nonstop_tsc cpuid 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 cpuid_fault invpcid_single pti ssbd ibrs ibpb stibp fsgsbase tsc_adjust bmi1 avx2 smep bmi2 invpcid mpx rdseed adx smap clflushopt xsaveopt xsavec xsaves arat flush_l1d arch_capabilities
bugs : cpu_meltdown spectre_v1 spectre_v2 spec_store_bypass l1tf
bogomips : 5184.00
clflush size : 64
cache_alignment : 64
address sizes : 43 bits physical, 48 bits virtual
power management:
[23:01:42 root@centos8[ ~]#
2、帮助文档
history:历史输入命令
--help:帮助文档
ls -help :查看ls命令的帮助
man ls :查看ls命令解释
man bash:可以通过man这个命令进入bash来查看集成在shell中的所有内部命令
which:查看命令的位置,例 which ls:查看ls命令所在的位置
3、查看日期
uptime:显示服务器运行时间
date:显示当前时间(ntp:网络时间协议)
date [MMDDhhmm[[yy]ss]]:格式化输出
date ‘+%Y-%m’ :格式化输出
4、进程控制
ps:查看进程信息,相当于任务管理器
ps -aux:显示所有正在运行的程序
-a:显示终端上的所有进程
-u:显示进程的详细状态
-x:显示没有控制终端的进程
-w:显示加宽以便显示更多信息
-r:只显示正在进行的进程
top:动态显示进程
m:内存,c:CPU等可按照属性的首字母排序
5、关机与重启
reboot:重启
shutdown -r now :立刻重启
shutdown -h now :立刻关机
shutdown -h 20:35 :八点三十五关机
shutdown -h +10 :十小时后关机
init 0 :关机
init 3 :登陆后进入控制台命令行模式
init 5:登陆后进入图形GUI模式
init 6 :重启
df :检查当前磁盘情况
du :显示当前路径下的所有文件的大小及路径
du -h :显示文件大小的单位
6、计算器:
bc:二进制转换,输入bc回车,输入obase=2回车,输入转换数字,这是2进制转换,ibase=8,是8进制转换:
[22:47:59 root@centos8[ ~]#bc
bc 1.07.1
Copyright 1991-1994, 1997, 1998, 2000, 2004, 2006, 2008, 2012-2017 Free Software Foundation, Inc.
This is free software with ABSOLUTELY NO WARRANTY.
For details type `warranty'.
obase=2
25
11001
obase=8
25566
10101101110110
^C
(interrupt) Exiting bc.
[22:48:49 root@centos8[ ~]#
字符命令:
.:跟source功能一样)
“”: 可以识别变量,不能识别命令
‘’: 变量和命令都不识别,都当成字符串
`` :变量和命令都识别,并且把单引号,并且会将反向单引号的内容当初命令执行后,再交给调用反 向单引号的命令继续
\ :可以实现转译(原本的意思是表示命令没结束)
$ () :变量
{ } : 等价于``