全部文章/linux

Linux

linux入门命令

文件管理

了解linux系统文件目录结构,以及各目录下的文件作用;

目录结构

/ ->

bin 普通用户使用的命令

sbin 管理员使用的命令

dev 设备文件

root 用户的home

home 存储普通用户家目录

proc 虚拟文件系统

usr 系统文件 /local软件安装目录 /bin普通用户使用的程序 /

boot 系统启动相关文件

etc 配置文件

网络/etc/sysconfig/network  /etc/hostname

应用配置文件/etc/ssh/sshd_config…

tmp 临时文件

var 存放一些变化文件 日志

mysql /var/mysql

vsftp /var/vdftp

log日志

文件或目录的创建,查看,删除,移动,压缩,查找

创建文件 touck

创建目录 mkdir

复制 cp

-r 递归

移动 mv

删除 rm

-r 递归

-f 强制

查看文件内容

文本文件cat

-n 显示行号

-A 显示控制字符(换行符/制表符)

grep 针对文件内容进行过滤

grep ‘password’ /etc/test/txt 过滤出文件中的password

vi编辑操作

文本编辑 y 复制  d 删除 x删除光标所在字符

i进入插入模式 :进入末行模式 v 进入可视模式

:10 进入第10行

:q  退出

:w 保存

:wq 保存退出

:w! 强制保存

:q! 不保存退出

:wq! 强制保存并退出

:x保存退出

:r /etc/1.txt 写入1.txt

扩展-文件时间

文件类型

ls -l

-普通文件

d目录文件

b设备文件

c设备文件

s套接字文件

p管道文件

l链接文件

用户管理

用户的查看,创建,删除

id 查看当前登录的用户信息

用户管理

管理员 uid 0

系统用户 1-499

普通用户 500-60000

管理组 gid 0

系统组 1-499

普通用户组 500-60000

添加账户 useradd test

用户信息文件 /etc/passwd

用户名

密码占位符

uid

gid

描述

家目录

用户shell

用户管理:组成员管理

groupadd,groupdel

useradd,usermod,userdel

passwd,chage

用户组

groupadd t1

groupadd t2 -g 200 指定t2gid为200

用户

useradd md 未指定选项,则默认系统创建一个和用户名相同的组作为用户的primary group

创建指定选项用户

-u uid

-d 指定家目录

-s 指定shell

删除用户

userdel mdd 只删除用户

userdel -r mdd 同时删除家目录和mail spool

密码 passwd md

组成员管理

gpasswd -a user group添加用户到组

添加多个

gpaswd -M user1.user2 group

组中删除账户

gpasswd -d user group

删除组

groupdel group

文件权限

文件权限设置:可以赋予某个用户或组以何种方式访问文件

 

ugo
rwxrwxrwx
 

权限对象

属主 u

属组 g

其他人 o

 

基本权限类型

r 读 4

w 写 2

x 执行1

 

设置权限

更改文件的属主,属组

chown user.group file 更改属主,属组

chown user file 更改属主

chown .group file 更改属组

更改权限

chmod 对象 赋值符号 权限类型

u/g/o

+/-/=

w/r/x

数字

alc基本权限

ugo设置基本权限只能一个用户一个组和其他人

acl设置基本权限 r,w,x

设置

getfacl /file

setfacl -m u:user:rw /file 增加用户user权限

setfacl -m u:user1:- /fiel 增加用户user1权限

查看/删除

getfacl

setfacl -x

-b 删除所有权限

chown更改 chmod赋予

进程管理

查看进程

静态ps

ps aux |less 分页查看 q推出

ps aux --sort %cpu|less 查询cpu百分比

ps -ef

自定义输出

ps axo user,pid,ppid

查看pid

ps aux |grep sshd

动态top

top -d 延迟间隔

top -p 指定进程

top -u 指定用户

 

netstat

-t 指名tcp端口

-u 指名udp端口

-a 显示所有连接端口

-p 程序名称

关闭进程

kill

文件查找打包

文件查找

grep 文件内容过滤

find 文件查找,针对文件名

1.命令文件

which ls

2.任意文件

a.locate(查询的数据库/var/lib/mlocate/mlocate.db)

updatedb更新数据

locate test.txt 查找所有

b.find

按文件名

find /etc -name ""

find /etc -iname ""忽略大小写

按文件大小

find /etc -size +5M 大于5M

按照目录深度

-maxdepth 3

按时间查找

find /etc -mtime +5修改时间超过5天

文件类型

find /dev -type f普通

d 目录 l链接 b 块设备 c 字符设备 s 套接字 p管道文件

文件权限

find .-perm 644 -ls .是当前目录 644权限的

find 文件查找,针对文件名 文件打包,解压

打包 压缩

tar -czf test1.tar.gz test

-z调用gzip

-j调用bzip2

-J调用xz

-f 压缩后名字

解压,解包

tar -tf tar.xz

tar -xzvf tar.gz

tar -xvf tar.gz 无需指定解压工具,tar会自动判断

tar -xvf tar.gz -C /tmp指定解压到tmp

tar xf tar.xz 自动寻找 记住-推荐

解压zip

unzip .zip

软件包管理

yum管理包(自动解决依赖问题)

安装/查询/卸载

软件类型

a源码包 需要编译 .tar.gz

b二进制包 rpm包

 

常见二进制包

系统平台包类型工具在线安装
Redhat/centosrpmrpm,rpmbuildyum
Ubuntu/debiandpkgdpkgapt
 

rpm包管理

uname -a 查看系统架构

yum官方源

/etc/yum.repos.d/   位置

yum repolist 列出源(默认国外源)

yum clear all 清除原来旧的yum数据库信息

yum makecache 重新构建源

EPEL源 :红帽企业版源

国外源 或者 阿里源

yum -y install repo直接安装源

使用yum管理rpm包

查看可用仓库

yum clear all 清空缓存以及其他文件

yum makecache 重建缓存

yum repolist 查询可用的仓库

安装

yum -y install

yum -y reinstall 重装

yum -y update 更新

yum -y groupinstall

查询(本地rpm数据库 从yum源中查询)

查询是否以安装 yum installed

yum list |grep mys

yum list mys*

卸载

yum -y remove

yum -y groupremove

查找软件包

yum provides

tar源码包管理

环境准备:gcc,make

下载tar.gz

  1. 详解源码安装三步曲
  2. # ./configure
  1. 指定安装路径,例如 --prefix=/usr/local/nginx
  2. 启用或禁用某项功能, 例如 --enable-ssl, --disable-filter --with-http_ssl_module
  3. 和其它软件关联,例如--with-pcre
  4. 检查安装环境,例如是否有编译器gcc,是否满足软件的依赖需求 最终生成:Makefile
# make //按Makefile文件编译,可以使用-j 2指定两颗CPU编译,优化编译器参数

make install //按Makefile定义的文件路径安装

报错

源码安装错误:

error1:

./configure: error: the HTTP gzip module requires the zlib library.

You can either disable the module by using –without-http_gzip_module option, or install the zlib library into the system, or build the zlib library statically from the source with nginx by using –with-zlib=<path> option. 解决方案:

yum -y install zlib-devel

error2:

./configure: error: SSL modules require the OpenSSL library.

You can either do not enable the modules, or install the OpenSSL library into the system, or build the OpenSSL library statically from the source with nginx by using –with-openssl=<path> option.

解决方案:

yum -y install openssl-devel

error3

checking for C compiler … not found ./configure: error: C compiler cc is not found

解决方案:

yum -y install gcc gcc-c++ make

error4:

./configure: error: the HTTP rewrite module requires the PCRE library. You can either disable the module by using –without-http_rewrite_module option, or install the PCRE library into the system, or build the PCRE library statically from the source with nginx by using –with-pcre=<path> option. 解决方案:

yum -y install pcre-devel