Linux中常用命令

1 、切换目录

cd

到/tmp 目录:cd /tmp

到上层目录:cd ..

2 、查看当前目录

pwd

3、 创建一个新的文件夹:

mkdir

创建一层目录:

创建多层目录:

4 、删除目录:

rmdir [-p]   如果需要层级删除目录,就需要带上p(只能删除空目录)

5、查询环境变量

echo $PATH  或者$PATH

 

6、切换用户:

su 用户名

7、移动文件

 

 

仔细阅读上面的命令,你会发现mv还可以对文件进行从命名,上面的命令将hellot.txt从a中移动到了b中,并改名为hello1.txt

 

8、查看文件与目录

ls

ls -a  目录名称:列出目录中所有的文件

ls -al 目录名:列出长字符串,包含文件的一些详细信息

如果没有给定目录名,那么就是当前目录

 

9、文件的复制:

cp [-adfilprsu] 源文件  目标文件    //将源文件拷贝到目标文件

cp  src1,src2,... des   //将多个源文件拷贝到目的文件夹

 

cp这个命令非常重要,不同的身份执行对命令产生不同的效果,尤其是-a,-p参数,对不同的身份来说,区别非常大。

例1:

使用root执行:

如果我们要将文件的所有的属性复制过来,则要加上参数-a

 

复制一个目录到另外一个目录 cp -r /src /desc

 

 

10 、移除文件或目录

rm [-fir] 文件或目录

-f 强制的意思,忽略不存在的文件,不会出现警告信息

-i互动模式:删除前,会询问是否删除

-r :递归删除

 

这里不再演示,记得之前的rmdir吗,只能删除空目录,所以删除非空目录只能使用rm -r

11、文件类容查询

cat

-b:列出行号

-n:列出行号,包括空白行

 

cat 是一次性将数据显示到屏幕上,如果想一页一页的看怎么办?

使用more命令

more在运行的过程中,你有几个按键可以按:

空格键:代表向下翻一页

Enter:代表向下滚动一行

q:离开more

b:往回翻页

 

 

12 、创建文件

touch

touch a.txt 就会在当前目录下创建a.txt

 

13、查找文件的命令

whereis ,find

whereis [-bmsu]  文件或目录名

-b:二进制文件

-m:只找在说明文件manual路径下的问津

-s:只找source源文件

-u:查找不在上述三个选项中的其他特殊文件

 

whereis ifconfig

 

下面看看find命令

 

find [path] [option] [actioin]

查找/home下面属于gavin的文件

find   /home  -user  gavin

查找系统中不属于任何人的文件

find /  -nouser

查找文件名为passwd的这个文件

find    /     -name passwd

查找文件类型为socket的文件

find   /    -type s

 

14、磁盘和目录的容量

df:列出文件系统的整体磁盘使用量

du:评估文件系统的磁盘使用量

15 创建链接文件

ln  [-sf] 源文件   目标文件

 

-s  :创建软连接,如果不加则是硬连接

-f:如果目标文件存在,则删除后再建

 

[root@localhost test2]# echo 'good'>a.txt
[root@localhost test2]# ls
a.txt
[root@localhost test2]# ln -s a.txt b
[root@localhost test2]# ls
a.txt  b
[root@localhost test2]# ll
total 12
-rw-r--r-- 1 root root 5 Aug  8 01:09 a.txt
lrwxrwxrwx 1 root root 5 Aug  8 01:09 b -> a.txt
[root@localhost test2]# echo 'hello'>>b
[root@localhost test2]# cat b
good
hello
[root@localhost test2]# cat a.txt
good
hello
[root@localhost test2]# ln a.txt c
[root@localhost test2]# ll
total 20
-rw-r--r-- 2 root root 11 Aug  8 01:09 a.txt
lrwxrwxrwx 1 root root  5 Aug  8 01:09 b -> a.txt
-rw-r--r-- 2 root root 11 Aug  8 01:09 c
[root@localhost test2]# echo 'bad'>>c
[root@localhost test2]# cat c
good
hello
bad
[root@localhost test2]# cat a.txt
good
hello
bad
[root@localhost test2]# cat b
good
hello
bad
[root@localhost test2]# rm a.txt
rm: remove regular file `a.txt'? y
[root@localhost test2]# cat b
cat: b: No such file or directory
[root@localhost test2]# cat c
good
hello
bad
[root@localhost test2]#

 

运行上面的命令行,相信你对ln的使用会非常清楚的。

 

15、挂载CD

16、文件压缩

tar

-c:创建一个压缩文件

-v:显示压缩过程

-f:给出压缩文件名

-x:解压文件

-t::查看压缩包中又哪些文件


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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值