栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 系统运维 > 运维 > Linux

Linux命令学习2

Linux 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Linux命令学习2

1.mkdir:创建目录

   touch:创建文件

vi [文件名] 文本编辑器

使用方法:输入vi命令,单击i键,输入内容;输入完毕,按ESC键、输入冒号(:)wq,即可退出文本编辑。

2.wc:默认统计并输出文件的行数、单词数和字节数

wc -c 输出文件字节数

wc -l 输出文件行数

wc -L 输出文件最长的行的长度

wc -w 输出文件单词数

[master@localhost ~]$ mkdir 0421
[master@localhost ~]$ cd 0421
[master@localhost 0421]$ touch file01
[master@localhost 0421]$ cat file01
[master@localhost 0421]$ vi file01
[master@localhost 0421]$ cat file01
aaabbb
cccddd
bbbccc
dddggg
hello word
hello word
hello word
[master@localhost 0421]$ wc file01
 7 10 61 file01
[master@localhost 0421]$ wc -c file01
61 file01
[master@localhost 0421]$ wc -l file01
7 file01
[master@localhost 0421]$ wc -L file01
10 file01
[master@localhost 0421]$ wc -w file01
10 file01

3.touch:创建新文件或修改文件时间

touch -a 修改文件访问时间

touch -m 修改文件修改时间

touch -c  修改文件时间

touch -t  使用指定的时间值

[master@localhost 0421]$ touch file02
[master@localhost 0421]$ ls -l file02
-rw-rw-r--. 1 master master 0 4月  21 22:47 file02
[master@localhost 0421]$ touch -a -t 202104202012 file02
[master@localhost 0421]$ ls -l file02
-rw-rw-r--. 1 master master 0 4月  21 22:47 file02
[master@localhost 0421]$ touch -m -t 202104212012 file02
[master@localhost 0421]$ ls -l file02
-rw-rw-r--. 1 master master 0 4月  21 2021 file02

4.rmdir:删除空目录

[master@localhost 0421]$ mkdir dir1
[master@localhost 0421]$ cd dir1
[master@localhost dir1]$ touch file01
[master@localhost dir1]$ cd ..
[master@localhost 0421]$ mkdir fir2
[master@localhost 0421]$ ls -l
总用量 4
drwxrwxr-x. 2 master master 20 4月  22 09:31 dir1
-rw-rw-r--. 1 master master 61 4月  21 22:31 file01
-rw-rw-r--. 1 master master  0 4月  21 2021 file02
drwxrwxr-x. 2 master master  6 4月  22 09:31 fir2
[master@localhost 0421]$ rmdir dir1
rmdir: 删除 "dir1" 失败: 目录非空
[master@localhost 0421]$ rmdir fir2
[master@localhost 0421]$ ls -l
总用量 4
drwxrwxr-x. 2 master master 20 4月  22 09:31 dir1
-rw-rw-r--. 1 master master 61 4月  21 22:31 file01
-rw-rw-r--. 1 master master  0 4月  21 2021 file02

5.cp:复制文件或目录

[master@localhost 0421]$ cp file01 file02 dir1
[master@localhost 0421]$ ls -l dir1
总用量 4
-rw-rw-r--. 1 master master 61 4月  22 09:38 file01
-rw-rw-r--. 1 master master  0 4月  22 09:38 file02
[master@localhost 0421]$ cp file01 file03
[master@localhost 0421]$ ls -l
总用量 8
drwxrwxr-x. 2 master master 34 4月  22 09:38 dir1
-rw-rw-r--. 1 master master 61 4月  21 22:31 file01
-rw-rw-r--. 1 master master  0 4月  21 2021 file02
-rw-rw-r--. 1 master master 61 4月  22 09:39 file03

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

mv -f    如果目标文件已存在,强制覆盖目标文件而且不给提示

mv -i     如果目标文件已存在,提示是否覆盖目标文件

[master@localhost 0421]$ mv file03 dir1
[master@localhost 0421]$ touch file03
[master@localhost 0421]$ mv -i file03 dir1/file03
mv:是否覆盖"dir1/file03"? y
[master@localhost 0421]$ mv file02 file2
[master@localhost 0421]$ ls -l
总用量 4
drwxrwxr-x. 2 master master 48 4月  22 09:46 dir1
-rw-rw-r--. 1 master master 61 4月  21 22:31 file01
-rw-rw-r--. 1 master master  0 4月  21 2021 file2

 

 7.rm:永久删除文件或目录

rm -f    删除文件和目录不给提示,即使文件和目录不存在

rm -i    与-f选项相反,删除文件和目录前有提示

[master@localhost 0421]$ ls
dir1  dir2  file01  file03  file2
[master@localhost 0421]$ rm -i file03
rm:是否删除普通空文件 "file03"?y
[master@localhost 0421]$ ls
dir1  dir2  file01  file2
[master@localhost 0421]$ touch file03
[master@localhost 0421]$ rm -f file03
[master@localhost 0421]$ ls
dir1  dir2  file01  file2

8.find:可以根据给定的路径和表达式查找的文件或目录。如不加任何参数,表示查找当前路径下所有文件和目录

find -name pattern  查找文件符合指定模式pattern的文件

find -iname pattern  -iname不区分大小写

通配符的使用

*表示可以匹配任意数量的任意字符,可以为0个、1个或者多个

?表示可在相应的位置上匹配任意单个字符,只能是1个

[]表示可以匹配指定范围内的任意单个字符,只能是1个

[master@localhost 0421]$ find -iname "file01"
./file01
./dir1/file01
[master@localhost 0421]$ find -iname "file1"
./File1
[master@localhost 0421]$ ls
dir1  dir2  dir3  file01  file03  file04  File1  file2
[master@localhost 0421]$ find -name "file??"
./file01
./dir1/file01
./dir1/file02
./dir1/file03
./file03
./file04
[master@localhost 0421]$ find -iname "file0[1-9]"
./file01
./dir1/file01
./dir1/file02
./dir1/file03
./file03
./file04

9.tar:对文件进行打包和压缩,将多个文件合并成一个文件夹,使用时可以不加"-"

tar -c 创建打包文件

tar -t 查看打包文件包括哪些文件或目录

[master@localhost 0421]$ ls
dir1  dir2  dir3  file01  file03  file04  File1  file2
[master@localhost 0421]$ tar -cvf 1.tar dir3 file2
dir3/
file2
[master@localhost 0421]$ ls
1.tar  dir1  dir2  dir3  file01  file03  file04  File1  file2
[master@localhost 0421]$ tar -tf 1.tar
dir3/
file2

10.gzip:对文件进行压缩,减少其占用的存储空间

[master@localhost 0421]$ ls
1.tar  dir1  dir2  dir3  file01  file03  file04  File1  file2
[master@localhost 0421]$ gzip 1.tar
[master@localhost 0421]$ ls
1.tar.gz  dir1  dir2  dir3  file01  file03  file04  File1  file2

11.grep:从文件中提取符合指定匹配表达式的行

grep -l  不区分大小写

grep -n  输出行号

grep -v  只显示不满足条件的行

[master@localhost 0421]$ cat -n file01
     1	aaabbb
     2	cccddd
     3	bbbccc
     4	dddggg
     5	hello word
     6	hello word
     7	hello word
[master@localhost 0421]$ grep -n bbb file01
1:aaabbb
3:bbbccc
[master@localhost 0421]$ grep -n -v bbb file01
2:cccddd
4:dddggg
5:hello word
6:hello word
7:hello word

12.chowm:修改文件所有者和属组

     chmod:改变文件或目录权限

     文件的权限分为三种读(r)、写(w)、执行(x),没有相应权限用-代替

修改文件权限-符号法

添加权限、移除权限和设置权限三种权限分别用"+"、"-"、"="表示

修改文件权限-数字法

文件的三种权限分别用数字表示,分别把每种用户的三种权限对应的数字相加

 

[master@localhost 0421]$ ls -l file2
-rw-rw-r--. 1 master master 0 4月  21 2021 file2
[master@localhost 0421]$ chown root file2
chown: 正在更改"file2" 的所有者: 不允许的操作
[master@localhost 0421]$ su root
密码:
[root@localhost 0421]# chown root file2
[root@localhost 0421]# ls -l file2
-rw-rw-r--. 1 root master 0 4月  21 2021 file2
[root@localhost 0421]# chmod 777 file2
[root@localhost 0421]# ls -l file2
-rwxrwxrwx. 1 root master 0 4月  21 2021 file2
[root@localhost 0421]# chmod 777 dir3
[root@localhost 0421]# ls -l dir3
总用量 0
[root@localhost 0421]# su master
[master@localhost 0421]$ ls -l
总用量 8
-rw-rw-r--. 1 master master 153 4月  22 16:14 1.tar.gz
drwxrwxr-x. 2 master master  48 4月  22 09:46 dir1
drwxrwxr-x. 2 master master   6 4月  22 09:54 dir2
drwxrwxrwx. 2 master master   6 4月  22 15:55 dir3
-rw-rw-r--. 1 master master  61 4月  21 22:31 file01
-rw-rw-r--. 1 master master   0 4月  22 15:56 file03
-rw-rw-r--. 1 master master   0 4月  22 15:56 file04
-rw-rw-r--. 1 master master   0 4月  22 16:01 File1
-rwxrwxrwx. 1 root   master   0 4月  21 2021 file2

 

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/826618.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号