linux 笔记整理
linux环境搭建
安装linux
安装vmware-tools
1 获取安装包
vm -> install vmware-tools … -> filebox
VMwareTools-8.4.5-324285.tar.gz
2 复制
cp VMwareTools-8.4.5-324285.tar.gz /tmp
3 切换目录
cd /tmp
4 解压
tar -xvf VMwareTools-8.4.5-324285.tar.gz
5 进入解压目录
cd vmware-tools-distrib => entern
6 重启
init 6 or reboot
配置网络
windows => kening 11223344 => 192.168.0.113
linux => 192.168.0.254
查看linux ip 地址
[root@localhost ken]# ifconfig
重启网络服务
/etc/init.d/network restart
注意:
以下信息表示网络可以连接
[root@localhost ken]# ping 192.168.0.254 -c 3
PING 192.168.0.254 (192.168.0.254) 56(84) bytes of data.
64 bytes from 192.168.0.254: icmp_seq=1 ttl=64 time=0.034 ms
64 bytes from 192.168.0.254: icmp_seq=2 ttl=64 time=0.036 ms
64 bytes from 192.168.0.254: icmp_seq=3 ttl=64 time=0.042 ms
以下信息表示网络不通
[root@localhost ken]# ping 192.168.0.23 -c 3
PING 192.168.0.23 (192.168.0.23) 56(84) bytes of data.
From 192.168.0.254 icmp_seq=1 Destination Host Unreachable
From 192.168.0.254 icmp_seq=2 Destination Host Unreachable
From 192.168.0.254 icmp_seq=3 Destination Host Unreachable
如何ping不通注意两点
1 是否桥接
2 网卡是否启动或者驱动没有安装
system-config-network
3 网卡配置文件
# Advanced Micro Devices [AMD] 79c970 [PCnet32 LANCE]
#表示网卡名
DEVICE=eth0
#指定ip分配方式 static 表示静态 dhcp 表示动态
BOOTPROTO=static
#BOOTPROTO=dhcp
#MAC地址
HWADDR=00:0C:29:F9:9F:7C
#表示是否启动这张网卡
ONBOOT=yes
#表示默认子网掩码
NETMASK=255.255.255.0
#表示指定IP地址
IPADDR=192.168.0.254
#表示默认网关
GATEWAY=192.168.0.1
#表示网络协议
TYPE=Ethernet
====================================================
下载课件:
1 检测网络是否连接
ping
2 查看共享课件
[root@localhost ken]# showmount -e 192.168.0.254
Export list for 192.168.0.254:
/ken * 课件
/tools * 工具
/homework * 作业
3 挂载nfs共享目录
[root@localhost ken]# mount 192.168.0.254:/ken /mnt
查看挂在是否成功
[root@localhost ken]# df -h
文件系统 容量 已用 可用 已用% 挂载点
/dev/sda2 34G 15G 17G 48% /
/dev/sda1 99M 12M 83M 13% /boot
tmpfs 506M 0 506M 0% /dev/shm
/tools/rhel55.iso 2.9G 2.9G 0 100% /iso
df: “/mnt/hgfs”: 没有那个文件或目录
/dev/hdc 103M 103M 0 100% /media/VMware Tools
192.168.0.254:/ken 34G 15G 17G 48% /mnt
4 拷贝:
cp /mnt/1st.txt /tmp
5 解挂
umount /mnt
umount -l /mnt 强制解挂
上传作业:/homework
1 测试网络
2 查看共享文件
3 挂载
mount 192.168.0.254:/homework /mnt
4 拷贝
cp /254_张三/ /mnt -rf
5 解挂
远程登录
1 创建用户
useradd zhangsan
2 用户设定密码
passwd zhangsan
3 远程登录
ssh zhangsan@192.168.0.254
注意:
1 知道服务器用户名和密码
2 开启sshd服务
service sshd restart
桌面环境
1 打开终端 所有的操作都是在终端上进行
1> 鼠标右键 => 打开终端
2> alt + F2 => gnome-terminal
3> 应用程序 => 附件 => 终端
2 关闭
exit
3 一个终端打开多个标签
ctrl + shift + t
4 标签之间切换
alt + num(1, 2, 3 …)
5 放大字体
ctrl + shift + +
6 缩小字体
ctrl + -
7 最大化窗口
alt + F10
8 最小化
alt + F9
9 关机
init 0
halt -h now
10 重启
init 6
halt -r now
reboot
11 查看系统信息
[root@localhost ken]# uname -a
Linux localhost.localdomain 2.6.18-194.el5 #1 SMP Tue Mar 16 21:52:43
EDT 2010 i686 i686 i386 GNU/Linux
Linux : 表示内核
localhost.localdomain : 表示主机名
2.6.18-194.el5 :表示内核版本
2 :表示主版本号
6 :表示次版本号
奇数:测试版本
偶数:稳定版本
18:表示释放版本号
www.kernel.org
#1 SMP Tue Mar 16 21:52:43 EDT 2010 表示第一次发布之间
i686 i686 i386 : 表示32位系统平台
x86_64 : 表示64位
[root@localhost ken]# uname -m
i686
GNU/Linux 操作系统
查看系统版本
[root@localhost ken]# lsb_release -a
LSB Version:
:core-3.1-ia32:core-3.1-noarch:graphics-3.1-ia32:graphics-3.1-noarch
Distributor ID: RedHatEnterpriseServer
Description: Red Hat Enterprise Linux Server release 5.5
(Tikanga)
Release: 5.5
Codename: Tikanga
=============================================
文件目录介绍
所有文件都是从根开始
所有的设备皆文件
bin : 存放二进制可执行文件
proc: 保存执行一些进程编号
sys : 虚拟目录
selinux :安全包存放目录
/etc/selinux/config
SELINUX=disabled 表示禁用selinux安全包
boot :存放启动镜像文件目录
home :表示普通用户家目录
普通用户uid >= 500
区分用户唯一标识是通过用户uid
useradd zhangsan 表示创建用户
userdel -r zhangsan 表示删除用户
root :root用户家目录
/root/Desktop/ 表示桌面
lib :存放库文件
[root@localhost test]# ldd ./hello
linux-gate.so.1 => (0x00fa8000)
libc.so.6 => /lib/libc.so.6 (0x001f8000)
/lib/ld-linux.so.2 (0x001da000)
.so : 表示动态库
.a : 表示静态库
mnt :默认挂载目录
tmp :临时目录
dev :存放设备文件目录
字符设备: c
块设备: b
etc : 表示所有配置文件存放路径
media :默认挂在光盘 优盘目录
opt :扩张包存放目录
sbin :存放管理员命令
切换用户 su - username
[root@localhost /]# su tom
[tom@localhost /]$ id
uid=500(tom) gid=500(tom) groups=500(tom)
[tom@localhost /]$ echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin:/opt/FriendlyARM/toolschain/4.5.1/bin/
[root@localhost /]# su - tom
[tom@localhost ~]$ echo $PATH
/usr/kerberos/bin:/usr/local/bin:/bin:/usr/bin:/home/tom/bin
退出用户:exit
usr : 用户安装信息
=================================================
命令分类:
内部命令:就是shell(kernel)自带的一些命令,这些命令没有路径,则不可以卸载。
外部命令:就是用户自己安装一些命令。就会有路径,就可以被卸载
如何区分:
type + cmdname
[root@localhost /]# type cd
cd is a shell builtin 表示是一个内部命令
[root@localhost /]# type fdisk
fdisk is hashed (/sbin/fdisk) 表示是一个外部命令
[root@localhost /]# type ls
ls is aliased to `ls --color=tty' 表示ls是一个别名
[root@localhost /]# which ls 表示查看命令路径
alias ls='ls --color=tty'
/bin/ls
[root@localhost /]# which cd
/usr/bin/which: no cd in
(/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/usr/X11R6/bin:/root/bin:/opt/FriendlyARM/toolschain/4.5.1/bin/)
别名:
[root@localhost /]# alias lll='ls -l' 临时有效(当前终端)
永久有效
vim ~/.bashrc
i => ESC键 => :wq
添加如下一行
alias iii='ls -l'
配置信息生效
source ~/.bashrc
================================================
tab键:
自动补齐
1 命令
2 文件
/etc/sysconfig/network-scripts/ifcfg-eth0 网卡配置文件
================================================
man : 帮助命令
format : man + cmdname
案例:
man ls
案例:
man 3 printf
man的9本手册
1 Commands 表示基本命令
2 System calls 表示系统调用函数接口 sys
3 Library calls 表示C库 或者数学库 第三方图形库接口
4 Special files 表示特殊文件格式(字符设备和块设备)
5 File formats and conventions 表示配置文件格式说明文档
6 Games 表示游戏相关说明文档
7 Conventions and miscellaneous 表示网络相关说明文档
8 System management commands 表示系统管理员说明文档
9 Kernel routines 内核相关说明文档
退出:q
info :
help :
ls --help 外部命令
help cd 内部命令
内事不觉问百度 外事不觉问谷歌
ls : 显示目录相关文件或者目录
ls [option] … [filename | dirname] …
option:
-a : 表示显示所有文件信息(隐藏和非隐藏)
-A : 表示除了不显示.和..,其他都显示
-l : 表示长格式显示
[root@localhost test]# ls -l
总计 12
-rwxr-xr-x 1 root root 4729 07-24 14:52 hello
-rw-r--r-- 1 root root 78 07-24 14:52 hello.c
空格分割成7列
第一列:表示文件类型和权限
文件类型:第一列的第一个字符表示
- : 表示普通文件
d : 表示目录文件
c : 表示字符设备类文件 device driver
b : 表示块设备类文件
l : 表示链接文件
s : 表示套接子文件 net
p : 表示管道文件 sys
文件权限
r : 表示只读 4
w : 表示只写 2
x : 表示可执行 1
- : 表示无权限
三位为一组,共三组
第一组 : 表示属主的权限
第二组 : 表示属组的权限
第三组 : 表示其他用户权限
设置文件权限
属主: u
属组: g
其他用户 : o
所有用户 :a
chmod option filename
添加权限:+
删除权限:-
赋值权限:=
案例一:字符指定方法
[root@localhost test]# chmod a=rwx hello.c
[root@localhost test]# ll
总计 12
-rwxr-xr-x 1 root root 4729 07-24 14:52 hello
-rwxrwxrwx 1 root root 102 07-24 17:30 hello.c
prw-r--r-- 1 root root 0 07-24 17:22 ken
[root@localhost test]# chmod u=rwx,g=rx,o=r hello.c
[root@localhost test]# ll
总计 12
-rwxr-xr-x 1 root root 4729 07-24 14:52 hello
-rwxr-xr-- 1 root root 102 07-24 17:30 hello.c
prw-r--r-- 1 root root 0 07-24 17:22 ken
案例二: 数字指定方法
[root@localhost test]# chmod 07 hello.c
[root@localhost test]# ll
总计 12
-rwxr-xr-x 1 root root 4729 07-24 14:52 hello
-------rwx 1 root root 102 07-24 17:30 hello.c
prw-r--r-- 1 root root 0 07-24 17:22 ken
[root@localhost test]# chmod 0700 hello.c
[root@localhost test]# ll
总计 12
-rwxr-xr-x 1 root root 4729 07-24 14:52 hello
-rwx------ 1 root root 102 07-24 17:30 hello.c
prw-r--r-- 1 root root 0 07-24 17:22 ken
设置文件属主和属组
chown
chown tom hello.c 指定文件属主
chown :jim hello.c 指定文件属组
chown lili:mary hello 指定属主和属组
第二列:表示文件硬连接数
计算机识别文件唯一标识:文件索引号 inode节点号
-i : 显示文件索引号
硬链接:
1 创建硬链接
ln srcfilename destfilename
2 相当于给文件做了一个备份
3 文件inode节点号是一致
4 不可以操作目录
5 不可以跨分区
软连接:
1 创建软连接
ln -s srcfilename destfilename
2 inode号不一致
3 相当于给文件做快捷方式
4 可以操作目录
5 不可以跨分区
第三列:表示文件属主(文件拥有者)
第四列:表示文件属组(文件拥有组)
第五列:表示文件大小(字节)
byte->K->M->G->T->p
1K=1024B
1M=1024K
bit(位) 1B=8bit
W(字)=2B=16bit
-h :表示易读模式
第六列:表示时间
stat:查看文件属性
[root@localhost liang]# stat hello
File: “hello”
Size: 4725 Blocks: 16 IO Block: 4096 一般文件
Device: 802h/2050d Inode: 4499906 Links: 1
Access: (0755/-rwxr-xr-x) Uid: ( 0/ root) Gid: ( 0/ root)
Access: 2020-07-24 23:21:41.000000000 +0800
Modify: 2020-07-24 22:55:04.000000000 +0800
Change: 2020-07-24 22:55:04.000000000 +0800
atime:访问时间 cat tac head tail more less
mtime:修改文件内容,同时会触发ctime时间
ctime:修改文件属性 chmod chowm
第七列:表示文件名
. : 表示当前目录
.. : 表示上级目录
.filename : 表示隐藏文件
.dirname : 表示隐藏目录