Shell/Bash在线运行

所属目录
点击了解高性能代码运行API
运行结果
教程手册
代码仓库
极速运行
交互输入
极速运行模式,更高效的运行,点击编辑器上方的运行按钮即刻体验吧。
以下是用户最新保存的代码
# 命令替换 有两种方法: - 方法一:`command` - 方法二:$(command) 总结: - ``和$()两者是等价的,但推荐初学者使用$(),易于掌握;缺点是极少数UNIX可能不支持,但``都是支持的 - $(())主要用来进行整数运算,包括加减乘除,引用变量前面可以加$,也可以不加$ 发布于:2023-03-17 21:48 awk的for循环和二维字典和printf实现二维数据表倒置 发布于:2023-03-15 23:34 # 变量替换 ## 字符串处理 ### 字符长度 1. ${#string} 2. `expr length "$string"` ### 获取字符串索引位置 1. expr index "$string" substr ### 获取子串长度 1. expr match "$string" substr ### 抽取子串 方法一: 1. ${string:position} 2. ${string:position:length} 3. ${string: -position} 或者 ${string:(position)} 方法二: 1. expr substr $string $position $length 注意:使用expr,索引计数是从1开始计算;使用${string:position},索引计数是从0开始计数 发布于:2023-03-17 21:33 for 循环用法 发布于:2023-03-15 03:47 测试测试测试测试测试测试测试 发布于:2023-03-14 10:48 #echo,xargs,sort,uniq,awk命令实现word.txt统计word次数 发布于:2023-03-14 10:47 工业互联网日报 发布于:2023-03-06 12:52 初次使用shell测试 发布于:2023-03-04 21:31 while 循环123 发布于:2023-03-01 22:48 检测两台服务器指定目录下的文件一致性 发布于:2023-02-27 21:22 增加新的判断条件并且兼容没有设置过判断参数的项目 发布于:2023-02-24 16:03 REDIS监控 发布于:2023-02-27 09:18 shell脚本1 发布于:2023-02-21 15:08 测试shell 发布于:2023-01-31 09:46 支持库安装 发布于:2022-12-29 12:15 测试软件服务是否安装并确认是否安装 发布于:2022-12-28 14:56 自定义函数 发布于:2022-12-27 10:49 read读取控制台输入 read (选项)(参数) 发布于:2022-12-27 09:14 while循环 while [ 条件判断式 ] do 程序 done 执行结果不对,为啥呢 发布于:2022-12-26 17:49 for循环 语法二 for 变量 in 值1 值2 值3... do 程序 done 发布于:2022-12-26 17:30 for循环 发布于:2022-12-26 17:16 shell脚本测试! 发布于:2022-12-20 17:25 for字符写三行值 发布于:2022-12-19 10:49 求最大值。 发布于:2022-12-19 10:48 Shell 基础知识 发布于:2022-12-06 00:41 【Shell】测试read功能,注意两次的输入要有回车 发布于:2022-12-01 20:15 【Shell】此段代码为shell if else测试代码 发布于:2022-12-01 20:16 the number of dirctary is 13 the number of file is 16 发布于:2022-11-30 00:27 bash-测试表清理 发布于:2022-11-28 18:09 设计一个任意输入一个数,判断这个数是不是质数 发布于:2022-11-26 18:02 shell判断解压 发布于:2022-11-24 16:49 九九乘法表 发布于:2022-11-07 17:39 字符类型判断 发布于:2022-11-07 21:45 12 编写shell脚本,执行后,打印一行提示“Please input a number.”逐次打印用户输入数值,直到用户输入“end”为止。 发布于:2022-10-24 21:42 程序建立三个以输入日期为名称的文件. 发布于:2022-07-12 15:19 用户输入姓氏和名字,系统输出姓名 发布于:2022-07-12 15:01 相隔某数倍数进行打印 发布于:2022-05-25 10:21 工作测试代码 发布于:2022-05-16 14:10 shell基础语法 发布于:2022-04-11 18:29 shell脚本 发布于:2022-01-20 15:56 sssasdfsad asdf asdfa 发布于:2021-10-08 17:10 在线Shell体验 发布于:2021-08-11 09:50 在线shell体验 发布于:2021-08-11 09:45 #输入一个数字,并显示出来。 发布于:2021-08-05 17:05 r_daily_new_clue_d.sh 发布于:2021-07-22 20:34 shell脚本测试 发布于:2021-07-20 20:02 查找局域网内可ssh登录的主机(22端口) 发布于:2021-07-14 18:03 dns setting for macOS 发布于:2021-06-22 14:54 不用date编写计算时间的脚本 发布于:2021-05-23 14:11 第一个shell程序 发布于:2021-05-09 16:12 [更多]
显示目录

fdisk 命令-进行分区



fdisk 命令

fdisk 命令进行分区。

格式

[root@localhost ~]# fdisk ~l
#列出系统分区
[root@localhost ~]# fdisk 设备文件名
#给硬盘分区

注意,千万不要在当前的硬盘上尝试使用 fdisk,这会完整删除整个系统,一定要再找一块硬盘,或者使用虚拟机。

[root@localhost ~]# fdisk -l
#查询本机可以识别的硬盘和分区
Disk /dev/sda:32.2 GB, 32212254720 bytes
#硬盘文件名和硬盘大小
255 heads, 63 sectors/track, 3916 cylinders
#共255个磁头、63个扇区和3916个柱面
Units = cylinders of 16065 *512 = 8225280 bytes
#每个柱面的大小
Sector size (logical/physical): 512 bytes/512 bytes
#每个扇区的大小
I/O size (minimum/optimal): 512 bytes/512 bytes
Disk identifier: 0x0009e098
Device Boot Start End Blocks ld System
/dev/sda1 * 1 26 204800 83 Linux
Partition 1 does not end on cylinder boundary.
#分区1没有占满硬盘
/dev/sda2 26 281 2048000 82 Linux swap / Solaris
Partition 2 does not end on cylinder boundary
#分区2没有占满硬盘
/dev/sda3 281 3917 29203456 83 Linux
#设备文件名启动分区 起始柱面 终止柱面容量 ID 系统
Disk /dev/sdb: 21.5 GB, 21474836480 bytes #第二个硬盘识别,这个硬盘的大小
255 heads, 63 sectors/track, 2610 cylinders
Units = cylinders of 16065 * 512 = 8225280 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes/512 bytes Disk identifier: 0x00000000

使用 "fdisk -l" 查看分区信息,能看到添加的两块硬盘(/dev/sda 和 /dev/sdb)的信息。解释一下这些信息,其上半部分态是硬盘的整体状态,/dev/sda 硬盘的总大小是 32.2 GB,共有 3916 个柱面,每个柱面由 255 个磁头读/写数据,每个磁头管理 63 个扇区。每个柱面的大小是 8225280 Bytes,每个扇区的大小是 512 Bytes。

信息的下半部分是分区的信息,共 7 列,含义如下:

Device: 分区的设备文件名。
Boot: 是否为启动引导分区,在这里 /dev/sda1 为启动引导分区。
Start: 起始柱面,代表分区从哪里开始。
End: 终止柱面,代表分区到哪里结束。
Blocks: 分区的大小,单位是 KB。
id: 分区内文件系统的 ID。在 fdisk 命令中,可以 使用 "i" 查看。
System: 分区内安装的系统是什么。

如果这个分区并没有占满整块硬盘,就会提示 "Partition 1 does not end on cyl inder boundary",表示第一个分区没有到硬盘的结束柱面。/dev/sda 已经分配完了分区,没有空闲空间。而第二块硬盘 /dev/sdb 已经可以被识别了,但是没有可分区。

以硬盘 /dev/sdb 为例来做练习,命令如下:

[root@localhost ~]# fdisk /dev/sdb
#给/dev/sdb分区
Device contains neither a valid DOS partition table, nor Sun, SGI or OSF disklabel
Building a new DOS disklabel with disk identifier 0xed7e8bc7.
Changes will remain in memory only, until you decide to write them.
After that, of course, the previous content won't be recoverable.
Warning: invalid flag 0x0000 of partition table 4 will be corrected by w(rite)
WARNING: DOS-compatible mode is deprecated.it's strongly recommended to switch off the mode (command 'c') and change display units to sectors (command 'u').
Command (m for help):m
#交互界面的等待输入指令的位置,输入 m 得到帮助
Command action
#可用指令
a toggle a bootable flag
b edit bsd disklabel
c toggle the dos compatibility flag
d delete a partition
I list known partition types m print this menu
n add a new partition
o create a new empty DOS partition table
p print the partition table
q quit without saving changes
s create a new empty Sun disklabel
t change a partition's system id
u change display/entry units
v verity the partition table
w write table to disk and exit
x extra functionality (experts only)

注意这里的分区命令是 "fdisk /dev/sdb",这是因为硬盘并没有分区,使用 fdisk 命令的目的就是建立分区。

fdisk 交互

在 fdisk 交互界面中输入 m 可以得到帮助,帮助里列出了 fdisk 可以识别的交互命令,如表 所示。

命令 说 明
a 设置可引导标记
b 编辑 bsd 磁盘标签
c 设置 DOS 操作系统兼容标记
d 删除一个分区
1 显示已知的文件系统类型。82 为 Linux swap 分区,83 为 Linux 分区
m 显示帮助菜单
n 新建分区
0 建立空白 DOS 分区表
P 显示分区列表
q 不保存退出
s 新建空白 SUN 磁盘标签
t 改变一个分区的系统 ID
u 改变显示记录单位
V 验证分区表
w 保存退出
X 附加功能(仅专家)
由JSRUN为你提供的Shell/Bash在线运行、在线编译工具
        JSRUN提供的Shell/Bash 在线运行,Shell/Bash 在线运行工具,基于linux操作系统环境提供线上编译和线上运行,具有运行快速,运行结果与常用开发、生产环境保持一致的特点。