Linux Basic Commands
Linux Commands
2011.12.22
1.远程连接
telnet 172.16.0.188
boss login:boss
password:
2.Linux的特点
稳定、安全、多任务
Solaris OS
Kernel:内核
Shell:外核
File System:文件系统
shell:命令解析器
#root:超级用户
$user:普通用户
3.Unix的发展
4.Linux命令
cd /,找到根目录
cd,找到普通用户的目录 回到home路径
cd home,找到根目录下的home
pwd,显示当前目录
cd . 回到当前目录
cd ..,找到当前目录的上级目录
ls,列出文件
clear 清屏
uname 版本信息
su - root 切换到超级用户
sudo passwd root – 输入登录 - 输入新的Unix密码
df -k,查看系统的挂在点,磁盘信息
touch filename,创建文件
chmod a=rw filename,修改文件的读写权限
mkdir dir1,创建目录dir1
mkdir -p dir1/dir2,创建多级目录
rm filename,删除文件
rmdir dir1 ,删除目录
rm -r dir1,删除多级目录
cp 复制文件或目录
cp source_file destination_file
cp -r dir3 dir4
cp -r dir3 dir4/tmp
mv 移动、重命名file or direction
man ls
ls --help
info ls
获取帮助信息
Module 4
2011.12.23
1.给前台进程发送中断信号:ctrl+c
2.软链接:ln -s
硬链接:ln
硬链接不能跨文件系统,不能给目录使硬链接
3.文件提示:Tab、Esc
4.ls -F 列出文件类型
5.echo $HOME 输出变量值
6.回到home目录 cd ~
7.*.txt 匹配所有txt文件
Briup$ls *.txt
date6.txt
Briup$
8.Linux下七种文件类型
普通文件
目录文件
特殊的字符文件
特殊的块文件
符号链接
管道文件
socket文件
9.同时执行多个命令
Briup$cd;ls :回到根目录同时显示文件
Briup$date;cal;pwd :显示日历
10. cat /etc/passwd:一次列出目录下所有文件
more /etc/passwd:分屏显示
less /etc/passwd:分屏列出部分目录文件
上下 f b
退出:q
11.重定向输入、输出
Briup$cal 10 2004 > a.txt 将日历重定向输出到a.txt中
12. cat date >> a.txt 追加 date到a.txt
13.cat < a.txt 显示文件的内容
cat > a.txt 往a.txt中添加内容 ctrl+c 退出
cat < a.txt > b.txt 将a.txt加到b.txt中输出
14.Briup$ls -l /etc | more
Briup$cat /etc/passwd | more
用管道把ls输出的内容作为more的输出
|代表管道
Briup$more /etc/passwd | grep root
root:x:0:0:root:/root:/bin/bash
Briup$cat /etc/passwd | grep briup //过滤作用
briup:x:1000:1000:briup,,,:/home/briup:/bin/bash
grep:包含 briup的相关行显示
15.Briup$cat /dev/null > a.txt 清空a.txt中的内容 清空某个文件
16.Briup$awk -F:'/root/' /etc/passwd
17.Briup$cat /etc/passwd | awk -F:'{print $1}'
以管道的方式打印第一行
18.Briup$head -3 /etc/passwd //显示开头的3行
Briup$tail -3 /etc/passwd //显示结尾的3行
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/bin/sh
bin:x:2:2:bin:/bin:/bin/sh
19.vi的三种工作模式
切换模式按键:esc
编辑模式 进行编辑
命令模式 移动光标h、l 前后 j、k 上下
行末模式 :
保存 :wq
退出 :q!
恢复 u
Module 6
2011.12.23
1.vi的三种工作模式
编辑模式 进行编辑
命令模式 移动光标h、l 前后 j、k 上下
行末模式 :
vi分文本模式和命令模式 切换模式:esc
1.激活vi命令:vi filename(filename是已存在的文件或要创建的新文名)
2.要退出vi,必须处于命令模式
3.有六个命令(a、A、i、I、o、O)会将vi切换到文本模式
切换模式按键:esc
i 在光标当前位置插入
a 在光标所在位置后插入
o 在光标所在行下插入一空行
删除
x 删除一个字符
dw 删除当前词
3dw 删除三个词
dd 删除当前行
5dd 删除五行
:5,10d 删除五到十行
替换
r 替换一个字符
cw 替换一个单词
cc 替换一行
C 替换从光标至行尾
保存
:w 存盘
:w newfile 存成新文件
:wq 存盘退出Vi
退出
:q!
拷贝
yw 拷贝词
yy 拷贝行(或y)
p 当前行下粘贴
:1,2co3 拷贝行1,行2在行3之后
:4,5m6 移动行4,行5在行6之后
~ 改变大小写
J 把当前行和下一行连起来
u 恢复,废除刚才的编辑操作
:set nu 显示行代码(:set nonu)
:21 光标停在指定行
21G 光标停在指定行(G 到文件尾,1G 到文件头)
/串 从当前行往下查找
?串 从当前行往上查找
n 查找继续
:r file2 在光标所在位置插入另一个文件
:1,$s/旧串/新串/g 替换全文(或:%/旧串/新串/g)
Module 7
2011.12.26
1.内部、外部命令
Briup$type cd
cd 是一个 shell 内部命令
Briup$type who
who 是 /usr/bin/who
2.查看root 的id
Briup$id root
uid=0(root) gid=0(root) 组=0(root)
Briup$users
briup briup briup
3.显示用户信息
Briup$who
briup tty7 2011-12-26 09:03 (:0)
briup pts/0 2011-12-26 09:40 (:0.0)
briup pts/1 2011-12-26 09:43 (:0.0)
显示当前用户
Briup$whoami
briup
4.find 查找 后接查找条件
grep 过滤
Briup$ls | grep -i a.txt //查找匹配a.txt文件的
a.txt
5.wc 统计 line words characters
Briup$cat /etc/passwd | wc -l
39
6.前台进程、后台进程
ctrl + c 给前台进程发送中断信号,中断前台进程
ctrl + z 使进程挂起(休眠)
jobs 查看休眠进程 id号
[1]+ Stopped yes
briup@briup-P4i65G:~$ ps -ef | grep yes
briup 1595 1398 1 10:53 pts/0 00:00:00 yes
briup 1597 1398 0 10:53 pts/0 00:00:00 grep yes
briup@briup-P4i65G:~$ jobs
[1]+ Stopped yes
bg %[id] 使挂起的进程后台执行
fg %[id] 使挂起的进程重新回到前台
7. bash
系统的初始化配置文件: /etc/profile
用户初始化的配置文件:~/.bashrc
查看进程树:pstree
使配置文件生效:source
8.给变量赋值
briup@briup-P4i65G:~$ var=2
briup@briup-P4i65G:~$ echo $var
2
另一种赋值方式
briup@briup-P4i65G:~$ wto=`uname -n`
briup@briup-P4i65G:~$ uname -n
briup-P4i65G
briup@briup-P4i65G:~$ echo $wto
briup-P4i65G
briup@briup-P4i65G:~$ wto=`date`
briup@briup-P4i65G:~$ echo $wto
2011年 12月 26日 星期一 14:23:09 CST
briup@briup-P4i65G:~$ echo "$wto"
2011年 12月 26日 星期一 14:23:09 CST
单引号、反斜干使变量的值失效
briup@briup-P4i65G:~$ echo '$wto'
$wto
briup@briup-P4i65G:~$ echo \$wto
$wto
9.压缩与解压缩
zip unzip
gzip gunzip
tar -cvf tar -xvf
compress -f uncompress (*.Z)
uncompress也可以解压*.gz类型的压缩文件
briup@briup-P4i65G:~$ zip -r unix.zip file2.txt b.txt
adding: file2.txt (stored 0%)
adding: b.txt (deflated 50%)
briup@briup-P4i65G:~$ unzip unix.zip
10.用户和组
创建组: groupadd 组名
创建组时给组加组号: groupadd -g gid 组名
删除组:groupdel 组名
修改组名称:groupmod -n 新组名 旧组名
修改组的id:groupmod -g 新id 组名
将用户添加到某一个组:gpasswd -a 用户名 组名
将用户从某一个组删除:gpasswd -d 用户名 组名
修改用户名:usermod -l 新用户名 旧用户名
修改用户家目录:usermod -d 新家目录 旧家目录
删除用户:userdel 用户名
userdel -r 用户名 (将用户的家目录彻底删除)
Briup#groupadd -g 999 shuigee
Briup#more /etc/group | grep 999
shuigee:x:999:
改变文件所属组
chown
附:12条基本命令
1.date 显示时间和日期
2.cal 显示日期
3.passwd 修改用户密码
4.bc 计算器
5.echo 显示其参数
6.ipr 打印文件列表
7.script 记录交互式会话
8.tty 显示终端名称
9.stty 设置或取消设置所选终端的输入/输出选项
10.uname 显示系统数据
11.who 显示当前登录到系统的所有用户
12.whoami 显示当前用户