【ONE·Linux || 常见指令入门(一)】

总言

  Linux下常见指令基本介绍。


  
  

1、前言

  我们敲击指令,究竟是在做什么?使用Linux。
  本质上这些命令都是可执行程序。Windows下或Linux下安装软件,本质上是将.exe程序拷贝到自己的主机上。
  
  
  

2、用户创建与删除

  相关指令:useradd、userdel -r
  
  

3、pwd

在这里插入图片描述
  演示如下:

[wj@VM-4-3-centos /]$ ls
bin  boot  data  dev  etc  home  lib  lib64  lost+found  media  mnt  opt  proc  root  run  sbin  srv  sys  tmp  usr  var
[wj@VM-4-3-centos /]$ pwd //使用pwd指令
/  //显示当前路径
[wj@VM-4-3-centos /]$ cd ~
[wj@VM-4-3-centos ~]$ pwd //使用pwd指令
/home/wj //显示当前路径

  
  

4、ls指令

在这里插入图片描述
  

4.1、文件属性

  问题引入:在磁盘上创建一个空文件,该文件是否占据一定的磁盘空间?
  答案:是。原因如下:
  因此,当创建一个空文件时,我们也记录了其数据。
在这里插入图片描述
  实际上ls所做的事就是显示文件属性。
  
  

4.2、隐藏文件

  我们知道windows下有隐藏文件,实际Linux下也有隐藏文件,那么如何创建一个隐藏文件?
在这里插入图片描述
  关于隐藏文件第一个基本用途:隐藏一些配置文件

[wj@VM-4-3-centos home]$ cd wj
[wj@VM-4-3-centos ~]$ ls
code  install.sh  one.-studybylinux
[wj@VM-4-3-centos ~]$ ls -l
total 12
drwxrwxr-x 4 wj wj 4096 Sep 14 16:03 code
-rw-rw-r-- 1 wj wj  827 Aug 21 21:22 install.sh
drwxrwxr-x 4 wj wj 4096 Sep 17 17:31 one.-studybylinux


[wj@VM-4-3-centos ~]$ ls -al
total 124
drwx------  10 wj   wj    4096 Sep 17 17:30 .
drwxr-xr-x.  6 root root  4096 Aug 20 20:47 ..
-rw-------   1 wj   wj   49657 Oct 31 14:39 .bash_history
-rw-r--r--   1 wj   wj      18 Apr  1  2020 .bash_logout
-rw-r--r--   1 wj   wj     193 Apr  1  2020 .bash_profile
-rw-r--r--   1 wj   wj     350 Aug 21 21:24 .bashrc
drwxrwxr-x   3 wj   wj    4096 Aug  8 10:40 .cache
drwxrwxr-x   4 wj   wj    4096 Sep 14 16:03 code
drwxrwxr-x   3 wj   wj    4096 Aug 21 21:24 .config
lrwxrwxrwx   1 wj   wj      47 Aug 21 21:24 .cquery -> /home/wj/.VimForCpp/cquery/config/cquery.config
-rw-rw-r--   1 wj   wj      49 Aug 27 19:40 .gitconfig
-rw-rw-r--   1 wj   wj     827 Aug 21 21:22 install.sh
-rw-------   1 wj   wj      49 Sep 17 16:05 .lesshst
drwxrwxr-x   3 wj   wj    4096 Aug 21 21:24 .LfCache
drwx------   3 wj   wj    4096 Aug 21 21:24 .local
drwxrwxr-x   4 wj   wj    4096 Sep 17 17:31 one.-studybylinux
drwxrw----   3 wj   wj    4096 Aug 21 21:22 .pki
lrwxrwxrwx   1 wj   wj      23 Aug 21 21:24 .vim -> /home/wj/.VimForCpp/vim
drwxrwxr-x   8 wj   wj    4096 Aug 21 21:23 .VimForCpp
-rw-------   1 wj   wj    2387 Aug 21 21:18 .viminfo
lrwxrwxrwx   1 wj   wj      32 Aug 21 21:24 .vimrc -> /home/wj/.VimForCpp/vim/init.vim
lrwxrwxrwx   1 wj   wj      37 Aug 21 21:24 .ycm_extra_conf.py -> /home/wj/.VimForCpp/ycm_extra_conf.py
[wj@VM-4-3-centos ~]$ 

  
  

4.3、-a 选项

-a:列出目录下的所有文件,包括以 . 开头的隐含文件。

[wj@VM-4-3-centos code]$ ls -al
total 12
drwxrwxr-x 3 wj wj 4096 Aug  8 15:07 .
drwx------ 5 wj wj 4096 Aug  8 13:51 ..
-rw-rw-r-- 1 wj wj    0 Aug  8 15:06 .hide.txt
drwxrwxr-x 2 wj wj 4096 Aug  8 15:07 .mydir
-rw-rw-r-- 1 wj wj    0 Aug  8 13:52 text.tex


[wj@VM-4-3-centos code]$ ls -a -l
total 12
drwxrwxr-x 3 wj wj 4096 Aug  8 15:07 .
drwx------ 5 wj wj 4096 Aug  8 13:51 ..
-rw-rw-r-- 1 wj wj    0 Aug  8 15:06 .hide.txt
drwxrwxr-x 2 wj wj 4096 Aug  8 15:07 .mydir
-rw-rw-r-- 1 wj wj    0 Aug  8 13:52 text.tex


[wj@VM-4-3-centos code]$ ls -l -a
total 12
drwxrwxr-x 3 wj wj 4096 Aug  8 15:07 .
drwx------ 5 wj wj 4096 Aug  8 13:51 ..
-rw-rw-r-- 1 wj wj    0 Aug  8 15:06 .hide.txt
drwxrwxr-x 2 wj wj 4096 Aug  8 15:07 .mydir
-rw-rw-r-- 1 wj wj    0 Aug  8 13:52 text.tex

  
  

4.4、-i 选项

-i:输出文件的 i 节点的索引信息。 如 ls –ai 指定文件
-i选项:查看文件inode编号,具体内容后续才会学到。

[wj@VM-4-3-centos code]$ ls -a -l -i
total 12
655381 drwxrwxr-x 3 wj wj 4096 Aug  8 15:07 .
655485 drwx------ 5 wj wj 4096 Aug  8 13:51 ..
655505 -rw-rw-r-- 1 wj wj    0 Aug  8 15:06 .hide.txt
655509 drwxrwxr-x 2 wj wj 4096 Aug  8 15:07 .mydir
655504 -rw-rw-r-- 1 wj wj    0 Aug  8 13:52 text.tex
//最前面的这串数字即为inode编号


[wj@VM-4-3-centos code]$ ls -l -a -i
total 12
655381 drwxrwxr-x 3 wj wj 4096 Aug  8 15:07 .
655485 drwx------ 5 wj wj 4096 Aug  8 13:51 ..
655505 -rw-rw-r-- 1 wj wj    0 Aug  8 15:06 .hide.txt
655509 drwxrwxr-x 2 wj wj 4096 Aug  8 15:07 .mydir
655504 -rw-rw-r-- 1 wj wj    0 Aug  8 13:52 text.tex



[wj@VM-4-3-centos code]$ ls -ali
total 12
655381 drwxrwxr-x 3 wj wj 4096 Aug  8 15:07 .
655485 drwx------ 5 wj wj 4096 Aug  8 13:51 ..
655505 -rw-rw-r-- 1 wj wj    0 Aug  8 15:06 .hide.txt
655509 drwxrwxr-x 2 wj wj 4096 Aug  8 15:07 .mydir
655504 -rw-rw-r-- 1 wj wj    0 Aug  8 13:52 text.tex


  
  

[wj@VM-4-3-centos code]$ ls -al
total 12
drwxrwxr-x 3 wj wj 4096 Aug  8 15:07 .
drwx------ 5 wj wj 4096 Aug  8 13:51 ..
-rw-rw-r-- 1 wj wj    0 Aug  8 15:06 .hide.txt
drwxrwxr-x 2 wj wj 4096 Aug  8 15:07 .mydir
-rw-rw-r-- 1 wj wj    0 Aug  8 13:52 text.tex
[wj@VM-4-3-centos code]$ pwd
/home/wj/code


[wj@VM-4-3-centos code]$ cd


[wj@VM-4-3-centos ~]$ ls -al
total 36
drwx------  5 wj   wj   4096 Aug  8 13:51 .
drwxr-xr-x. 4 root root 4096 Aug  8 10:02 ..
-rw-------  1 wj   wj   1059 Aug  8 15:30 .bash_history
-rw-r--r--  1 wj   wj     18 Apr  1  2020 .bash_logout
-rw-r--r--  1 wj   wj    193 Apr  1  2020 .bash_profile
-rw-r--r--  1 wj   wj    231 Apr  1  2020 .bashrc
drwxrwxr-x  3 wj   wj   4096 Aug  8 10:40 .cache
drwxrwxr-x  3 wj   wj   4096 Aug  8 15:07 code
drwxrwxr-x  3 wj   wj   4096 Aug  8 10:40 .config
[wj@VM-4-3-centos ~]$ pwd
/home/wj


  
  

5、cd 指令

5.1、基本介绍

在这里插入图片描述
  
  

5.2、目录、绝对路径、相对路径

5.2.1、当前路径、上级路径

  此处需要注意"." 、“..” :当前路径、直接上级路径的作用,即它们一般是用来干嘛的。
在这里插入图片描述
  
  
  

5.2.2、根目录

[wj@VM-4-3-centos ~]$ 
[wj@VM-4-3-centos ~]$ cd /home/wj/code //'/'斜杆路径分隔符,分割文件夹、文件
[wj@VM-4-3-centos code]$ pwd
/home/wj/code
[wj@VM-4-3-centos code]$ cd ..
[wj@VM-4-3-centos ~]$ pwd
/home/wj
[wj@VM-4-3-centos ~]$ cd ..
[wj@VM-4-3-centos home]$ pwd
/home
[wj@VM-4-3-centos home]$ cd ..
[wj@VM-4-3-centos /]$ pwd
/  //根目录
[wj@VM-4-3-centos /]$ cd ..//到根目录后再次无法再往上级跳转。
[wj@VM-4-3-centos /]$ pwd
/
[wj@VM-4-3-centos /]$ 

  
  说明:
在这里插入图片描述
  
  
  问题:为什么能通过路径定位到文件所在位置?
  回答: 文件的路径具有唯一性(树的性质,孩子节点只能有一个父节点)。
  
  注意事项: Linux和windows路径分隔符是不同的。

Linux:/home/wj/code

Windows:D:\Daily\visual studio 2019\program\selfstudy\allgame\game01

  
  
  

5.2.3、关于绝对路径和相对路径的使用

  绝对路径: 在日常操作中很少使用,一般常出现在比较正式的场合,比如配置文件中;
  相对路径: 常在日常操作中使用。
  
  以查找某路径下文件举例:

[wj@VM-4-3-centos ~]$ ls //当前在家目录下
code  install.sh  one.-studybylinux
[wj@VM-4-3-centos ~]$ cd one.-studybylinux //进入下一级one.-studybylinux目录
[wj@VM-4-3-centos one.-studybylinux]$ ls
README.en.md  README.md  study2022  text.c //可看到其中有一个text.c文件,这是我们要找的文件
[wj@VM-4-3-centos one.-studybylinux]$ cd study2022
[wj@VM-4-3-centos study2022]$ ls
T2209  T2211  text.c
[wj@VM-4-3-centos study2022]$ cd T2211
[wj@VM-4-3-centos T2211]$ ls
t1031
[wj@VM-4-3-centos T2211]$ cd t1031
[wj@VM-4-3-centos t1031]$ ls
[wj@VM-4-3-centos t1031]$ pwd
/home/wj/one.-studybylinux/study2022/T2211/t1031 //这是我们当前所在的路径


[wj@VM-4-3-centos t1031]$ ls ../../text.c -al  //使用相对路径定位文件的方法
-rw-rw-r-- 1 wj wj 0 Aug 27 19:54 ../../text.c

[wj@VM-4-3-centos t1031]$ ls /home/wj/one.-studybylinux/text.c -al  //使用绝对路径定位文件的方法
-rw-rw-r-- 1 wj wj 0 Aug 27 19:42 /home/wj/one.-studybylinux/text.c

  
  
  

5.3、cd ~ 、cd-

  简述:

cd ~:进入用户家目
cd -:返回最近访问目录

  

5.3.1、cd ~

  说明:
  对普通用户,当前用户的家目录(工作目录)为/home/XXX
  对root用户,家目录为 /root

//对cd~的演示
[wj@VM-4-3-centos /]$ cd ~
[wj@VM-4-3-centos ~]$ pwd
/home/wj
[wj@VM-4-3-centos ~]$ cd /
[wj@VM-4-3-centos /]$ pwd
/

  
  

5.3.2、cd -


//对cd-的演示
[wj@VM-4-3-centos /]$ cd ~ //先来到家目录
[wj@VM-4-3-centos ~]$ pwd
/home/wj//当前位置是/home/wj
[wj@VM-4-3-centos ~]$ 
[wj@VM-4-3-centos ~]$ cd - //cd -后返回最近访问的目录,即/
/        //当前位置是/根目录
[wj@VM-4-3-centos /]$ cd -//再次cd -后返回最近访问的目录,即/home/wj
/home/wj
[wj@VM-4-3-centos ~]$ cd -
/
[wj@VM-4-3-centos /]$ cd -
/home/wj

  
  Windows下用户家目录演示:
在这里插入图片描述
  
  
  

6、touch

6.1、基本介绍

在这里插入图片描述
  
  

6.2、使用说明

6.2.1、touch创建普通文件

[wj@VM-4-3-centos t1031]$ ls  //一开始t1031目录下没有文件
[wj@VM-4-3-centos t1031]$ touch myfile //使用touch创建了一个名为myfile的普通文件
[wj@VM-4-3-centos t1031]$ ls
myfile

  
  

6.2.2、touch更新文件、目录最近修改时间

  touch命令参数可更改文档或目录的日期时间,包括存取时间和更改时间,或者新建一个不存在的文件。
  
  关于文件日期更新相关演示:

[wj@VM-4-3-centos code]$ pwd
/home/wj/code
[wj@VM-4-3-centos code]$ ls
text.txt //当前目录下已有text.txt文件
[wj@VM-4-3-centos code]$ ll//ll:等同于 ls -l
total 0
-rw-rw-r-- 1 wj wj 0 Aug  8 13:52 text.txt//可以看到text.txt文件的创建时间

[wj@VM-4-3-centos code]$ touch text.txt//使用touch创建再次创建同名文件
[wj@VM-4-3-centos code]$ ll
total 0
-rw-rw-r-- 1 wj wj 0 Aug  8 17:56 text.txt//可看到该文件时间被更新

  
  
  

6.3、stat:获取文件时间

  问题:一个文件都有哪些时间?该怎么获取?

需要的命令:stat 文件名

  
  ACM时间说明:

[wj@VM-4-3-centos code]$ stat text.tex
  File: ‘text.tex’//表示文件名称
  Size: 0//文件大小      Blocks: 0          IO Block: 4096   regular empty file
Device: fd01h/64769d	Inode: 655504      Links: 1
Access: (0664/-rw-rw-r--)  Uid: ( 1001/      wj)   Gid: ( 1001/      wj)
Access: 2022-08-08 17:56:15.978077936 +0800//文件最近修改时间
Modify: 2022-08-08 17:56:15.978077936 +0800//文件内容最近修改时间
Change: 2022-08-08 17:56:15.978077936 +0800//文件属性最近修改时间
 Birth: -
[wj@VM-4-3-centos code]$ 

  
  
  

7、mkdir

7.1、基本介绍

在这里插入图片描述

  
  实际演示如下:
  需求:如何在当前目录下创建一系列路径?即:.../d1/d2/d3/d4

[wj@VM-4-3-centos code]$ pwd
/home/wj/code    //当前文件路径

[wj@VM-4-3-centos code]$ mkdir d1/d2/d3/d4 //若直接使用mkdir指令
mkdir: cannot create directory ‘d1/d2/d3/d4’: No such file or directory //可看到创建失败


[wj@VM-4-3-centos code]$ mkdir -p d1/d2/d3/d4  //此时需要引入-p选项
[wj@VM-4-3-centos code]$ ls -l
total 4
drwxrwxr-x 3 wj wj 4096 Aug  8 18:15 d1 //可看到成功创建了d1总目录
-rw-rw-r-- 1 wj wj    0 Aug  8 17:56 text.tex

[wj@VM-4-3-centos code]$ cd d1  //进入d1
[wj@VM-4-3-centos d1]$ pwd
/home/wj/code/d1 //d1当前路径

[wj@VM-4-3-centos d1]$ cd d2  //进入d2
[wj@VM-4-3-centos d2]$ ll
total 4
drwxrwxr-x 3 wj wj 4096 Aug  8 18:15 d3 //可看到d2目录下文件信息

[wj@VM-4-3-centos d2]$ cd d3  //进入d3
[wj@VM-4-3-centos d3]$ pwd
/home/wj/code/d1/d2/d3 //d3当前路径
[wj@VM-4-3-centos d3]$ ll
total 4
drwxrwxr-x 2 wj wj 4096 Aug  8 18:15 d4  //可看到d3目录下文件信息

[wj@VM-4-3-centos d3]$ cd d4  //进入d4
[wj@VM-4-3-centos d4]$ ll
total 0
[wj@VM-4-3-centos d4]$ pwd
/home/wj/code/d1/d2/d3/d4  //可看到路径都按照我们的需求创建出来了


  
  

7.2、tree

  基本说明: tree指令可用将路径以树状结构显示出来。
  
  1)、tree指令的安装

  现象说明: 当出现以下显示时,表示tree没有安装,此时需要登陆root用户进行安装。

[wj@VM-4-3-centos ~]$ tree
-bash: tree: command not found
[wj@VM-4-3-centos ~]$ tree .
-bash: tree: command not found

  
  相关按照指令: 登录超级用户输入下述命令,即可安装tree。当提示安装完成后(Complete!),此时再返回原先那个用户中,即可使用tree。

 yum install -y tree

  
  
  2)、tree指令的使用

  使用演示: 现在就可以执行tree命令了。
  
  1、未指定目录名而直接输入tree:对当前路径下所有文件显示其树状结构

[wj@VM-4-3-centos code]$ ls  //a1、d1为文件夹,text.cpp为单独文件
a1  d1  text.cpp
[wj@VM-4-3-centos code]$ pwd //当前在code路径下
/home/wj/code
[wj@VM-4-3-centos code]$ tree//未指定目录名而直接输入tree
.
|-- a1
|   `-- a2
|-- d1
|   `-- d2
|       `-- d3
|           `-- d4
`-- text.cpp

6 directories, 1 file
[wj@VM-4-3-centos code]$ 

  
  
  2、tree . :类似于 cd . (.表示当前目录)

[wj@VM-4-3-centos ~]$ tree .//此处tree+. 
.
`-- code
    |-- d1
    |   `-- d2
    |       `-- d3
    |           `-- d4
    `-- text.tex

5 directories, 1 file

  
  
  3、tree 当前目录下指定文件:可将指定文件按tree的结构显示

[wj@VM-4-3-centos code]$ pwd
/home/wj/code
[wj@VM-4-3-centos code]$ ls
d1  text.tex
[wj@VM-4-3-centos code]$ tree d1 //tree 当前目录下指定文件
d1
`-- d2
    `-- d3
        `-- d4

3 directories, 0 files

  
  
  4、在非对应路径下查看tree,结果为错误。即要确保当前目录下有指定文件。

[wj@VM-4-3-centos ~]$ ls //当前路径下无d1文件
install.sh  one.-studybylinux
[wj@VM-4-3-centos ~]$ pwd
/home/wj
[wj@VM-4-3-centos ~]$ tree d1 //此时tree + 当前路径下不存在的文件
d1 [error opening dir]

0 directories, 0 files
[wj@VM-4-3-centos ~]$ 

  
  5、延伸:如何验证我们访问了Linux下的文件?(使用例子是任意网址访问)

https://blog.csdn.net/EPIPHANYECHO/article/details/126425517

  /EPIPHANYECHO/article/details/126425517:此处,url后面的路径分隔符为/,就是Linux下的某一个目录。
  
  
  

8、rmdir、rm

8.1、rmdir

  说明: 单独使用rmidr指令,只能删除空目录。

  ①使用rmdir当删除先前的d1目录 ,删除失败。

[wj@VM-4-3-centos code]$ ls //根据之前mkdir中的操作,我们在../code下建立了d1/d2/d3/d4路径
d1  text.tex
[wj@VM-4-3-centos code]$ rmdir d1 //此时使用rmdir删除d1
rmdir: failed to remove ‘d1’: Directory not empty //会发现删除失败,原因是目录不为空

  
  ②使用rmdir删除空目录,删除成功:

[wj@VM-4-3-centos code]$ ls -a
.  ..  d1  .hide.txt  .mydir  text.tex  //之前创建了一个隐藏目录.mydir
[wj@VM-4-3-centos code]$ tree .mydir //tree可看到目录为空
.mydir

0 directories, 0 files
[wj@VM-4-3-centos code]$ rmdir .mydir //使用rmdir删除该隐藏文件
[wj@VM-4-3-centos code]$ ls -a //再用-a查看一下code目录下的所有文件
.  ..  d1  .hide.txt  text.tex  //可用看到.mydir目录被删除了
[wj@VM-4-3-centos code]$ 

  
  
  

8.2、rm

  说明: rm命令可以同时删除文件或目录
  
  ①使用rm命令删除普通文件:

//接上述代码
[wj@VM-4-3-centos code]$ ls -a /code当前目录下的文件和子目录
.  ..  d1  .hide.txt  text.tex
[wj@VM-4-3-centos code]$ rm text.tex //使用rm删除文件
[wj@VM-4-3-centos code]$ ls -a
.  ..  d1  .hide.txt
[wj@VM-4-3-centos code]$ rm .hide.txt//使用rm删除文件
[wj@VM-4-3-centos code]$ ls -a
.  ..  d1//可看到此时code中只剩下d1

  
  ②直接使用rm指令删除非空目录:
  当我们删除d1目录时,显示不让删除。这是因为rm后面不跟选项的情况下,默认删除的是普通文件。

[wj@VM-4-3-centos code]$ rm d1
rm: cannot remove ‘d1’: Is a directory

  若是想让rm删除目录,且是一个非空目录,则需要选项-rf递归删除 。
  -rf说明: 这是一种强制地删除命令。在windows中删除文件时,会跳出对话框询问是否删除,此处-rf表示不询问意见,直接删除文件。

[wj@VM-4-3-centos code]$ rm -rf d1//r递归,f强制
[wj@VM-4-3-centos code]$ ll
total 0
[wj@VM-4-3-centos code]$ ls -a
.  ..
[wj@VM-4-3-centos code]$ 

  
  

8.3、 *通配介绍

  1)、基础介绍
  * :星号是通配结构
  
  ls * .c:显示当前目录下所有的.c文件
  ls file* :显示当前目录下所有文件名带file的文件
  
   rm -rf *.c : 删除当前目录下所有.c文件
   rm -rf * :将当前目录下所有的文件删除
  
   rm -rf / :删除根目录下的所有文件
  关于该指令的注意事项: Linux没有回收站,删除了若再想找回过程会十分复杂,在没有基础的阶段此命令慎用!

  其它: rm -i:在rm后跟随-i,则会在每次删除前都询问一下十分删除,若输入y(yes)则是,输入n(no)则否。
  
  
  2)、演示说明

[wj@VM-4-3-centos code]$ ls
text1.txt  text.txt //当前路径下文件

[wj@VM-4-3-centos code]$ rm -i text.txt //rm后跟随-i选项
rm: remove regular empty file ‘text.txt’? n //选择n
[wj@VM-4-3-centos code]$ ls
text1.txt  text.txt  //当前路径下文件

[wj@VM-4-3-centos code]$ rm -i text.txt
rm: remove regular empty file ‘text.txt’? y //选择y
[wj@VM-4-3-centos code]$ ls
text1.txt  //当前路径下文件

  说明: 操作系统跳出对话框询问是一种免责声明,若什么也不提示会导致误删行为。
  
  
  

9、man

9.1、基本介绍

在这里插入图片描述

  
  

9.2、使用举例

  1)、简单演示
  例如:man pwd
在这里插入图片描述
  
  也可以man man:查询man本身
在这里插入图片描述
  
  
  2)、man中使用的比较多的手册种类

 1   Executable programs or shell commands //命令
 2   System calls (functions provided by the kernel)  //系统调用
 3   Library calls (functions within program libraries)  //库函数调用
 4   Special files (usually found in /dev)
 5   File formats and conventions eg /etc/passwd
 6   Games //游戏接口
 7   Miscellaneous (including macro packages and conventions), e.g. man(7), groff(7)
 8   System administration commands (usually only for root)
 9   Kernel routines [Non standard]

   例如,需要查ls命令时,输入下述指令,得

[wj@VM-4-3-centos code]$ man 1 ls

   其它使用方法举例:

[wj@VM-4-3-centos code]$ man 3 printf
No manual entry for printf in section 3
[wj@VM-4-3-centos code]$ man 2 fork
No manual entry for fork in section 2

在这里插入图片描述
  当输入man时显示手册不全,这是云服务器精简版的原因,解决该问题需要输入如下指令:

yum install -y man-pages

  
  
  

10、cp

10.1、基本介绍

在这里插入图片描述
  
  

10.2、Nano

说明: nano 是一个字符终端的文本编辑器,有点像DOS下的editor程序。它比vi/vim要简单得多,比较适合Linux初学者使用。

  
  相关使用演示:

[wj@VM-4-3-centos code]$ nano hello.c //用nano打开一个C文件
[wj@VM-4-3-centos code]$ ll
total 4
-rw-rw-r-- 1 wj wj 78 Aug  8 20:39 hello.c
[wj@VM-4-3-centos code]$ cat hello.c //在C文件中写下一段程序(编辑、退出保存此处不演示)
#include<stdio.h>

int main(void)
{
  printf("hello nano\n");
  return 0;
}


[wj@VM-4-3-centos code]$ 

  若没有Nano可使用下命指令解决:

yum install -y nano

  
  
  

10.3、cp使用举例

  1)、拷贝时关于跨路径拷贝的问题
  演示如下:将hello.c文件拷贝到/根目录下,发现拷贝失败。

[wj@VM-4-3-centos code]$ cp  ./hello.c  /  
cp: cannot create regular file ‘/hello.c’: Permission denied

  关于命令拷贝失败说明:
  回答:这是因为权限问题。当前用户为普通用户,根目录访问权在超级用户那。普通用户能拷贝的路径在/home以下
  
  
  
  2)、拷贝普通文件
  此处路径可以使用绝对路径,也可以使用相对路径。

[wj@VM-4-3-centos code]$ pwd
/home/wj/code

[wj@VM-4-3-centos code]$ mkdir text//在code下创建一个text目录
[wj@VM-4-3-centos code]$ ls
hello.c  text

[wj@VM-4-3-centos code]$ cp hello.c text//将hello.c拷贝到text目录下
[wj@VM-4-3-centos code]$ ls text //检查text目录下是否拷贝成功(ls+文件名学习)
hello.c

[wj@VM-4-3-centos code]$ rm /home/wj/code/text/hello.c//将拷贝到text文件下的hell.c文件删除。
[wj@VM-4-3-centos code]$ ls text
[wj@VM-4-3-centos code]$ ll text
total 0

[wj@VM-4-3-centos code]$ cp hello.c ../  //将hello.c文件拷贝到当前目录的上一层(../ 需要学习)
[wj@VM-4-3-centos code]$ ll
total 8
-rw-rw-r-- 1 wj wj   78 Aug  8 20:39 hello.c
drwxrwxr-x 2 wj wj 4096 Aug  8 20:52 text
[wj@VM-4-3-centos code]$ ls ../ //查看上一层文件,可看到hello.c拷贝成功
code  hello.c

  
  
  3)、拷贝目录:需要带-rf
  相关演示如下:

[wj@VM-4-3-centos code]$ ls//查看当前文件
hello.c  text

[wj@VM-4-3-centos code]$ cp text ../ //将text目录拷贝到上一层目录,发现拷贝失败
cp: omitting directory ‘text’

[wj@VM-4-3-centos code]$ cp -rf text ../  //同删除目录一样,需要借助-rf选项
[wj@VM-4-3-centos code]$ ls ../
code  hello.c  text
[wj@VM-4-3-centos code]$ 

  观察一下上级目录下的整个结构:

[wj@VM-4-3-centos code]$ tree ../
../
|-- code
|   |-- hello.c
|   `-- text
|-- hello.c
`-- text

3 directories, 2 files
[wj@VM-4-3-centos code]$ 

  
  
  

11、mv

11.1、基本介绍

在这里插入图片描述

  
  
  

11.2、功能一:剪切

  mv具有剪切功能:转储特定的一个文件或目录到其它路径下。
  
  1)、对普通文件移动:

[wj@VM-4-3-centos code]$ tree //当前目录下的树状图,假若我们需要把text目录下的hello.c文件移动到与text同目录下(当前目录下)
.
`-- text
    `-- hello.c

1 directory, 1 file
[wj@VM-4-3-centos code]$ mv text/hello.c . //可用执行此段代码:将text/hello.c的文件mv到 . (当前目录下)
[wj@VM-4-3-centos code]$ tree//调用tree指令可查看剪切成功。
.
|-- hello.c
`-- text

1 directory, 1 file
[wj@VM-4-3-centos code]$ 

  
  
  2)、对目录移动:

[wj@VM-4-3-centos code]$ tree//当前目录下的结构
.
|-- text
`-- world.cpp

1 directory, 1 file

[wj@VM-4-3-centos code]$ mv world.cpp text/ //先改变一下结构,方便观察后续移动目录
[wj@VM-4-3-centos code]$ tree
.
`-- text
    `-- world.cpp

1 directory, 1 file


[wj@VM-4-3-centos code]$ mkdir new //当前目录下新建一个子目录
[wj@VM-4-3-centos code]$ ll
total 8
drwxrwxr-x 2 wj wj 4096 Aug  8 21:23 new 
drwxrwxr-x 2 wj wj 4096 Aug  8 21:22 text


[wj@VM-4-3-centos code]$ mv text new //将text目录包括其中文件移动到new目录下
[wj@VM-4-3-centos code]$ tree
.
`-- new
    `-- text
        `-- world.cpp

2 directories, 1 file
[wj@VM-4-3-centos code]$ 


[wj@VM-4-3-centos code]$ mv new/text . //再将new目录下的text目录移动到当前目录下
[wj@VM-4-3-centos code]$ tree
.
|-- new
`-- text
    `-- world.cpp

2 directories, 1 file
[wj@VM-4-3-centos code]$ 


  
  
  
  

11.3、功能二:重命名

  mv可在同等路径下重命名文件:对一个文件或目录进行重命名.
  
  1)、对普通文件重命名:

[wj@VM-4-3-centos code]$ tree
.
|-- hello.c//修改前
`-- text

1 directory, 1 file
[wj@VM-4-3-centos code]$ mv hello.c world.cpp//例如:将当前hello.c文件重命名为world.cpp
[wj@VM-4-3-centos code]$ tree
.
|-- text
`-- world.cpp//修改后

1 directory, 1 file
[wj@VM-4-3-centos code]$ 

  
  
  2)、对目录重命名:

[wj@VM-4-3-centos code]$ tree//当前目录下的结构
.
|-- new
`-- text
    `-- world.cpp

2 directories, 1 file

[wj@VM-4-3-centos code]$ ll
total 8
drwxrwxr-x 2 wj wj 4096 Aug  8 21:27 new//改变目录名称前
drwxrwxr-x 2 wj wj 4096 Aug  8 21:22 text


[wj@VM-4-3-centos code]$ mv new newname //改变目录名称


[wj@VM-4-3-centos code]$ ll
total 8
drwxrwxr-x 2 wj wj 4096 Aug  8 21:27 newname //改变目录名称后
drwxrwxr-x 2 wj wj 4096 Aug  8 21:22 text
[wj@VM-4-3-centos code]$ 

  
  
  
  

12、 cat

12.1、基本介绍

在这里插入图片描述

  
  

12.2、使用举例1:cat、tac

  主要作用:打印文件内容

[wj@VM-4-3-centos code]$ tree//当前目录结构
.
|-- newname
|-- text
`-- world.cpp


2 directories, 1 file
[wj@VM-4-3-centos code]$ cat world.cpp //打印文件内容
#include<stdio.h>

int main(void)
{
  printf("hello nano\n");
  return 0;
}


[wj@VM-4-3-centos code]$ cat -n world.cpp //若想打印时有行号,可加入一个-n选项
     1	#include<stdio.h>
     2	
     3	int main(void)
     4	{
     5	  printf("hello nano\n");
     6	  return 0;
     7	}
     8	
     9	
[wj@VM-4-3-centos code]$ 


[wj@VM-4-3-centos code]$ tac world.cpp //tac,相对于cat而言,文本逆向打印


}
  return 0;
  printf("hello nano\n");
{
int main(void)

#include<stdio.h>
[wj@VM-4-3-centos code]$ 

  关于文本内容的逆置,有其适用的场景。
  
  

12.3、使用举例2:cat从文件读取和从键盘读取

  cat后跟文件名:从文件中读取数据打印到显示器上
  cat后什么也不跟:从键盘中读取数据打印到显示器上

  < : 本来应该从键盘中读取内容,变为从文件中读取内容
  >、>>:输出重定向和追加重定向,在后一文章中提到。

[wj@VM-4-3-centos ~]$ ls
code  file.txt  hello.c  text
[wj@VM-4-3-centos ~]$ cat file.txt
hello world
aaaaa
bbbb

[wj@VM-4-3-centos ~]$ cat <file.txt //<:表示输入重定向
hello linux
aaaaa
bbbb


[wj@VM-4-3-centos ~]$ cat 
aaaa
aaaa
bbbb
bbbb
cccc
cccc
dddd
dddd

  
  

12.4、使用举例3:cat

  cat 文件 对 文件的操作:

[wj@VM-4-3-centos ~]$ ls
code  file.txt  hello.c  text  //当前

[wj@VM-4-3-centos ~]$ cat file.txt >  bak.txt  //将file.txt文件内容复制到bak.txt文件中,相当于备份

[wj@VM-4-3-centos ~]$ ls
bak.txt  code  file.txt  hello.c  text  //可看到自动创建了一个bak.txt文件

[wj@VM-4-3-centos ~]$ cat bak.txt  //且文件内容也一并拷贝过来了
hello linux
aaaaa
bbbb
[wj@VM-4-3-centos ~]$ 


[wj@VM-4-3-centos ~]$  cat < file.txt >bak.txt  //效果与上类同
[wj@VM-4-3-centos ~]$ ls
bak.txt  code  file.txt  hello.c  text
[wj@VM-4-3-centos ~]$ 

  
  

  
  

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值