Linux培训系列(一)

=>linux命令

ls -dl   查看目录本身

ls -rl   查看目录内部

ls -i   查看索引节点号

ls -id 查看目录的节点号

mkdir -p  创建父目录

touch

echo "test" > test.txt

cat test.txt

cp

mv

ln -s

rm -rf

=>regexp

+,.,、,*,[,],\作为单字符时需要用\来转意

.:元字符,与任何单个字符匹配

[1,2]:指定匹配字符1,2.方括号内部不做转意

[^12]:排除1,2

*:0次或多次重复前一个字符

grep ^# /etc :  以#开头的行

grep '^#.*\.$' /etc/fstab  以#开头,以.结尾的行

 =>FHS与查找文件

/(根目录)
/boot(引导装入程序的静态文件)
/dev(设备文件)
/etc(主机特定的系统配置)
/lib(基本共享库和核心模块)
/mnt(临时挂装文件系统的挂装点)
/opt(附加的应用程序软件包)
/sbin(基本系统二进制文件)
/tmp(临时文件)
/usr(辅助层次结构)
/var(可变数据)

+---------+-----------------+-------------+
| | 可共享 | 不可共享 |
+---------+-----------------+-------------+
|静态 | /usr | /etc |
|         | /opt | /boot |
+---------+-----------------+-------------+
|可变 | /var/mail | /var/run |
|          | /var/spool/news | /var/lock |
+---------+-----------------+-------------+

which  ls,是否有ls

which -a ls,显示所有相关

whereis

find /usr/share/doc -iname README\*

find /etc -iregex '.*.txt.*'

find /usr/bin -name '*vim*' -type l

find /usr/bin -type f -size -50c -exec ls -l '{}' ';'

find:全路径匹配

locate:与路径的任何部分匹配

updatedb:为文件系统建立索引

slocate: locate的安全版本

=>进程控制

Ctrl+C   or  ^C: kill process

Ctrl+Z   or ^Z   : stop prcess

fg:前台运行

bg:后台运行

xeyes -center blue &:后台运行

jobs -l   :查看后台运行程序

ps -ax

ps x --forest

ps -au

ps -al

top

nice

renice

=>文本处理

cat---tac

sort

uniq

cat myfile.txt | sort | uniq | wc -l

wc

head

tail

expand

unexpand

=>系统和网络文档

手册页 /usr/share/man

man1  用户程序

man2 系统调用

man3 函数库

man4 特殊文件

man5 文件格式

man6 游戏

man7 其它

$whatis printf

$man 3 printf

$man -k whatis   搜索手册页的NAME 这一节

#makewhatis    它扫描您的 Linux 系统上的所有手册页,并且为 whatis 和 apropos 构建数据库

info diff

info info

/usr/share/doc    帮助资源

=> Linux权限模型

“d”目录
“l”符号链接
“c”字符专门设备文件
“b”块专门设备文件
“p”先进先出
“s”套接字

“-”常规文件

whoami

groups

chown

chgrp

chmod +x

umask-->创建文件时使用的默认属性

suid-->与x处于同一位,设置了x权限用s表示,未设置x权限用S表示

sgid->类似suid.


chmod u+s /usr/bin/myapp

chmod g-s /home/test

 文件权限的第一位:

suid sgid sticky 模式数字
on on on 7
on on off 6
on off on 5
on off off 4
off on on 3
off on off 2
off off on 1
off off off 0

=> linux账户管理

/etc/passwd

 drobbins:x:1000:1000:Daniel Robbins:/home/drobbins:/bin/bash

->用户名:x:数字用户标识:用户所属的组:用户名称:用户主目录:用户缺省shell

 /etc/shadow

-->存储账户的密码

/etc/group

-->定义linux系统上所有的组

passwd

=>调节用户环境
1.登录shell:
   1)-bash
   2)-login启动
   初始化环境顺序:
    1./etc/profile
    2.~/.bash_profile
2.交互式shell
    靠source ~/.bashrc初始化环境变量
3.export,给bash中的变量做标记,使它们在任何bash启动的新shell中设置相同。
4.到处和设置-x
set -x:是bash打印出要运行的每个命令
set +x:关闭
~/fortune

 =>Linux 文件系统

1.fdisk

2.fstab

3.fsck

4.ext2,ext3,ext4,vfat,xfs,JFS

=>引导系统

1.MBR

2./sbin/init

3.dmesg -->打印内核的log

4./var/log/message-->syslog守护进程记录的log

5.更改运行级别

telinit 1

     0:停止计算机
     1 或 s:单用户方式    
     2:多用户,无网络
     3:多用户,文本控制台
     4:多用户,图形控制台
     5:同 4
     6:重新引导计算机

6.关机

     shutdown 5

     shutdown -r now

==>系统日志

 /var/log-->日志目录

messages:一般系统程序和守护程序的信息性错误消息

secure:认证消息与错误

maillog

cron

 ==>共享库

1.ldd,判断一个库是否为静态链接库,可以查看库依赖的所有共享库列表

2.动态装入器负责将程序需要的动态库装入(ld-linux.so.2)

 动态装入器靠两个文件找到共享库:

1)/etc/ld.so.conf-->包括所有的动态链接库,(/lib和/usr/lib除外,它们会自动包含在其中)

ldconfig负责将ld.so.conf转换为/etc/ld.so.cache,供动态装入器使用

LD_LIBRARY_PATH可以指示动态装入器首先检查某个目录,找不到时再检查ld.so.conf

猜你喜欢

转载自u010837360.iteye.com/blog/2063473