linux学习(三)

linux学习(三)

1.man帮助指令

当我们对某个指令不熟悉时候,即可使用帮助指令

man[命令配置文件]

例如:

列出所有命令:

man ls(全是英文) 按回车翻页 退出按ESC ,然后:wq

2.help帮助指令

help 指令

例如:

help cd

 Change the shell working directory.
    
    Change the current directory to DIR.  The default DIR is the value of the
    HOME shell variable.
    
    The variable CDPATH defines the search path for the directory containing
    DIR.  Alternative directory names in CDPATH are separated by a colon (:).
    A null directory name is the same as the current directory.  If DIR begins
    with a slash (/), then CDPATH is not used.
    
    If the directory is not found, and the shell option `cdable_vars' is set,
    the word is assumed to be  a variable name.  If that variable has a value,
    its value is used for DIR.
    
    Options:
        -L	force symbolic links to be followed
        -P	use the physical directory structure without following symbolic
    	links
    
    The default is to follow symbolic links, as if `-L' were specified.
    
    Exit Status:
    Returns 0 if the directory is changed; non-zero otherwise.

3.文件目录类

  1. pwd

    one :显示当前工作目录的绝对路径

two: ls [选项] [目录或是文件]

经常搭配:-a 显示当前目录所有目录和文件,包括隐藏的

​ -l 以列表方式显示信息

4.路径问题

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-6tyhlN1H-1593526488441)(C:\Users\18035\OneDrive - 中国加油!武汉加油!\Desktop\markdown\img\相对绝对路径.png)]

也就是说,绝对路径使用的从/ 开始找想要的位置,相对路径从自己所在的位置开始到想要的位置

cd 或cd~ 回到家目录 cd …回到当前目录的上级目录( ~ 代表是home目录,也就是家目录, \代表根目录)

5.创建空目录

mkdir(可创建目录)

1.mkdir 【选项】 目录名

例如:

mkdir /home/xq (表示在home下创建xq目录)

2.创建多级目录

mkdir -p /home/animal/tiger(表示在home下创建annimal,在animal下创建tiger)

6.删除目录

rmdir /home/animal

rmdir: failed to remove `/home/animal’: Directory not empty(因为下面有tiger)

所以此指令只能删除空目录,即目录中不可以有东西

[root@localhost animal]# rmdir tiger

total 0 此时,tiger就可以被删除

7.强制删除目录

创建目录:

mkdir /home/animal/aaaaa

删除不为空的animal的目录

rm -rf /home/animal

8.touch创建空文件

touch创建空文件

touch 1.txt 2.txt(可以同时创建多个文件)

9.cp复制指令

拷贝文件到指定目录

mkdir test 当前目录创建test文件夹

touch test1.txt 当前目录创建test1.txt文件

cp test1.txt test/ 当前目录下,将test1.txt 移动到当前目录下的test目录下

-r 递归复制整个文件夹到另一个文件夹下

cp -f test01/ test02/ 代表将test01下的所有文件复制一份到test02

\cp -f test01/ test02/ 强制覆盖文件,不会提示

10.rm删除文件

一.移除文件

[root@localhost test01]# ls -l
total 0
-rw-r–r--. 1 root root 0 Jun 29 10:34 1.txt
-rw-r–r--. 1 root root 0 Jun 29 10:34 2.txt
[root@localhost test01]# rm 1.txt 删除某个文件
rm: remove regular empty file `1.txt’? y 是否要删除?如果真要删除就输入y
[root@localhost test01]# ls -l
total 0
-rw-r–r--. 1 root root 0 Jun 29 10:34 2.txt
[root@localhost test01]#

二.移出文件夹==(有提示)==

[root@localhost test02]# pwd
/home/test02
[root@localhost test02]# rm -r test01 test02文件夹下有个test01文件,且该文件下有一个2.txt文件 此时想要删除test02及其以下文件
rm: descend into directory test01'? y 是否进去test01 rm: remove regular empty filetest01/2.txt’? y 是否删除test01/2.txt
rm: remove directory test01'? y 是否删除test01
[root@localhost test02]# ls -l
total 0
[root@localhost test02]#

三.移出文件夹==(无提示)==

rm -f 文件 强制删除不提醒

注意

和强制删除不为空的目录区别 rm -rf 强制删除目录不管是否为空,

rm -f 删除文件,不会提示

[root@localhost test01]# ls -l
total 0
-rw-r–r--. 1 root root 0 Jun 29 10:32 1.txt
-rw-r–r--. 1 root root 0 Jun 29 10:32 2.txt
[root@localhost test01]# rm -f 2.txt
[root@localhost test01]# ls -l
total 0
-rw-r–r--. 1 root root 0 Jun 29 10:32 1.txt
[root@localhost test01]#

11.mv移动文件目录或重命名

一:重命名:

mv 名字1 名字2

将名字1改为名字2

[root@localhost test01]# mv 1.txt abc.txt
[root@localhost test01]# ls -l
total 0
-rw-r–r--. 1 root root 0 Jun 29 10:32 abc.txt
[root@localhost test01]#

二:移动(剪切)

[root@localhost test01]# mv abc.txt /home/lxz/

移动到lxz目录下了

12.cat查看文件内容

cat查看文件内容(以只读的方式查看)

cat经常与 | more结合使用,| more指令是分页显示内容

-n 显示行号

语法:

cat [可选] 位置 | more

例如:

cat -n /etc/profile |more 显示etc下的profile文件中的内容 ,more分页显示,按空格翻页显示,按enter,逐行向下显示,按pageup向上翻页,pagedownf向下翻页

13.less根据需求查看文件

less用来查看大的文件,比如日志文件,这样可以根据需求加载文件内容

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值