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

命令行与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   
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Linux shell命令行及脚本编程是一种在Linux操作系统中使用命令行和脚本语言进行编程和自动化的技术。下面将详细介绍一些常见的实例来解释这个概念。 1. 文件操作:通过命令行可以完成文件的创建、复制、移动、删除等操作。比如,使用`mkdir`命令创建一个新的目录,使用`cp`命令复制文件,使用`mv`命令移动文件,使用`rm`命令删除文件等。 2. 系统管理:通过shell命令行,可以管理和监控Linux系统的各种信息。比如,使用`ps`命令查看当前运行的进程,使用`top`命令监控CPU和内存的使用情况,使用`df`命令查看磁盘空间等。 3. 网络管理:通过shell脚本编程可以实现一些网络管理的功能。比如,使用`ping`命令来测试主机的连通性,使用`ifconfig`命令配置网络接口,使用`curl`命令进行HTTP请求等。 4. 任务调度:通过shell脚本编程可以实现定时任务的自动化执行。比如,使用`crontab`命令可以定时执行一些任务,比如备份文件、清理临时文件等。 5. 数据处理:通过shell脚本编程可以对数据进行一些处理和分析。比如,使用`awk`命令可以进行文本处理和分析,使用`grep`命令进行文本搜索,使用`sed`命令进行文本替换等。 总结来说,通过shell命令行及脚本编程,可以实现各种功能的自动化和批量处理,提高工作效率。掌握这些技能对于Linux系统管理员和开发人员来说非常重要。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值