0316 linux目录认识和基本命令

1.目录认识

linux系统中,所有的目录和文件都是在根目录/开始的,linux目录结构配置方式也成为“目录树”

cd /      #切换到根目录
ls      #查看

0316 linux目录认识和基本命令
/ : 下面是根目录下主要的目录介绍
bin-----用户会用到的命令
boot--------开机文件,里面有grub
dev----------设备文件
home---------用户家目录
etc--------软件配置文件
lib、lib64--------主要有库函数
media-------------cdrom等暂存媒体
mnt----------------临时挂载
opt-----------第三方软件
proc----------内存中的数据,如进程
root-----root家目录
run------开机会消失的文件
sbin----root用到的命令
srv---------"service"简写,存放一些服务数据
sys-------记录与内核相关信息
tmp---------共享目录
usr--------软件资源放置的目录
var-----主要是常态性变动的文件,包括缓存,登入文件(log file)以及某些软件所产生的文件

2.linux常用命令

  • ls命令
    常用参数:
    -i 显示文件inode号码
    -l 详细显示文件信息,例如:属性、权限、inode号码数、所有者、所有组、时间、
    文件名
    -a 显示所有文件
    -t 文件按时间排序
    -h 人性化的显示,比如说有单位
    0316 linux目录认识和基本命令
    文件类型:
    c 表示串行端口设备,例如键盘、鼠标
    d 表示目录
    l 连接文件
    b 设备文件
    [-] 文件

alias别名命令:

which  #用来查找执行文件
alias    #查看所有的别名
alias ll='ls -l --color=auto'    #设置ll别名
unalias ll      #取消别名

相对 路径和绝对命令:
cd - #切换到上一次目录
cd ~ #切换到家目录
cd … #切换到上一级目录

创建和删除命令:

mkdir创建目录:

mkdir /root/1/               #在root目录下创建1目录
mkdir /root/1/2/3         #创建失败,因为还不存在2目录
mkdir -p /root/1/2/3     #  -p参数 直接创建一层层目录

rmdir删除目录:
rmdir 只能删除空目录

  • rm删除目录和文件
    rm -r /root/1/2/3/ #-r参数能够删除目录
    rm -f /root/1/2/ #不会出现提示

PATH环境变量

echo $PATH          #查看环境变量
which ls      #查看ls执行命令路径
cp /usr/bin/ls /root/ls2
ls2                     #试着执行ls2 错误
PATH="$PATH":/root/     #添加/root/环境变量
ls2     #执行成功
vi /etc/profile        #写入 PATH=$PATH:/root/ 永久生效
  • cp命令:

-r : 复制目录
-p : 把文件属性一起复制过去

  • mv命令移动文件或更名:

查看文本命令工具less

less 文件名 
G g 上下翻屏
n N 上下查找
q键退出
head -n 5 文件名  #查看前5行
tail -n 5 文件名      #查看后五行

chmod命令介绍

[[email protected] ~]# ls -ld /root/.ssh/
drwx------. 2 root root 80 3月  15 20:59 /root/.ssh/
[[email protected] ~]# getenforce      #查看selinux是否开启
Enforcing     #开启
[[email protected] ~]# setenforce 0              #暂时关闭
[[email protected] ~]# getenforce
Permissive
[[email protected] ~]# vi /etc/se  
securetty      security/      selinux/       services       sestatus.conf  
[[email protected] ~]# vi /etc/selinux/config    #selinux配置文件 
[[email protected] ~]# chmod -R ^C            #把目录下的文件和子目录都更改权限
[[email protected] ~]# ls ./1
[[email protected] ~]# touch ./1/3.txt
[[email protected] ~]# ls -l ./1/
总用量 0
-rw-r--r--. 1 root root 0 3月  18 12:32 3.txt
[[email protected] ~]# chmod -R 770 ./1
[[email protected] ~]# ls -al ./
1/               .bash_history    .bashrc          .ssh/            
2.txt            .bash_logout     .cshrc           .tcshrc          
anaconda-ks.cfg  .bash_profile    .lesshst         
[[email protected] ~]# ls -al ./1
总用量 0
drwxrwx---. 2 root root  19 3月  18 12:32 .
dr-xr-x---. 4 root root 185 3月  18 12:26 ..
-rwxrwx---. 1 root root   0 3月  18 12:32 3.txt

chown命令介绍:

[[email protected] ~]# chown ligen /root/1/    
[[email protected] ~]# ls -ld /root/1/
drwxrwx---. 2 ligen root 19 3月  18 12:32 /root/1/
[[email protected] ~]# chgrp ligen /root/1/
[[email protected] ~]# ls -ld /root/1
drwxrwx---. 2 ligen ligen 19 3月  18 12:32 /root/1
[[email protected] ~]# chown root:root /root/1/      #chown一起更改所有者和所有组
[[email protected] ~]# ls -ld /root/1/
drwxrwx---. 2 root root 19 3月  18 12:32 /root/1/

umask认识:

系统默认权限

  [[email protected] ~]# umask
    0022
    [[email protected] ~]# umask 002
    [[email protected] ~]# umask
    0002
    [[email protected] ~]# touch 4.txt
    [[email protected] ~]# mkdir 5
    [[email protected] ~]# ls -al
    总用量 40
    dr-xr-x---.  5 root root  207 3月  18 12:49 .
    dr-xr-xr-x. 17 root root  245 3月  16 01:27 ..
    drwxrwx---.  2 root root   19 3月  18 12:32 1
    -rw-r--r--.  1 root root    0 3月  18 12:26 2.txt
    -rw-rw-r--.  1 root root    0 3月  18 12:49 4.txt
    drwxrwxr-x.  2 root root    6 3月  18 12:49 5
    -rw-------.  1 root root 6494 3月  16 19:39 anaconda-ks.cfg
    -rw-------.  1 root root 4825 3月  16 21:55 .bash_history
    -rw-r--r--.  1 root root   18 12月 29 2013 .bash_logout
    -rw-r--r--.  1 root root  176 12月 29 2013 .bash_profile
    -rw-r--r--.  1 root root  176 12月 29 2013 .bashrc
    -rw-r--r--.  1 root root  100 12月 29 2013 .cshrc
    -rw-------.  1 root root   44 3月  16 19:45 .lesshst
    drwx------.  2 root root   80 3月  15 20:59 .ssh
    -rw-r--r--.  1 root root  129 12月 29 2013 .tcshrc
  • 课堂讲解笔记:
    目录结构的讲解和回忆,回顾上面的目录笔记
    alias ls=‘ls -al --color=auot’ 设置alias的格式
    PATH环境变量的讲解以及重点知识
    cp、mv命令的回顾