命令行与shell编程系列之磁盘和文件系统

本文档详细介绍了命令行的基础概念、文件权限管理、文件操作、磁盘与文件系统结构,以及shell解析器和进程管理。通过实例演示了如何使用sudo查看log目录占用磁盘、fdisk分区及mkfs创建文件系统,并挂载到系统中进行管理。

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

命令行与shell编程系列文章目录

第一章 什么是命令行
第二章 文件权限
第三章 文件的处理
第四章 磁盘和文件系统
第五章 理解shell解析器和shell进程



前言

文件系统是一种管理磁盘等存储设备的软件,位于最底层直接同硬件打交道。主要作用就是简化终端用户对于磁盘的数据的管理。简单的说文件系统将磁盘空间进行规划和编号处理,这样使得可以通过文件名就可以找到具体的数据。

查看log目录下文件占用磁盘的大小
zhang:trunk$ sudo du -S  /var/log/   | sort -nr
sudo: unable to resolve host zhangguoting
20356	/var/log/vmware-caf/pme
7332	/var/log/samba
4644	/var/log/
1164	/var/log/installer
268	/var/log/cups
120	/var/log/apache2
112	/var/log/lightdm
112	/var/log/apt
60	/var/log/TecAgentLog/Running
52	/var/log/unattended-upgrades
40	/var/log/TecAgentLog/KeyPoints
32	/var/log/mysql
12	/var/log/fsck
4	/var/log/vmware-caf
4	/var/log/upstart
4	/var/log/TecAgentLog
4	/var/log/speech-dispatcher
4	/var/log/samba/cores/smbd
4	/var/log/samba/cores/nmbd
4	/var/log/samba/cores
4	/var/log/hp/tmp
4	/var/log/hp
4	/var/log/dist-upgrade

用fdisk工具对磁盘分区
# fdisk  /dev/sda
Welcome to fdisk (util-linux 2.27.1).
Changes will remain in memory only, until you decide to write them.  
Be careful before using the write command.   
 
Command (m for help): p  
Disk /dev/sda: 7.5 GiB, 8054112256 bytes, 15730688 sectors   
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos  
Disk identifier: 0x00000000  
 
Device Boot Start  End  Sectors  Size Id Type
/dev/sda1  32 15730687 15730656  7.5G  b W95 FAT32   
 
Command (m for help): d  
Selected partition 1 
Partition 1 has been deleted.
 
Command (m for help): p  
Disk /dev/sda: 7.5 GiB, 8054112256 bytes, 15730688 sectors   
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos  
Disk identifier: 0x00000000  
 
Command (m for help): n  
Partition type   
   p   primary (0 primary, 0 extended, 4 free)   
   e   extended (container for logical partitions)   
Select (default p): p
Partition number (1-4, default 1):   
First sector (2048-15730687, default 2048):  
Last sector, +sectors or +size{K,M,G,T,P} (2048-15730687, default 15730687): 
 
Created a new partition 1 of type 'Linux' and of size 7.5 GiB.   
 
Command (m for help): w  
The partition table has been altered.
Calling ioctl() to re-read partition table.  

为新分区的磁盘制作文件系统
# mkfs.ext4 /dev/sda1
mke2fs 1.42.13 (17-May-2015) 
Creating filesystem with 1966080 4k blocks and 491520 inodes 
Filesystem UUID: aa5d4194-4415-4222-982b-e721d1b782e1
Superblock backups stored on blocks: 
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632
 
Allocating group tables: done
Writing inode tables: done   
Creating journal (32768 blocks): 
done 
Writing superblocks and filesystem accounting information: done 
挂载磁盘
mount /dev/sda1 /media/sda1/

# df -h
Filesystem  Size      Used Available Use% Mounted on           
/dev/root 484.2M    230.6M    228.6M  50% /      
devtmpfs   28.2M         0     28.2M   0% /dev   
tmpfs      28.3M         0     28.3M   0% /dev/shm             
tmpfs      28.3M    264.0K     28.0M   1% /tmp   
tmpfs      28.3M     20.0K     28.3M   0% /run   
/dev/mmcblk0p3            6.5G    143.2M      6.1G   2% /data  
/dev/sda1   7.5G    682.4M      6.8G   9% /media/sda1   
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值