Linux基本命令《一,文件系统命令》

本文深入讲解了Linux系统中常用的文件和目录操作命令,包括df、du、ls、cd、pwd、mkdir、rm、cp、mv、ln和touch等,详细介绍了每个命令的功能、使用方法及示例。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

df:显示磁盘使用情况

[root@node01 ~]# df -h
Filesystem      Size  Used Avail Use% Mounted on
/dev/sda3        97G  770M   91G   1% /
tmpfs           491M     0  491M   0% /dev/shm
/dev/sda1       194M   28M  157M  15% /boot

du:显示文件系统使用情况

[root@node01 ~]# du -h /etc/
4.0K	/etc/gcrypt
28K	/etc/iproute2
8.0K	/etc/dbus-1/system.d
12K	/etc/dbus-1
12K	/etc/default
4.0K	/etc/opt
4.0K	/etc/terminfo
96K	/etc/pam.d
4.0K	/etc/popt.d
60K	/etc/init
144K	/etc/makedev.d
8.0K	/etc/cron.daily
16K	/etc/skel
20K	/etc/yum.repos.d

ls:显示目录
-:普通文件(f)
d:目录文件
b:块设备文件(block)
c:字符设备文件(character)
l:符号链接文件(symbolic link file)
p:命令管道文件(pipe)
s:套接字文件(socket)
文件权限:9位,每3位一组,3组 权限(u,g,o)每一组:rwx(可读可写可执行)

ls -a:显示隐藏目录

[root@node01 /]# ls -a
.   .autofsck  boot  etc   lib    lost+found  mnt  proc  sbin     srv  tmp  var
..  bin        dev   home  lib64  media       opt  root  selinux  sys  usr

ls -l:长链表显示

[root@node01 /]# ls -l
total 90
dr-xr-xr-x.  2 root root  4096 Jan  9 23:34 bin
dr-xr-xr-x.  5 root root  1024 Jan  9 23:34 boot
drwxr-xr-x. 18 root root  3700 Jan 10 04:34 dev
drwxr-xr-x. 61 root root  4096 Jan 10 04:34 etc
drwxr-xr-x.  2 root root  4096 Sep 23  2011 home
dr-xr-xr-x.  8 root root  4096 Jan  9 23:34 lib
dr-xr-xr-x.  9 root root 12288 Jan  9 23:34 lib64
drwx------.  2 root root 16384 Jan  9 23:33 lost+found
drwxr-xr-x.  2 root root  4096 Sep 23  2011 media
drwxr-xr-x.  2 root root  4096 Sep 23  2011 mnt
drwxr-xr-x.  2 root root  4096 Sep 23  2011 opt
dr-xr-xr-x. 86 root root     0 Jan 10 04:34 proc
dr-xr-x---.  2 root root  4096 Jan  9 23:45 root
dr-xr-xr-x.  2 root root 12288 Jan  9 23:34 sbin
drwxr-xr-x.  7 root root     0 Jan 10 04:34 selinux
drwxr-xr-x.  2 root root  4096 Sep 23  2011 srv
drwxr-xr-x. 13 root root     0 Jan 10 04:34 sys
drwxrwxrwt.  3 root root  4096 Jan 10 05:27 tmp
drwxr-xr-x. 13 root root  4096 Jan  9 23:33 usr
drwxr-xr-x. 17 root root  4096 Jan  9 23:33 var

cd:切换工作目录
pwd:显示当前工作目录

[root@node01 etc]# pwd
/etc

mkdir:创建目录

[root@node01 ~]# mkdir x y
[root@node01 ~]# ls
anaconda-ks.cfg  install.log  install.log.syslog  x  y
[root@node01 ~]# 

mkdir -p a/b/c 创建a里有b,b有c

[root@node01 ~]# mkdir -p a/b/c
[root@node01 ~]# tree a
a
└── b
    └── c

2 directories, 0 files

mkdir x/{aa,bb,cc}dir

[root@node01 ~]# mkdir x/{aa,bb,cc}dir
[root@node01 x]# ls
aadir  bbdir  ccdir

rm:删除
rm -rf 文件

[root@node01 ~]# ls
a  anaconda-ks.cfg  install.log  install.log.syslog  x  y
[root@node01 ~]# rm -rf a
[root@node01 ~]# ls
anaconda-ks.cfg  install.log  install.log.syslog  x  y

cp:拷贝

cp直接拷贝文件

[root@node01 ~]# ls
123  anaconda-ks.cfg  install.log  install.log.syslog  x  y
[root@node01 ~]# cp anaconda-ks.cfg  123
[root@node01 ~]# cd 123
[root@node01 123]# ls
anaconda-ks.cfg

cp -r x y(拷贝目录)

[root@node01 ~]# ls
123  anaconda-ks.cfg  install.log  install.log.syslog  x  y
[root@node01 ~]# cp x y
cp: omitting directory `x'
[root@node01 ~]# cp -r x y
[root@node01 ~]# ls
123  anaconda-ks.cfg  install.log  install.log.syslog  x  y
[root@node01 ~]# cd y
[root@node01 y]# ls
x

mv:移动文件 重命名文件

[root@node01 ~]# ls
123  anaconda-ks.cfg  install.log  install.log.syslog  x  y
[root@node01 ~]# mv 123 123.bak
[root@node01 ~]# ls
123.bak  anaconda-ks.cfg  install.log  install.log.syslog  x  y

ln:硬链接

[root@node01 ~]# ll
total 32
-rw-r--r--. 1 root root    0 Jan 10 06:11 123.bak
-rw-------. 1 root root  900 Jan  9 23:34 anaconda-ks.cfg
-rw-r--r--. 1 root root 8815 Jan  9 23:34 install.log
-rw-r--r--. 1 root root 3384 Jan  9 23:34 install.log.syslog
-rw-r--r--. 1 root root 1796 Jan 10 06:13 profile
drwxr-xr-x. 5 root root 4096 Jan 10 06:01 x
drwxr-xr-x. 3 root root 4096 Jan 10 06:08 y
[root@node01 ~]# ln profile abc
[root@node01 ~]# ll
total 36
-rw-r--r--. 1 root root    0 Jan 10 06:11 123.bak
-rw-r--r--. 2 root root 1796 Jan 10 06:13 abc
-rw-------. 1 root root  900 Jan  9 23:34 anaconda-ks.cfg
-rw-r--r--. 1 root root 8815 Jan  9 23:34 install.log
-rw-r--r--. 1 root root 3384 Jan  9 23:34 install.log.syslog
-rw-r--r--. 2 root root 1796 Jan 10 06:13 profile
drwxr-xr-x. 5 root root 4096 Jan 10 06:01 x
drwxr-xr-x. 3 root root 4096 Jan 10 06:08 y

touch:创建一个文件

[root@node01 ~]# touch wangle
[root@node01 ~]# ls
123.bak  abc  anaconda-ks.cfg  install.log  install.log.syslog  profile  wangle  x  y
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值