Linux 简要命令记录

1、设置时区:

#设为上海:
timedatectl set-timezone Asia/Shanghai
#搜索特定时区
timedatectl list-timezone

2、修改时间:

#设定系统时间
date -s "2023-11-16 22:30:00"
#同步写入BIOS
hwclock -w

3、fdisk分区

root@heihei:~# fdisk /dev/nvme0n1
Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

The size of this disk is 3.5 TiB (3840755982336 bytes). DOS partition table format cannot be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT).

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-4294967295, default 2048):
Last sector, +sectors or +size{K,M,G,T,P} (2048-4294967294, default 4294967294):

Created a new partition 1 of type 'Linux' and of size 2 TiB.

Command (m for help): w
The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
root@heihei:~# lsblk |grep nvme0n1
nvme0n1     259:0    0   3.5T  0 disk
`-nvme0n1p1 259:2    0     2T  0 part
#可以看到已经创建成功

4、自动交互

简要作用,shell下老是会有交互界面,比如让你按y确定进行下一步,比如mkfs 的时候需要按y确认等等需要交互的时候,我们可以在给命令的时候就先给出,当其弹出交互时,自动输入
如上面第三条:fdisk分区,需要在输入fdisk /dev/nvme0n1以后再输入

n[回车]
p[回车]
[回车]
[回车]
[回车]
w[回车]

已知回车在 linux下用 \n可以代替

# -e 代表激活转义符
root@heihei:~# echo -e "1\n2"
1
2

得出解:echo -e "n\np\n\n\n\nw\n"
再透过管道命令 | 传递给fdisk命令,效果如下:

root@heihei:~# echo -e "n\np\n\n\n\nw\n"|fdisk /dev/nvme0n1

Welcome to fdisk (util-linux 2.31.1).
Changes will remain in memory only, until you decide to write them.
Be careful before using the write command.

The size of this disk is 3.5 TiB (3840755982336 bytes). DOS partition table format cannot be used on drives for volumes larger than 2199023255040 bytes for 512-byte sectors. Use GUID partition table format (GPT).

Command (m for help): Partition type
   p   primary (0 primary, 0 extended, 4 free)
   e   extended (container for logical partitions)
Select (default p): Partition number (1-4, default 1): First sector (2048-4294967295, default 2048): Last sector, +sectors or +size{K,M,G,T,P} (2048-4294967294, default 4294967294):
Created a new partition 1 of type 'Linux' and of size 2 TiB.

Command (m for help): The partition table has been altered.
Calling ioctl() to re-read partition table.
Syncing disks.
root@heihei:~# lsblk |grep nvme0n1
nvme0n1     259:0    0   3.5T  0 disk
`-nvme0n1p1 259:2    0     2T  0 part
#创建成功

你可能感兴趣的:(Linux系统,Shell,linux)