In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-03-31 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)05/31 Report--
This article mainly introduces "Linux disk management and Shell programming knowledge points". In daily operation, I believe many people have doubts about Linux disk management and Shell programming knowledge points. Xiaobian consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the questions of "Linux disk management and Shell programming knowledge points". Next, please follow the editor to study!
Disk management
The three common commands for Linux disk management are df, du, and fdisk.
List the disk usage of the file system
Lists the disk usage of the file system-"df".
File system capacity used available mount point udev 1.9G 0 1.9G 0 / dev tmpfs 393M 6.3M 386m 2% / run / dev/sda1 19G 13G 5.5G 69% / tmpfs 2.0G 300K 2.0G 1% / dev/shm tmpfs 5.0M 4.0K 5.0M 1% / run/lock tmpfs 2.0G 02.0G 0% / sys/fs/cgroup tmpfs 393M 4.0K 393M 1% / run/user/108 tmpfs 393M 60K 393M 1% / run/user/1000 / dev/sr0 1.6G 1.6G 0100% / media/maoli/Ubuntu 16.04.6 LTS amd64
Disk partition table operation
Disk partition table operation-"fdisk".
Maoli@ubuntu:~$ sudo fdisk-l [sudo] maoli password: Disk / dev/sda: 20 GiB, 21474836480 bytes 41943040 sectors Units: sectors of 1 * 512 = 512 bytes Sector size (logical/physical): 512 bytes / 512 bytes I 0xdc219461 O size (minimum/optimal): 512 bytes / 512 bytes Disklabel type: dos Disk identifier: 0xdc219461 device launch Start tail sector Size Id type / dev/sda1 * 2048 39942143 39940096 19G 83 Linux / dev/sda2 39944190 41940991 1996802 975M 5 extension / dev/sda5 39944192 41940991 1996800 975M 82 Linux Exchange / Solaris
Disk partitioning tool
Disk Partition tool-parted.
Format the file system
Format the file system-"mkfs".
Maoli@ubuntu:~$ mkfs-t ext4-v / dev/sdb
-t-specifies the type of file system.
-c-check for disk corruption when creating a file system.
-v-displays details.
File system check
File system check-"fsck".
Convert or copy a file
Convert or copy files-"dd".
Mount / uninstall
Mount / unmount-"mount" / "umount".
Create / activate / close swap partition
Create / activate / close swap partition-"mkswap" / "swapon" / "swapoff".
Refer to the rookie tutorial: "https://www.runoob.com/linux/linux-filesystem.html"
Shell
Shell is an application that connects the user and the operating system. It provides a human-computer interface (interface) through which users can access the services of the operating system kernel. Shell script is a scripting program written for Shell. We can manage the system through Shell script, and we can also do file operations through it.
There is a lot of knowledge about Shell script on the Internet, I do not intend to do a comprehensive and systematic explanation of Shell script, we can get a perceptual understanding of Shell script through the following code.
Create a new Shell script
Open a text editor (you can use the vi/vim command to create a file) and create a new file test.sh with the extension sh (sh stands for shell).
Maoli@ubuntu:~$ vim test.sh #! / bin/bash echo "Hello World!"
Enter an echo "Hello World!", which is very similar to php. Chmod + x script is required to run a sh with execute permission
Maoli@ubuntu:~$ chmod + x. / test.sh maoli@ubuntu:~$. / test.sh Hello World!
Variable
The variable name is not marked with a dollar sign ($, required for variables in the PHP language). For example, the variable name = Runsen is defined in shell, while in php, $name = Runsen uses a defined variable, as long as the variable name is preceded by a dollar sign, such as $name or ${name}. The curly braces outside the variable name are optional and can be added or not.
Variables support string type, floating point and other types. These three prefixes are common:
Unset: deleting variabl
Readonly: Mark read-only variabl
Export: specify global variabl
#! / bin/bash # defines ordinary variables without special characters or spaces. You can define global variables without quotation marks export NAME=Runsen # define read-only variables readonly AGE=20 # print variables echo $CITY echo $NAME echo $AGE # delete CITY variables unset CITY # will not output Dongguan echo $CITY
Predefined variable
Predefined variables are often used to get command line input, such as the following:
$0: script file name $1-9: 1st-9th command line parameter name $#: command line parameter $@: all command line arguments $*: all command line arguments $?: the exit status of the previous command, which can be used to get the function return value $$: the process ID executed
An example:
#! / bin/bash echo "\ $0 = $0" echo "\ $1 = $1" echo "\ $2 = $2" echo "\ $# = $#" echo "\ $@ = $@" echo "\ $* = $*" echo "\ $$= $" echo "\ $? = $?"
The result of executing. / hello.sh 1 2 3 4 5:
# Program name $0 =. / hello.sh # first parameter $1 = 1 # second parameter $2 = 2 # A total of 5 parameters $# = 5 # print out all parameters $@ = 12345 # print out all parameters $* = 12345 # process ID $$= 9450 # No other commands or functions have been executed before
If statement
"the process control of sh cannot be empty"
#! / bin/bash read VAR # the following two judgment methods can be used. Use [] to add spaces around # if test $VAR-eq 10 if [$VART-eq 10] then echo "true" else echo "false" fi.
The read method is written on one line for the input in python (for terminal command prompt):
If [$VART-eq 10]; then echo "true"; else echo "false"; fi
For cycle
There is no difference between for loop and Python. It's very simple.
# ordinary for loop for ((I = 1; I)
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.