史上最经典的Linux基础知识整理!
卖萌控的博客
点击这里进入电脑版页面!体验更好
史上最经典的Linux基础知识整理!
2022-10-2 萌小白


培训目的



通过本次培训,对Linux操作系统有一个初步的了解,掌握Linux操作系统的相关基础知识及一些常用的命令,并对系统进行日常的维护。



02



课程目标




文件类型



文件结构



文件目录权限




linux系统介绍



Linux是一套免费使用和自由传播的类Unix操作系统,是一个多用户、多任务、多线程、多CPU的操作系统,它能运行主要的UNIX工具软件、应用程序和网络协议,它支持32位和64位硬件。Linux继承了Unix以网络为核心的设计思想,是一个性能稳定的多用户网络操作系统。



Linux操作系统诞生于1991 年10 月5
日(这是第一次正式向外公布时间)。Linux可安装在各种计算机硬件设备中,比如手机、平板电脑、路由器、视频游戏控制台、台式计算机、大型机和超级计算机。Linux存在着许多不同的Linux版本,但它们都使用了Linux内核。



Linux存在着许多不同的Linux版本,但它们都使用了Linux内核,系统操作命令基本一样,内部模块稍有不同,如ORACLE Linux,内部就增加对ORACLE数据库的支持,很多操作系统层面的参数已按常规做了预先配置。



常用的Linux版本如下:






登录Linux



Linux是一个真正的多用户操作系统,允许多个用户同时登录



root是linux权限最大的用户,可以执行一切操作,包括删除操作系统本身!



Linux主要系统分区







所有的目录、文件、设备都在/之下,/就是Linux文件系统的组织者,也是最上级的领导者。




该目录放置系统内核及驱动模块引导程序,需要独立分区




类似于Windows的虚拟内存,就是当内存不足的时候,把一部分硬盘空间虚拟成内存使用,操作系 统先把内存中暂时不用的数据,存到硬盘的交换空间,腾出内存来让别的程序运行,从而解决内存容量不足的情况。



SWAP SPACE比内存要慢



在安装时,系统会尝试将交换分区安装到磁盘外端



当有多个磁盘控制器时,在每个磁盘上都建立交换分区



尽量将交换分区安装在访问最频繁的数据区附近



[root@OEL64 ~]# df -h



Filesystem Size Used Avail Use% Mounted on



/dev/sda3 19G 12G 5.3G 70% / --根分区



tmpfs 758M 88K 757M 1% /dev/shm



/dev/sda1 97M 68M 25M 74% /boot --引导分区



[root@OEL64 ~]# free -m



total used free shared buffers cached



Mem: 1514 339 1174 0 101 124



-/+ buffers/cache: 113 1400



Swap: 1535 0 1535 --交换分区



文件类型



在linux中,所有东西都被当成文件



文件权限前的第一个字母用来标识文件类型:



-:一般文件



d:目录文件



b:块设备文件



c:字符设备文件



l:连接文件



s:socket文件



[oracle@OEL64 dev]$ ls -al



-rw-r--r--. 1 root root 883Apr 30 2012 zshrc



drwxr-xr-x. 3 root root 60Sep 22 11:16 bus



brw-rw----.1 root floppy 2, 0Sep 22 11:16 fd0



crw-rw----. 1 root video 10, 175Sep 22 11:16 agpgart



lrwxrwxrwx. 1 root root 3Sep 22 11:16 cdrom -> sr0



srw-rw-rw-. 1 root root 0Sep 22 11:16 log



文件特点



Linux将每个文件系统mount在系统目录树中使用。



文件区分大小写。



文件以”.”开头的文件为隐含文件



文件名称最多255个字符(所有字符有效,正斜杠除外)



[oracle@OEL64 ~]$ ls -al



total 152



drwx------. 26 oracle oinstall 4096 Sep 19 15:59 .



drwxr-xr-x. 6 root root 4096 Jun 27 2013 ..



-rw-r--r--. 1 oracle oinstall 685 Sep 18 17:35 .bash_profile



文件结构




文件目录权限



文件或目录的权限位由10位构成,如-rwxr-xr-x。




例如:



-rwxr-xr-x表示这是个普通文件,文件的所有者可以读、写、执行这个文件



,与文件



常用文件介绍




系统初始化配置文件,init进程需要读取的文件,init进程是所有进程的起点。




定时任务配置文件




用户配置文件、用户密码配置文件




用户组配置文件




网络配置文件




系统错误信息




服务与端口信息



常用的linux命令





以/开头的完整的路径



[oracle@OEL64 oracle]$ cd /u01/app/oracle



[oracle@OEL64 oracle]$ pwd



/u01/app/oracle




不以/开头,只相对于当前工作目录



[oracle@OEL64 oracle]$ cd /u01/app



[oracle@OEL64 app]$ cd ./oracle



[oracle@OEL64 oracle]$ pwd



/u01/app/oracle




[root@OEL64 tmp]# cd /u01/app/oracle



[root@OEL64 oracle]# pwd



/u01/app/oracle



[root@OEL64 oracle]# cd ..



[root@OEL64 app]# pwd



/u01/app




[root@OEL64 app]# pwd



/u01/app



[root@OEL64 app]# cd ./oracle



[root@OEL64 oracle]# pwd



/u01/app/oracle




[oracle@OEL64 oracle]$ cd /u01/app/oracle



[oracle@OEL64 oracle]$ pwd



/u01/app/oracle




[oracle@OEL64 oracle]$ pwd



/u01/app/oracle



[oracle@OEL64 oracle]$ cd /etc



[oracle@OEL64 app]$ pwd



/etc




[root@OEL64 u01]# ls -al



total 28



drwxrwxr-x. 4 oracle oinstall 4096 Sep 19 10:44 .



dr-xr-xr-x. 25 root root 4096 Sep 22 11:16 ..



drwxrwxr-x. 4 oracle oinstall 4096 Sep 19 10:45 app



drwxrwxr-x. 2 oracle oinstall 16384 Sep 19 09:33 lost+found




[root@OEL64 oracle]# cp /home/oracle/a.txt /tmp/.



[root@OEL64 oracle]# cd /tmp



[root@OEL64 tmp]# ls -al a.txt



-rw-r--r--. 1 root root 0 Sep 22 16:27 a.txt




[root@OEL64 tmp]# mv /tmp/b.txt /home/oracle/.



[root@OEL64 tmp]# cd /home/oracle



[root@OEL64 oracle]# ls -al b.txt



-rw-r--r--. 1 root root 0 Sep 22 16:30 b.txt




[root@OEL64 hanxi]# cd /tmp



[root@OEL64 tmp]# touch c.txt



[root@OEL64 tmp]# ls -al c.txt



-rw-r--r--. 1 root root 0 Sep 22 16:36 c.txt




[root@OEL64 tmp]# file c.txt



c.txt: ASCII text




[root@OEL64 bin]# cd /tmp



[root@OEL64 tmp]# rm c.txt



rm: remove regular file `c.txt'? Y



注意:此操作慎重使用,特别对于rm –rf,文件和目录一并删除的操作!!




[root@OEL64 tmp]# mkdir test



[root@OEL64 tmp]# ls -al



total 108



drwxrwxrwt. 26 root root 4096 Sep 22 16:45 .



dr-xr-xr-x. 25 root root 4096 Sep 22 11:16 ..



drwxr-xr-x. 2 root root 4096 Sep 22 16:45 test




[root@OEL64 tmp]# cd /tmp



[root@OEL64 tmp]# rmdir test



[root@OEL64 tmp]# ls -al test



ls: cannot access test: No such file or directory




[root@OEL64 tmp]# cat /tmp/alert.log




[root@OEL64 tmp]# more /tmp/alert.log




[root@OEL64 tmp]# less /tmp/alert.log




[root@OEL64 tmp]# date



Fri Sep 22 17:03:47 CST 2017




[root@OEL64 tmp]# cal



September 2017



Su Mo Tu We Th Fr Sa



1 2



3 4 5 6 7 8 9



10 11 12 13 14 15 16



17 18 19 20 21 22 23



24 25 26 27 28 29 30




[root@OEL64 tmp]# head -5 alert.log



Tue Sep 19 13:04:31 2017



Starting ORACLE instance (normal)



LICENSE_MAX_SESSION = 0



LICENSE_SESSIONS_WARNING = 0



Shared memory segment for instance monitoring created




[root@OEL64 tmp]# tail -5 alert.log



Completed: ALTER DATABASE OPEN



Fri Sep 22 16:55:43 2017



Starting background process CJQ0



Fri Sep 22 16:55:43 2017



CJQ0 started with pid=22, OS id=5644




[root@OEL64 /]# find /tmp -name alert.log



/tmp/alert.log




[root@OEL64 /]# cd /tmp



[root@OEL64 tmp]# ls -al *.txt



-rw-r--r--. 1 root root 0 Sep 22 16:27 a.txt



[root@OEL64 tmp]# ls -al *.txt|wc -l



1




[root@OEL64 tmp]# ls -l a1.txt



-rw-r--r--. 1 root root 0 Sep 28 16:45 a1.txt



[root@OEL64 tmp]# chmod +x a1.txt



[root@OEL64 tmp]# ls -l a1.txt



-rwxr-xr-x. 1 root root 0 Sep 28 16:45 a1.txt




[root@OEL64 tmp]# clear




[root@OEL64 tmp]# ls -l a.txt



-rw-r--r--. 1 root root 0 Sep 22 16:27 a.txt



[root@OEL64 tmp]# chown oracle:oinstall a.txt



[root@OEL64 tmp]# ls -l a.txt



-rw-r--r--. 1 oracle oinstall 0 Sep 22 16:27 a.txt




[root@OEL64 hanxi]# diff a.txt b.txt



2d1



< bbbbbbbbbbbbbbbbbbbbbbbbbbbbb




[root@OEL64 hanxi]# ps -ef |grep ora



oracle 5543 1 0 16:55 ? 00:00:00 ora_dbrm_orcl



oracle 5545 1 0 16:55 ? 00:00:00 ora_dia0_orcl



oracle 5547 1 0 16:55 ? 00:00:04 ora_mman_orcl



oracle 5549 1 0 16:55 ? 00:00:01 ora_dbw0_orcl




[root@OEL64 dev]# mount /dev/cdrom



[root@OEL64 dev]# cd /mnt/cdrom




[root@OEL64 dev]# su - oracle



[oracle@OEL64 ~]$ echo $ORACLE_HOME



/u01/app/oracle/product/11.2.0/db_1




[root@OEL64 tmp]# whoami



root




[root@OEL64 dev]# whereis gzip



gzip: /bin/gzip /usr/bin/gzip /usr/share/man/man1/gzip.1.gz



[root@OEL64 dev]# which gzip



/bin/gzip




[root@OEL64 dev]# su - oracle



[oracle@OEL64 ~]$ id



uid=54321(oracle) gid=54321(oinstall) groups=54321(oinstall),54322(dba)




[root@OEL64 dev]# kill -9 30247




[root@OEL64 dev]# passwd oracle



Changing password for user oracle.



New password:



Retype new password:



passwd: all authentication tokens updated successfully.




[root@OEL64 dev]# history



50 cd /mnt



51 ls



!! 重复执行最近一次的命令




[root@OEL64 tmp]# gzip alert.log



[root@OEL64 tmp]# ls -ltr



total 76



-rw-r-----. 1 root root 5997 Sep 22 16:57 alert.log.gz



[root@OEL64 tmp]# gunzip alert.log.gz



[root@OEL64 tmp]# ls -al



total 144



drwxrwxrwt. 25 root root 4096 Sep 22 17:44 .



dr-xr-xr-x. 25 root root 4096 Sep 22 11:16 ..



-rw-r-----. 1 root root 37568 Sep 22 16:57 alert.log




[root@OEL64 tmp]# bzip2 alert.log



[root@OEL64 tmp]# ls -al



total 112



drwxrwxrwt. 25 root root 4096 Sep 22 17:45 .



dr-xr-xr-x. 25 root root 4096 Sep 22 11:16 ..



-rw-r-----. 1 root root 6594 Sep 22 16:57 alert.log.bz2



[root@OEL64 tmp]# bunzip2 alert.log.bz2



[root@OEL64 tmp]# ls -al



total 144



drwxrwxrwt. 25 root root 4096 Sep 22 17:46 .



dr-xr-xr-x. 25 root root 4096 Sep 22 11:16 ..



-rw-r-----. 1 root root 37568 Sep 22 16:57 alert.log




[root@OEL64 tmp]# pwd



/tmp



[root@OEL64 tmp]# ls -al *log*



-rw-r-----. 1 root root 37568 Sep 22 16:57 alert.log



-rw-r--r--. 1 root root 40960 Sep 28 16:09 alert.log.tar




[root@OEL64 tmp]# pwd



/tmp



[root@OEL64 tmp]# ls a.t?t



a.txt




[root@OEL64 tmp]# ls -l a[1-2].txt



-rw-r--r--. 1 root root 0 Sep 28 16:45 a1.txt



-rw-r--r--. 1 root root 0 Sep 28 16:45 a2.txt




[root@OEL64 log]# su - oracle



[oracle@OEL64 ~]$ exit



logout



[root@OEL64 log]#




[[oracle@OEL64 ~]$ export ORACLE_BASE=/u01/app/oracle



[oracle@OEL64 ~]$ echo $ORACLE_BASE



/u01/app/oracle




[root@OEL64 log]# ps -ef |grep ora



oracle 5343 1 0 14:36 ? 00:00:00 ora_pmon_orcl



oracle 5345 1 0 14:36 ? 00:00:00 ora_psp0_orcl



oracle 5348 1 3 14:36 ? 00:00:01 ora_vktm_orcl



oracle 5352 1 0 14:36 ? 00:00:00 ora_gen0_orcl



oracle 5354 1 0 14:36 ? 00:00:00 ora_diag_orcl




[root@OEL64 log]# rpm -qa|grep mysql



mysql-server-5.1.66-2.el6_3.i686



mysql-connector-odbc-5.1.5r1144-7.el6.i686



qt-mysql-4.6.2-26.el6_4.i686



mysql-connector-java-5.1.17-6.el6.noarch




[root@OEL64 log]# fdisk -l



255 heads, 63 sectors/track, 3916 cylinders



Sector size (logical/physical): 512 bytes / 512 bytes



I/O size (minimum/optimal): 512 bytes / 512 bytes



Disk identifier: 0x0000786a



Device Boot Start End Blocks Id System



Partition 1 does not end on cylinder boundary.



Partition 2 does not end on cylinder boundary.




top - 14:42:55 up 3:56, 1 user, load average: 0.58, 0.60, 0.36



Tasks: 144 total, 1 running, 142 sleeping, 1 stopped, 0 zombie



Cpu0 : 0.3%us, 0.7%sy, 0.0%ni, 99.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st



PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND



5348 oracle -2 0 774m 13m 11m S 1.0 0.9 0:04.66 oracle



5485 root 20
0 0 0 0 S 0.3 0.0 0:00.07 kworker/0:1 5516 root 20 0 2752 1040 780 R
0.3 0.1 0:00.08 top 1 root 20 0 2948 1440 1224 S 0.0 0.1 0:01.20 init




shutdown -r now 关机重启



shutdown -h now 关机并关闭电源




init 0 关机



init 1 重启




[root@OEL64 tmp]# man ls




[root@OEL64 tmp]# ls --help



Usage: ls [OPTION]... [FILE]...



。。。




[root@OEL64 tmp]# info ls



File: coreutils.info, Node: ls invocation, Next: dir invocation, Up: Directo\



ry listing



Vi编辑器的使用







浏览、删除、剪贴、查找等



可以用各种命令进入插入模式




输入新文档



用<ESC>退出插入模式回命令模式





:w 保存当前文件



:q 如果未对文件做改动则退出



:wq 保存当前文件并退出



:q! 不保存强制退出



:e 文件名 打开另一文件并开始编辑



用户和组的管理




groupadd –g 540 dba




groupdel dba




useradd -u 541 -g dba -s /bin/bash oracle



默认创建的用户将会在/home下为该用户创建一个目录,为用户的home目录




userdel oracle



网络管理




[root@OEL64 log]# ifconfig –a



eth4 Link encap:Ethernet HWaddr 00:0C:29:5B:AC:23



inet addr:172.21.110.51 Bcast:172.21.110.255 Mask:255.255.255.0



inet6 addr: fe80::20c:29ff:fe5b:ac23/64 Scope:Link



UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1



RX packets:19405 errors:0 dropped:211 overruns:0 frame:0



TX packets:3435 errors:0 dropped:0 overruns:0 carrier:0



collisions:0 txqueuelen:1000



Interrupt:19 Base address:0x2024



lo Link encap:Local Loopback



inet addr:127.0.0.1 Mask:255.0.0.0



inet6 addr: ::1/128 Scope:Host



UP LOOPBACK RUNNING MTU:16436 Metric:1



RX packets:8 errors:0 dropped:0 overruns:0 frame:0



TX packets:8 errors:0 dropped:0 overruns:0 carrier:0



collisions:0 txqueuelen:0



RX bytes:452 (452.0 b) TX bytes:452 (452.0 b)




[root@OEL64 log]# cat /etc/sysconfig/network-s/ifcfg-eth4



DEVICE=eth4



IPADDR=172.21.110.51



NETMASK=255.255.255.0



GATEWAY=172.21.110.1



ONBOOT=yes



NAME=eth4



HWADDR=00:0C:29:5B:AC:23




[root@OEL64 log]# netstat –antp



Active Internet connections (servers and established)



Proto Recv-Q Send-Q Local Address Foreign Address State PID/Program name



tcp 0 0 0.0.0.0:22 0.0.0.0:* LISTEN 2313/sshd



tcp 0 0 127.0.0.1:631 0.0.0.0:* LISTEN 2161/cupsd



tcp 0 0 127.0.0.1:25 0.0.0.0:* LISTEN 2561/master



tcp 0 0 0.0.0.0:30368 0.0.0.0:* LISTEN 2040/rpc.statd



tcp 0 0 0.0.0.0:111 0.0.0.0:* LISTEN 1962/rpcbind



tcp 0 0 172.21.110.51:22 172.21.110.50:63025 ESTABLISHED 2880/sshd



tcp 0 0 :::22 :::* LISTEN 2313/sshd



tcp 0 0 ::1:631 :::* LISTEN 2161/cupsd



tcp 0 0 ::1:25 :::* LISTEN 2561/master



tcp 0 0 :::13993 :::* LISTEN 2040/rpc.statd



tcp 0 0 :::111 :::* LISTEN 1962/rpcbind




[root@OEL64 log]# ping 172.21.110.50



PING 172.21.110.50 (172.21.110.50) 56(84) bytes of data.



64 bytes from 172.21.110.50: icmp_seq=1 ttl=128 time=0.322 ms



64 bytes from 172.21.110.50: icmp_seq=2 ttl=128 time=0.335 ms



64 bytes from 172.21.110.50: icmp_seq=3 ttl=128 time=0.321 ms



64 bytes from 172.21.110.50: icmp_seq=4 ttl=128 time=0.333 ms



64 bytes from 172.21.110.50: icmp_seq=5 ttl=128 time=0.334 ms



64 bytes from 172.21.110.50: icmp_seq=6 ttl=128 time=0.332 ms



64 bytes from 172.21.110.50: icmp_seq=7 ttl=128 time=0.298 ms



64 bytes from 172.21.110.50: icmp_seq=8 ttl=128 time=0.343 ms



64 bytes from 172.21.110.50: icmp_seq=9 ttl=128 time=0.317 ms



登录Linux系统的常用工具










Linux系统性能监控工具介绍








  • Nagios工具




  • cacti工具



发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容