linux
来源:互联网 发布:电脑游戏截图软件 编辑:程序博客网 时间:2024/05/29 18:26
一、rhel-server-6.4-i386 操作系统安装:
使用的虚拟机是vwware
1、建立虚拟机(相当于去电脑城diy主机)
网卡模式:三种(桥接、nat、hostonly),选择桥接
硬盘格式:三种(IDE、sata、scsi),选择scsi
2、添加系统光盘
3、安装系统
安装方式:
图形界面安装--安装介质(光盘):
分区规划:
/boot --引导分区(200M)
/ --根分区(至少40G)
swap --交换分区(物理内存的1.5~2倍)
如何关机: #shutdown -h now
二、终端的基本使用:
1、如何开启终端:
右键--->open in terminal
alt+F2--->gnome-terminal--->回车
2、如何关闭: 鼠标关闭 exit--->回车
3、清空终端: ctrl+l
4、终止命令 ctrl+c
5、补全命令或文件和目录名 tab
6、ctrl+shift+t 开启新的标签
ctrl+shift+n 开启新的终端
ctrl+shift++ 放大终端
ctrl+- 缩小终端
alt+[1~9] 标签之间切换
三、基本命令的使用
whoami --我是谁
pwd --我在哪
cd --要去哪
#cd /usr/local/src --切换到绝对路径
#pwd
/usr/local
#cd src --切换到相对路径
#pwd
/usr/local/src
# cd - --切换刚才的路径
1、如何创建文件和目录(文件夹)
创建文件:touch filename --(如果有同名文件会更新时间戳)
如何创建多个文件:#touch a{1,2,3}
#touch {b1,b2,b3}
#touch {c,d}{1,2,3}
#touch {/test/file8,/uplook/file9}
创建目录:mkdir dirname
如何创建多个目录:#mkdir dir{1,2,3}
#mkdir {/test/dir4,/uplook/dir5}
#mkdir /dir1/dir2/dir3/dir4 -pv
查看目录内的内容:ls
2、复制cp
# cp /test/file5 /uplook --拷贝文件
# ls /uplook
file5
# cp /test /uplook -r --拷贝目录(r:递归)
# cp /test/* /uplook --拷贝目录内的所有文件到其它目录下
# cp /uplook/file8 /test/file9 --拷贝并改名
# cp /etc/passwd . --拷贝到当前路径(.代表当前路径,..代表上一层路径)
3、删除rm 注意:非常危险,生产环境中慎用
# rm a1 --交互式删除一个文件
# rm a1 b1 c2 --交互式删除多个文件
# rm -rf /test/mulu2/*
--非交互式删除/test/mulu2/目录下的所有文件(r:递归,f:强制删除不提示)
# rm -rf /uplook --删除目录
4、剪切mv
# mv /test/file1 /uplook --将/test目录下的file1文件剪切到/uplook目录下
# mv /test/* /backup --剪切目录下的所有文件
# mv /backup/{file2,file3} /test --剪切/backup目录下多个文件
# mv {/test/file4,/uplook/file6} /backup/ --剪切多个不同目录下的文件到同一个目录下
# mv /backup/ /uplook/ --剪切目录,将/backup目录剪切到/uplook目录下
5、改名mv
# mv file9 file7 --修改文件名
# mv /uplook/file10 /test/file5 --剪切并改名
# mv /uplook/backup /back --剪切目录并改名
6、查看文件内容:
cat:一次性查看文件所有内容
# cp /etc/passwd /test
# cat passwd --查看文件内容
# cat /test/passwd --查看文件内容
less:分屏显示文件内容
(pageup:向上翻页,
pagedown和空格:向下翻页,
上下方向键:以行形式上下查看,
home/end :文件的首和尾,或者是g/G
q:退出)
# less /test/passwd
head: 显示文件的首10行
# head passwd
# head -n 5 passwd 或 head -5 passwd --显示文件首5行
tail:显示文件的尾10行
# tail passwd
# tail -n 5 passwd 或 tail -5 passwd --显示文件的尾5行 *******************************************************************************
练习
* 在/tmp目录下创建一个子目录为shared
* 在根目录下创建一个目录为shared1
* 在shared1目录内创建9个子目录为a1~a9
* 在a5目录内创建file1~file3三个文件
* 在shared目录内创建两个目录,old,new
* 把shared目录更名为backup
* 拷贝/etc/inittab文件到old目录内
* 拷贝/boot/grub/grub.conf文件到old目录内
* 移动shared1目录到backup目录内,删除a1---a4,a6---a9目录
* 将a5目录改名为inp,移动到new目录内
* 删除shared1目录
day1021
本编辑工具:
图形界面下的文本编辑工具:# gedit passwd
命令行模式下的文本编辑工具:vi/vim # vi passwd(# vim passwd)
vi/vim有三种模式:
命令模式---(i、I、a、A、o、O)---->编辑模式(再回到命令模式esc)
命令模式----------(:)------------>末行模式
1、命令模式
dd 删除(剪切)光标所在行
ndd 删除光标所在行及下面行共n行
u 撤销
gg 切换到文件的首行
G 切换到文件的尾行
dG 删除光标所在行到尾行
dgg 删除光标所在行到首行
yy 复制光标所在行
nyy 复制光标所在行及下面行共n行
p 粘贴在光标所在行的下一行
x 删除光标所在字符
r 修改当前光标所在字符
R 替换当前字符及后面字符
dw 删除单词
d$ 删除光标所在位置到行尾
d^ 删除光标所在位置到行首
2、编辑模式
3、末行模式
:q 退出
:q! 强制不保存退出
:w 保存
:wq 保存并退出
:wq! 强制保存退出
:set nu 显示行号
:set nonu 关闭显示行号
如何实现永久显示行号:
# vim /etc/vimrc
:set nohlsearch 关闭查找高亮
:set hlsearch 开启查找高亮
:set list 显示制表符和行尾标识符
替换:
/+关键字 搜索(n向下切换,N向上切换)
:1,$ s/root/tom/g --替换所有的root为tom(或:% s/root/tom/g)
:1,$ s/root/tom/ --替换每一行的第一个root为tom
:2,5 s/nologin/uplook/g --第2-5行所有的nologin替换为uplook
:8 s/halt/root/g --替换第8行的所有halt为root
替换特殊符号要加转义符号(\):
:% s/\:/\-/g --将所有的:替换为-
:% s/\:\//\-/g --将所有的:/替换为-
删除:
:6,10 d --删除6-10行
追加:
:10,15w>>/test/ww.c --将10-15行追加到/test/ww.c文件中
读取:
:r /test/ww.c --将ww.c文件的内容读取到当前文件中
可视化模式:
ctrl+v
shift+v
练习:
# vim /etc/sysconfig/network-scripts/ifcfg-eth0
DEVICE=eth0
HWADDR=00:0C:29:2B:47:94
TYPE=Ethernet
UUID=938c7ed5-0016-4708-861e-c8d12e9f25f4
ONBOOT=yes
NM_CONTROLLED=no
BOOTPROTO=static
IPADDR=172.16.254.100
NETMASK=255.255.0.0
# vim /etc/yum.repos.d/local.repo
[base]
name=base
baseurl=file:///mnt/iso
enabled=1
gpgcheck=0
day1022
文件属性的查看:
[root@localhost ~]# ls -l anaconda-ks.cfg
-rw-------. 1 root root 1330 Oct 19 16:10 anaconda-ks.cfg
[root@localhost ~]# ls -lh
total 104K
-rw-------. 1 root root 1.3K Oct 19 16:10 anaconda-ks.cfg
drwxr-xr-x. 2 root root 4.0K Oct 19 19:49 Desktop
drwxr-xr-x. 2 root root 4.0K Oct 19 16:26 Documents
drwxr-xr-x. 2 root root 4.0K Oct 19 16:26 Downloads
[root@localhost ~]# ls -lt --按修改时间排序
[root@localhost ~]# ls -lS --按文件大小排序
[root@localhost ~]# ls -ltr --按修改时间倒序排列
命令的帮助:
help:
# ls --help 外部命令查看帮助
# help cd 内部命令查看帮助
man: --manual
语法:# man +命令(# man ls)
/+关键字 --搜索关键字(n向下查找,N向上查找,q退出)
------------------------案例-----------------------------------
# man ls
NAME --命令名称
ls - list directory contents
SYNOPSIS --命令的语法
ls [OPTION]... [FILE]...
DESCRIPTION --命令的描述(包括选项)
List information about the FILEs (the current directory by default). Sort
entries alphabetically if none of -cftuvSUX nor --sort.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
do not ignore entries starting with .
-A, --almost-all
EXAMPLES --案例
………………………………………………
AUTHOR --命令的开发者
Written by Richard M. Stallman and David MacKenzie.
REPORTING BUGS --bug上传地址
Report ls bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
Report ls translation bugs to <http://translationproject.org/team/>
COPYRIGHT --版权
Copyright ? 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL
version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it. There
is NO WARRANTY, to the extent permitted by law.
SEE ALSO --其它帮助
The full do
--------------------------------------------------------------------------------
# man 1 man
1 User Commands --普通命令的帮助
2 System Calls --系统调用的帮助
3 C Library Functions --c的库函数帮助
4 Devices and Special Files --设备和特殊文件的帮助
5 File Formats and Conventions --配置文件的帮助
6 Games et. Al. --给游戏的帮助
7 Miscellanea --杂项(系统环境变量)
8 System Administration tools and Deamons --系统管理员相关命令的帮助
[root@localhost ~]# man 1 passwd --查看passwd作为命令的帮助
[root@localhost ~]# man 5 passwd --查看passwd作为配置文件帮助
[root@localhost ~]# man -a passwd --查看所有帮助
****************************************************************************
学习命令的方法:
1、记住基本选项
2、通过man看扩展选项
3、去搜索引擎、看相关书籍和官方文档
4、逛论坛
5、通过笔记记下特殊的用法
****************************************************************************
练习:
1、用vim编辑/etc/yum.repos.d/base.repo文件
[Server]
name=Server
baseurl=file:///mnt/cdrom/Server
enabled=1
gpgcheck=0
[ScalableFileSystem]
name=ScalableFileSystem
baseurl=file:///mnt/cdrom/ScalableFileSystem
enabled=1
gpgcheck=0
[ResilientStorage]
name=ResilientStorage
baseurl=file:///mnt/cdrom/ResilientStorage
enabled=1
gpgcheck=0
[LoadBalancer]
name=LoadBalancer
baseurl=file:///mnt/cdrom/LoadBalancer
enabled=1
gpgcheck=0
[HighAvailability]
name=HighAvailability
baseurl=file:///mnt/cdrom/HighAvailability
enabled=1
gpgcheck=0
2、将/etc/yum.repos.d/base.repo复制到/tmp下并改名为local.repo
然后将file:///mnt/cdrom字符串替换为http://172.16.254.100/iso
:% s/file\:\/\/\/mnt\/cdrom/http\:\/\/172\.16\.254\.254\/iso/g
------------------------------------------------------------------------------------
3、拷贝/etc/passwd到/test下,然后在每行的行首增加字符串hello
:% s/^/hello/g
4、在每行的行尾添加END :% s/$/end/g
5、将3到7行的sbin换成xxxx :3,7 s/sbin/xxxx/g
6、将3行到8行之间的内容删除 :3,8 d
day1023
用户的管理:
添加用户:
# useradd tom
# id tom
uid=500(tom) gid=500(tom) groups=500(tom)
uid --用户的唯一标识符号
0: 代表超级管理员(root)
1~499: 系统用户,主要用于完成某些特定功能,但是不具有登录能力
500~65536: 普通用户,具有登录能力
gid --所属主组的id号
groups --属于哪些组的信息
# useradd -u 800 user2 --指定uid添加用户
# id user2
uid=800(user2) gid=800(user2) groups=800(user2)
给用户设置密码:
[root@localhost ~]# passwd --当前用户给自己设置密码
Changing password for user root.
New password:
BAD PASSWORD: it is based on a dictionary word
BAD PASSWORD: is too simple
Retype new password:
passwd: all authentication tokens updated successfully.
[root@localhost ~]# passwd tom --给普通用户设置密码
--普通用户无密码无法登录系统
删除用户:
# userdel user2
# id user2
id: user2: No such user
# userdel -rf user1 --删除用户同时删除家目录
练习:添加用户u1,uid为888,再将此用户设置密码为666666,再删除该用户并且不保留家目录
修改用户:
# usermod -u 550 tom --修改用户的uid
# id tom
uid=550(tom) gid=500(tom) groups=500(tom)
# usermod -g 551 tom --修改用户的gid
# id tom
uid=550(tom) gid=551(user1) groups=551(user1)
# usermod -G 501 user1 --修改用户的附属组
# id user1
uid=500(user1) gid=500(user1) groups=500(user1),501(user2)
# usermod -a -G 502 user1 --追加附属组
# id user1
uid=500(user1) gid=500(user1) groups=500(user1),501(user2),502(user3)
用户的查看:
/etc/passwd --存储用户的基本信息
[root@localhost home]# tail /etc/passwd
postfix:x:89:89::/var/spool/postfix:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
rpcuser:x:29:29:RPC Service User:/var/lib/nfs:/sbin/nologin
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
user1:x:500:500::/home/user1:/bin/bash
user2:x:501:501::/home/user2:/bin/bash
user3:x:502:502::/home/user3:/bin/bash
# tail -1 /etc/passwd
user3:x:502:502::/home/user3:/bin/bash
用户名:密码位:uid:gid:描述信息:家目录:用户的shell
/etc/shadow --存储用户的密码信息
[root@localhost home]# tail -3 /etc/shadow
user1:$6$uHlwy.rZ$nRN/hrzfWQQKN4xmJhCa2Zl/0U17kODzbJ0q29LO1JNtoys56zjHDg2blc8uozt3AwqtEgzpq5Q6B9n7/nu8F0:16366:0:99999:7:::
user2:!!:16366:0:99999:7:::
user3:!!:16366:0:99999:7:::
[root@localhost home]# man 5 shadow --查看shadow文件的帮助
组的管理:
组的添加:
# groupadd group1
# tail -3 /etc/group
user2:x:501:user1
user3:x:502:user1
group1:x:503:
组的删除:
# groupdel group1
组的修改:
# groupmod -g 505 group1 --修改group1组的gid为505
综合练习:
添加group2组
[root@localhost home]# groupadd group2
查看group2组信息
[root@localhost home]# tail -3 /etc/group
user3:x:502:user1
group1:x:505:
group2:x:506:
添加用户user4指定组为group2
[root@localhost home]# useradd -u 800 -g 506 user4
查看user4信息
[root@localhost home]# id user4
uid=800(user4) gid=506(group2) groups=506(group2)
[root@localhost home]# tail -5 /etc/group
user1:x:500:
user2:x:501:user1
user3:x:502:user1
group1:x:505:
group2:x:506:
查看一个组的组成员:
[root@localhost home]# id user5
uid=801(user5) gid=801(user5) groups=801(user5),507(g1)
[root@localhost home]# groupmems -g g1 -l
user5
用户的切换:
su --switch user
root用户切换到普通用户
[root@localhost ~]# su - user1
[user1@localhost ~]$
如何退出:
[user1@localhost ~]$ exit
logout
[root@localhost ~]#
- linux
- linux
- Linux
- Linux
- LINUX!
- Linux
- linux
- linux
- linux
- Linux
- linux
- linux
- linux
- linux
- Linux
- linux
- linux
- Linux
- oracle 修改最大连接数
- 个人服务器资源列表
- python保存数据到本地文件
- mxnet保存模型,加载模型来预测新数据
- [Python3入门与进阶]8 函数
- linux
- spring中用joinpoint来访问目标方法的参数
- 【今日头条】2017年短视频创作者商业变现报告
- python 操作mysql数据中fetchone()和fetchall()
- bzoj1026 [SCOI2009]windy数(数位dp)
- Qt应用程序“xxx.exe 已停止工作 故障模块msvcr120.dll”
- 不用额外变量交换两个整数值 Python版
- [C/C++]堆栈的概念与区别
- KNN 图像分类python实现