Linux初级知识的了解介绍

来源:互联网 发布:手机剪辑软件 编辑:程序博客网 时间:2024/05/08 21:16

摘要 

这两天对Linux学习,,,,有了初步的了解,,,,在这里想分享给大家看看 
在这里只要说的有:
Linux下的环境变量
Linux下的文件类型
Linux下的文件的访问权限
Linux下如何修改文件的访问权限
Linux下的简单的指令

Linux下的环境变量 

Linux下的环境变量 ,,,都是在全局都有效的一些变量 
1、PATH:指定命令的搜索路径
[wxeast@localhost ~]$ echo $PATH/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/wxeast/bin
Linux下,,,查看PATH变量
显示某个环境变量值 echo $PATH
2、HOME :用户的主工作目录  ,,,指的是系统打开时 默认的路径
[wxeast@localhost ~]$ echo  $HOME/home/wxeast
这里的/home/wxeast  为我安装的系统的主工作目录 
3、HISTSIZE:指保存历史命令记录的条数。

4、LOGNAME:指当前⽤用户的登录名。
[wxeast@localhost ~]$ echo $LOGNAMEwxeast
wxeast为此系统的登录名 
5、HOSTNAME:指主机的名称
[wxeast@localhost ~]$ echo  $HOSTNAMElocalhost.localdomain
6、SHELL:指当前用户用的是哪种Shell。
[wxeast@localhost ~]$ echo $SHELL/bin/bash
7、LANG/LANGUGE:和语言相关的环境变量,使用多种语言的用户可以修改此环境变量。
[wxeast@localhost ~]$ echo $LANGen_US.UTF-8

8、MAIL:指当前用户的邮件存放目录。
[wxeast@localhost ~]$ echo  $MAIL/var/spool/mail/wxeast

9、PS1:命令基本提⽰示符,对于root⽤用户是#,对于普通⽤用户是$。
[wxeast@localhost ~]$ echo $PS1[\u@\h \W]\$

10、PS2:附属提示符,默认是“>”。
[wxeast@localhost ~]$ echo  $PS2>
注意:上述变量的名字并不固定,如HOSTNAME在某些Linux系统
中可能设置成HOST



当然Linux也提供了修改和查看环境变量的命令

1、echo   显示某个环境变量     例如  :echo $PATH
2、export  添加或者修改某个环境变量    
例如要在当前的搜索路径加上一个  新的路径
[wxeast@localhost ~]$ export PATH=$PATH:/home/wxeast/Linux[wxeast@localhost ~]$ echo  $PATH/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/home/wxeast/bin:/home/wxeast/Linux
在原有的环境变量PATH下,,添加新的搜索路径
3、env   显示所有的环境变量
4、set    显示本地的shell变量(包含的有环境变量还有的就是 其他的变量)
5、unset 清除环境变量

Linux下的文件类型 


Linux下的文件是么有 文件的后缀名的 像".txt"、".doc"什么的,,,,,

Linux下的文件是通过,,文件的首字符来判断文件的类型 的
 
文件的类型 :
1、普通文件        首字符为 【-】;
2、目录文件        首字符为 【d】;
3、连接文件        首字符为 【l】;  像我们平常所使用的快捷方式
4、块设备、块设备文件    
1)块设备文件        首字符为【b】 ,,,比如硬盘 
2)字符设备文件     首字符为【c】 ,,,比如鼠标、键盘
5、套接字(sockets)    首字符为 【s】
6、管道(FIFO,pipe)   首字符为【p】

Linux下的shell指令的运行

Linux严格意义上说的是一个操作系统,我们称之为“核心(kernel)“ ,但我们一般用户,不能直接使用kernel。而是通过kernel的“外壳”程序,也就是所谓的shell,来与kernel沟通。

shell又被称为是   命令行解释字;;;
在此处有 主要的两个作用 :
1、将使用者的命令翻译给   操作系统来处理 ;
2、把操作系统的处理结果返回给使用者
另外、、、、、shell还有保护操作系统的作用 ,,,,要是命令   不是很正确,,,,,shell会自动舍弃。。。


Linux下的文件访问权限

Linux下的文件访问权限
主要分为三类人:
1、用户(文件的所有者)   user   简称为是 u
2、文件的所有组    group   简称为 是 g
3、其他人      others    简称是 o


对于一个文件的访问权限也有三种  
【r】读
【w】写
【x】执行
看下面一幅图、、来了解Linux下的文件是怎么来表示 不同的人的访问权限的


文件权限的表示 
rwx   表示文件可读、可写、可执行
r--    表示文件只可读
rw-   表示文件可读、可写


另外,,,也有一种文件权限的八进制表现形式 



如何更改文件的访问权限????


对于很多的文件我们需要对文件进行读写;;;但是该文件不支持次权限;;;我们就需要来更改文件的访问权限

修改文件的权限有三种改法:

修改文件的所有者:

使用  命令 chown 
格式:chown [参数]  用户名 文件名
这里的参数可以是   -R  表示的是   递归修改目录下的所有文件的所有者


实例(假设我们要修改的是file文件的拥有者)
[wxeast@localhost Linux]$ chown root  filechown: changing ownership of `file': Operation not permitted
这样显示表示我们的权限不够  ,,,,我们需要在root权限下来操作
[wxeast@localhost Linux]$ su
su可进入到root权限下,,,,
[root@localhost Linux]# chown root file[root@localhost Linux]# lltotal 4-rw-rw-r--. 1 root   wxeast    0 Mar 13 13:24 file-rw-rw-r--. 1 wxeast wxeast    0 Mar 13 13:43 file.c-rw-rw-r--. 1 wxeast wxeast 1304 Mar 14 17:29 myfile
表示修改成功

如果要修改一个目录下所有文件的拥有者
假设要修改的是 Linux下的所有文件的
[root@localhost wxeast]# chown -R root Linux[root@localhost wxeast]# lltotal 36drwxr-xr-x. 2 wxeast wxeast 4096 Mar 13 07:13 Desktopdrwxr-xr-x. 2 wxeast wxeast 4096 Mar 13 07:13 Documentsdrwxr-xr-x. 2 wxeast wxeast 4096 Mar 13 07:13 Downloadsdrwxrwxr-x. 2 root   wxeast 4096 Mar 13 13:49 Linuxdrwxr-xr-x. 2 wxeast wxeast 4096 Mar 13 07:13 Musicdrwxr-xr-x. 2 wxeast wxeast 4096 Mar 13 07:13 Picturesdrwxr-xr-x. 2 wxeast wxeast 4096 Mar 13 07:13 Publicdrwxr-xr-x. 2 wxeast wxeast 4096 Mar 13 07:13 Templatesdrwxr-xr-x. 2 wxeast wxeast 4096 Mar 13 07:13 Videos[root@localhost wxeast]# cd Linux[root@localhost Linux]# lltotal 4-rw-rw-r--. 1 root wxeast    0 Mar 13 13:24 file-rw-rw-r--. 1 root wxeast    0 Mar 13 13:43 file.c-rw-rw-r--. 1 root wxeast 1304 Mar 14 17:29 myfile


修改文件的所在组 

使用的是 chgrp命令 (此命令也需要在root权限下使用)
[root@localhost Linux]# chgrp root file[root@localhost Linux]# lltotal 4-rw-rw-r--. 1 root   root      0 Mar 13 13:24 file-rw-rw-r--. 1 wxeast wxeast    0 Mar 13 13:43 file.c-rw-rw-r--. 1 wxeast wxeast 1304 Mar 14 17:29 myfile
递归修改与chown  命令相同


修改文件的使用权限

chmod命令权限值的格式
① 用户表示符+/-=权限字符
+:向权限范围增加权限代号所表示的权限
-:向权限范围取消权限代号所表示的权限
=:向权限范围赋予权限代号所表示的权限
用户符号:
u:拥有者
g:拥有者同组用户
o:其它用户
a:所有用户

[wxeast@localhost Linux]$ lsfile  file.c  myfile[wxeast@localhost Linux]$ lltotal 4-rw-rw-r--. 1 wxeast wxeast    0 Mar 13 13:24 file-rw-rw-r--. 1 wxeast wxeast    0 Mar 13 13:43 file.c-rw-rw-r--. 1 wxeast wxeast 1304 Mar 14 17:29 myfile
假设将  file文件的user    的权限改为只可读(当前的权限为可读可写)
[wxeast@localhost Linux]$ chmod u-w file[wxeast@localhost Linux]$ lltotal 4-r--rw-r--. 1 wxeast wxeast    0 Mar 13 13:24 file-rw-rw-r--. 1 wxeast wxeast    0 Mar 13 13:43 file.c-rw-rw-r--. 1 wxeast wxeast 1304 Mar 14 17:29 myfile
除此之外,,,我们还可以使用八进制的方式来更改文件的权限
(该方法可直接对于三类群体进行直接修改)
[wxeast@localhost Linux]$ chmod  666  file[wxeast@localhost Linux]$ lltotal 4-rw-rw-rw-. 1 wxeast wxeast    0 Mar 13 13:24 file-rw-rw-r--. 1 wxeast wxeast    0 Mar 13 13:43 file.c-rw-rw-r--. 1 wxeast wxeast 1304 Mar 14 17:29 myfile

umask命令

功能:查看或修改文件掩码
什么意思呢???
就是  我们一般新建的文件的访问权限     为  666 (rw-rw-rw-)(只有一些特殊的执行文件的权限为777)
但是  实际上我们默认新建的文件的访问权限都会去掉掩码的权限
[wxeast@localhost Linux]$ umask0002

当前系统下的文件掩码是 002   ,,,也就是 文件的创建需要去掉others的读权限
因此、、、我们默认创建的文件的权限应该为 664(rw-rw-r--)
[wxeast@localhost Linux]$ touch test[wxeast@localhost Linux]$ lltotal 4-rw-rw-rw-. 1 wxeast wxeast    0 Mar 13 13:24 file-rw-rw-r--. 1 wxeast wxeast    0 Mar 13 13:43 file.c-rw-rw-r--. 1 wxeast wxeast 1304 Mar 14 17:29 myfile-rw-rw-r--. 1 wxeast wxeast    0 Mar 16 13:55 test
另外也可以使用 unmask  掩码      来修改计算机的掩码




补充一些基础操作命令 

1、ls  显示当前目录下的文件

[wxeast@localhost Linux]$ lsfile  file.c  myfile  test

-a   列出目录下的所有文件,包括以 . 开头的隐含⽂文件。
[wxeast@localhost Linux]$ ls -a.  ..  file  file.c  myfile  test


-l 列出文件的详细信息。
[wxeast@localhost Linux]$ ls -ltotal 4-rw-rw-rw-. 1 wxeast wxeast    0 Mar 13 13:24 file-rw-rw-r--. 1 wxeast wxeast    0 Mar 13 13:43 file.c-rw-rw-r--. 1 wxeast wxeast 1304 Mar 14 17:29 myfile-rw-rw-r--. 1 wxeast wxeast    0 Mar 16 13:55 test

-s 在文件名后输出该文件的大小
[wxeast@localhost Linux]$ ls -stotal 40 file  0 file.c  4 myfile  0 test


-t 以时间排序。


2、cd命令


cd ~   切换到用户的主工作目录下
cd ..   切换到当前目录下的上一级目录
cd /    切换到根目录下
cd -    切换到 历史目录下


3、date指令

date 指定格式显示时间:date +%Y_%m_%d, date +%Y:%m:%d

[wxeast@localhost Linux]$ date +%Y-%m-%d-%H:%M:%S2017-03-16-14:10:48

date +%s   显示的是时间戳(从1970年1月1日(UTC/GMT的午夜)开始所经过的秒数,不考虑闰秒。)
[wxeast@localhost Linux]$ date +%s1489688869

4、Cal指令

显示日历
[wxeast@localhost Linux]$ cal     March 2017     Su Mo Tu We Th Fr Sa          1  2  3  4 5  6  7  8  9 10 1112 13 14 15 16 17 1819 20 21 22 23 24 2526 27 28 29 30 31

命令参数:
-1 显示一个月的月历
-3 显示系统前一个月,当前月,下一个月的月历
-s 显示星期天为一个星期的第一天,默认的格式
-m 显示星期一为一个星期的第一天


5、touch指令

创建一个文件普通文件

6、mkdir指令

创建一个目录文件


递归建立多个目录:mkdir –p test/test1
[wxeast@localhost Linux]$ mkdir -p test1/test2/test3[wxeast@localhost Linux]$ lsfile  file.c  myfile  test  test1[wxeast@localhost Linux]$ cd test1[wxeast@localhost test1]$ lstest2[wxeast@localhost test1]$ cd test2[wxeast@localhost test2]$ lstest3

7、rmdir指令 && rm 指令(重要):

这两个指令都是文件的删除指令但是 

rmdir  只能删除 空的目录文件


rm  删除文件
参数:
-f 即使文件属性为只读(即写保护),亦直接删除
-i 删除前逐一询问确认
-r 删除目录及其下所有文件
[wxeast@localhost Linux]$ mkdir -p test1/test2/test3[wxeast@localhost Linux]$ lsfile  file.c  myfile  test  test1[wxeast@localhost Linux]$ cd test1[wxeast@localhost test1]$ lstest2[wxeast@localhost test1]$ cd test2[wxeast@localhost test2]$ lstest3[wxeast@localhost test2]$ cd ..[wxeast@localhost test1]$ cd ..[wxeast@localhost Linux]$ lsfile  file.c  myfile  test  test1[wxeast@localhost Linux]$ rm -r test1[wxeast@localhost Linux]$ lsfile  file.c  myfile  test


8、cp指令


赋值文件到指定的目录

格式    : cp  【参数】 复制的文件   复制到的文件目录

9、mv指令

移动某个文件到指定的目录


格式    :  mv  【参数】 移动的文件 移动到的目标文件或目录


 
0 0