Linux Learning & Replay (a): The Basics

This article is to learn from [ rookie tutorial do] after the notes.

 

 
 
 1. Account

If the username is not root, and there is  / etc / nologin  file, login nologin will output the contents of the file, and then exit.

This prevents non-root user login time is usually used for system maintenance. Only / / etc securetty registered in the terminal only allow the root user login, if the file does not exist, the root user can log on any terminal.

/ etc / usertty file is used to make an additional user access restrictions , if the file does not exist, there are no other restrictions

 
 
2, Linux provides six preset command terminal window Let's log in, the default login is our first window
1:2345:respawn:/sbin/mingetty tty1
2:2345:respawn:/sbin/mingetty tty2
3:2345:respawn:/sbin/mingetty tty3
4:2345:respawn:/sbin/mingetty tty4
5:2345:respawn:/sbin/mingetty tty5
6:2345:respawn:/sbin/mingetty tty6
 
3, shutdown
  sync > shutdown > reboot > halt
sync 将数据由内存同步到硬盘中。

shutdown 关机指令,你可以man shutdown 来看一下帮助文档。例如你可以运行如下命令关机:

shutdown –h 10‘This server will shutdown after 10 mins’
这个命令告诉大家,计算机将在10分钟后关机,并且会显示在登陆用户的当前屏幕中。

shutdown –h now 立马关机

shutdown –h 20:25系统会在今天20:25关机

shutdown –h +10十分钟后关机

shutdown –r now 系统立马重启

shutdown –r +10系统十分钟后重启

reboot 就是重启,等同于 shutdown –r now

halt 关闭系统,等同于shutdown –h now 和 poweroff
 
4, the current directory parent directory
  •  . : Represents the current directory, you can also use the ./ to indicate;
  •  ..  : On behalf of parent directory, you can also ../ be represented.
 
5, hidden files, hidden folders
 If a directory or file name to a point  Start, indicating that the file or directory is a hidden directory or a file (such as: .bashrc ). That is to find ways to default, the directory or file is not displayed.
 
6, the system folder
  System startup must:
  • boot: kernel files stored using the boot Linux, including connected files and image files.
     
  • / etc: store all the systems required configuration files and subdirectories list of changed files directory may cause the system will not boot.
     
  • / lib : storing basic code base (such as c ++ library), where its role is similar to Windows DLL files. Almost all applications need to use these shared libraries.
     
  • / SYS : This is a core linux2.6 great changes. The directory of a file system sysfs 2.6 kernel emerging installation. sysfs file system integrates information on the following three kinds of file systems: for proc file system processes information for devfs file system devices and file systems for devpts pseudo terminal. The file system is a visual reflection of kernel device tree. When a kernel object is created, the corresponding files and directories are kernel objects subsystem

Instruction set:

  • / bin: to store the most frequently used programs and instruction
  • / sbin: Only program instructions and system administrators can use.

External File Management:

  • /dev :Device(设备)的缩写, 存放的是Linux的外部设备。注意:在Linux中访问设备和访问文件的方式是相同的。
     
  • /media:类windows的其他设备,例如U盘、光驱等等,识别后linux会把设备放到这个目录下。
     
  • /mnt:临时挂载别的文件系统的,我们可以将光驱挂载在/mnt/上,然后进入该目录就可以查看光驱里的内容了。

临时文件:

  • /run:是一个临时文件系统,存储系统启动以来的信息。当系统重启时,这个目录下的文件应该被删掉或清除。如果你的系统上有 /var/run 目录,应该让它指向 run。
     
  • /lost+found:一般情况下为空的,系统非法关机后,这里就存放一些文件。
     
  • /tmp:这个目录是用来存放一些临时文件的。

账户:

  • /root:系统管理员的用户主目录。
     
  • /home:用户的主目录,以用户的账号命名的。
     
  • /usr:用户的很多应用程序和文件都放在这个目录下,类似于windows下的program files目录。
     
  • /usr/bin:系统用户使用的应用程序与指令。
     
  • /usr/sbin:超级用户使用的比较高级的管理程序和系统守护程序。
     
  • /usr/src:内核源代码默认的放置目录。

运行过程中要用:

  • /var:存放经常修改的数据,比如程序运行的日志文件(/var/log 目录下)。
     
  • /proc:管理内存空间!虚拟的目录,是系统内存的映射,我们可以直接访问这个目录来,获取系统信息。这个目录的内容不在硬盘上而是在内存里,我们也可以直接修改里面的某些文件来做修改。

扩展用的:

  • /opt:默认是空的,我们安装额外软件可以放在这个里面。
     
  • /srv:存放服务启动后需要提取的数据(不用服务器就是空)
 
7、Linux系统中是通过ssh服务实现的远程登录功能,默认ssh服务端口号为 22。
 
8、文件属性
 在Linux中第一个字符代表这个文件是目录文件链接文件等等。
  • 当为[ d ]则是目录
  • 当为[ - ]则是文件;
  • 若是[ l ]则表示为链接文档(link file);
  • 若是[ b ]则表示为装置文件里面的可供储存的接口设备(可随机存取装置);
  • 若是[ c ]则表示为装置文件里面的串行端口设备,例如键盘、鼠标(一次性读取装置)。

接下来的字符中,以三个为一组,且均为『rwx』 的三个参数的组合。其中
,[ r ]代表可读(read)、[ w ]代表可写(write)、[ x ]代表可执行(execute)。
 要注意的是,这三个权限的位置不会改变,如果没有权限,就会出现减号[ - ]而已。

每个文件的属性由左边第一部分的10个字符来确定(如下图)。

从左至右用0-9这些数字来表示。

第0位确定文件类型,第1-3位确定属主(该文件的所有者)拥有该文件的权限。

第4-6位确定属组(所有者的同组用户)拥有该文件的权限,第7-9位确定其他用户拥有该文件的权限。

其中,第1、4、7位表示读权限,如果用"r"字符表示,则有读权限,如果用"-"字符表示,则没有读权限;

第2、5、8位表示写权限,如果用"w"字符表示,则有写权限,如果用"-"字符表示没有写权限;
第3、6、9位表示可执行权限,如果用"x"字符表示,则有执行权限,如果用"-"字符表示,则没有执行权限。

 

更改文件属性

1、chgrp:更改文件属组

语法:

chgrp [-R]属组名文件名

参数选项

  • -R:递归更改文件属组,就是在更改某个目录文件的属组时,如果加上-R的参数,
    那么该目录下的所有文件的属组都会更改。

2、chown:更改文件属主,也可以同时更改文件属组

语法:

chown [–R]属主名文件名
chown [-R]属主名:属组名文件名

进入 /root 目录(~)将install.log的拥有者改为bin这个账号:

[root@www ~] cd ~[root@www ~]# chown bin install.log
[root@www ~]# ls -l
-rw-r--r--1 bin  users 68495Jun2508:53 install.log

将install.log的拥有者与群组改回为root:

[root@www ~]# chown root:root install.log
[root@www ~]# ls -l
-rw-r--r--1 root root 68495Jun2508:53 install.log

3、chmod:更改文件9个属性

Linux文件属性有两种设置方法,一种是数字,一种是符号。

Linux文件的基本权限就有九个,分别是owner/group/others三种身份各有自己的read/write/execute权限。

先复习一下刚刚上面提到的数据:文件的权限字符为:『-rwxrwxrwx』,
 这九个权限是三个三个一组的!其中,我们可以使用数字来代表各个权限,各权限的分数对照表如下:

  • r:4
  • w:2
  • x:1

每种身份(owner/group/others)各自的三个权限(r/w/x)分数是需要累加的,
例如当权限为: [-rwxrwx---] 分数则是:

  • owner = rwx = 4+2+1 = 7
  • group = rwx = 4+2+1 = 7
  • others= --- = 0+0+0 = 0

所以等一下我们设定权限的变更时,该文件的权限数字就是770啦!
变更权限的指令chmod的语法是这样的:

 chmod [-R] xyz 文件或目录

选项与参数:

  • xyz : 就是刚刚提到的数字类型的权限属性,为 rwx 属性数值的相加。
  • -R : 进行递归(recursive)的持续变更,亦即连同次目录下的所有文件都会变更

举例来说,如果要将.bashrc这个文件所有的权限都设定启用,那么命令如下:

[root@www ~]# ls -al .bashrc
-rw-r--r--1 root root 395Jul411:45.bashrc
[root@www ~]# chmod 777.bashrc
[root@www ~]# ls -al .bashrc
-rwxrwxrwx  1 root root 395Jul411:45.bashrc

那如果要将权限变成 -rwxr-xr-- 呢?那么权限的分数就成为 [4+2+1][4+0+1][4+0+0]=754。

符号类型改变文件权限

还有一个改变权限的方法,从之前的介绍中我们可以发现,基本上就九个权限分别是:

  • (1)user
  • (2)group
  • (3)others

那么我们就可以使用 u, g, o 来代表三种身份的权限!

此外, a 则代表 all,即全部的身份。读写的权限可以写成 r, w, x,也就是可以使用下表的方式来看:

chmod u
g
o
a
+(加入)
-(除去)
=(设定)
r
w
x
文件或目录

如果我们需要将文件权限设置为 -rwxr-xr-- ,可以使用 chmod u=rwx,g=rx,o=r 文件名 来设定:

#  touch test1    // 创建 test1 文件
# ls -al test1    // 查看 test1 默认权限
-rw-r--r--1 root root 0Nov1510:32 test1
# chmod u=rwx,g=rx,o=r  test1   
 // 修改 test1 权限# 
ls -al test1-rwxr-xr--1 root root 0Nov1510:32 test1

而如果是要将权限去掉而不改变其他已存在的权限呢?例如要拿掉全部人的可执行权限,则:

#  chmod  a-x test1# ls -al test1-rw-r--r--1 root root 0Nov1510:32 test1
 
 
 
系统运行级别配置文件:    /etc/inittab

常用的是   3   &   5  
 

 

忘记root密码处理
 
1、  进入单用户模式    1
2、  e  进入     b启动
3、passws root 
4、输入新密码
5、ok   正常重启进入Linux
 
 
查看帮助命令
man 命令  
man  ls
 
 
 
 
 

1.Linux 链接概念

Linux 链接分两种,一种被称为硬链接(Hard Link),另一种被称为符号链接(Symbolic Link)。默认情况下,ln 命令产生硬链接。

硬连接

硬连接指通过索引节点来进行连接。在 Linux 的文件系统中,保存在磁盘分区中的文件不管是什么类型都给它分配一个编号,称为索引节点号(Inode Index)。在 Linux 中,多个文件名指向同一索引节点是存在的。比如:A 是 B 的硬链接(A 和 B 都是文件名),则 A 的目录项中的 inode 节点号与 B 的目录项中的 inode 节点号相同,即一个 inode 节点对应两个不同的文件名,两个文件名指向同一个文件,A 和 B 对文件系统来说是完全平等的。删除其中任何一个都不会影响另外一个的访问。

硬连接的作用是允许一个文件拥有多个有效路径名,这样用户就可以建立硬连接到重要文件,以防止“误删”的功能。其原因如上所述,因为对应该目录的索引节点有一个以上的连接。只删除一个连接并不影响索引节点本身和其它的连接,只有当最后一个连接被删除后,文件的数据块及目录的连接才会被释放。也就是说,文件真正删除的条件是与之相关的所有硬连接文件均被删除

软连接

另外一种连接称之为符号连接(Symbolic Link),也叫软连接。软链接文件有类似于 Windows 的快捷方式。它实际上是一个特殊的文件。在符号连接中,文件实际上是一个文本文件,其中包含的有另一文件的位置信息。比如:A 是 B 的软链接(A 和 B 都是文件名),A 的目录项中的 inode 节点号与 B 的目录项中的 inode 节点号不相同,A 和 B 指向的是两个不同的 inode,继而指向两块不同的数据块。但是 A 的数据块中存放的只是 B 的路径名(可以根据这个找到 B 的目录项)。A 和 B 之间是“主从”关系,如果 B 被删除了,A 仍然存在(因为两个是不同的文件),但指向的是一个无效的链接。

2.通过实验加深理解

[oracle@Linux]$ touch f1          #创建一个测试文件f1[oracle@Linux]$ ln f1 f2          #创建f1的一个硬连接文件f2[oracle@Linux]$ ln -s f1 f3       #创建f1的一个符号连接文件f3[oracle@Linux]$ ls -li            # -i参数显示文件的inode节点信息
total 09797648-rw-r--r--2 oracle oinstall 0Apr2108:11 f1
9797648-rw-r--r--2 oracle oinstall 0Apr2108:11 f2
9797649 lrwxrwxrwx  1 oracle oinstall 2Apr2108:11 f3 -> f1

从上面的结果中可以看出,硬连接文件 f2 与原文件 f1 的 inode 节点相同,均为 9797648,然而符号连接文件的 inode 节点不同。

[oracle@Linux]$ echo "I am f1 file">>f1
[oracle@Linux]$ cat f1
I am f1 file
[oracle@Linux]$ cat f2
I am f1 file
[oracle@Linux]$ cat f3
I am f1 file
[oracle@Linux]$ rm -f f1
[oracle@Linux]$ cat f2
I am f1 file
[oracle@Linux]$ cat f3
cat: f3:No such file or directory

通过上面的测试可以看出:当删除原始文件 f1 后,硬连接 f2 不受影响,但是符号连接 f1 文件无效

3.总结

依此您可以做一些相关的测试,可以得到以下全部结论:

  •  1).删除符号连接f3,对f1,f2无影响;
  •  2).删除硬连接f2,对f1,f3也无影响;
  •  3).删除原文件f1,对硬连接f2没有影响,导致符号连接f3失效;
  •  4).同时删除原文件f1,硬连接f2,整个文件会真正的被删除。
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

 
发布了19 篇原创文章 · 获赞 10 · 访问量 3万+

Guess you like

Origin blog.csdn.net/Cupster/article/details/104478566