linux扩展磁盘空间命令_在Linux上监视磁盘空间– SQL Server DBA的有用命令

linux扩展磁盘空间命令

In this article, we will explore the different Linux commands related to the disk space.

在本文中,我们将探讨与磁盘空间相关的各种Linux命令。

  1. ‘ls’ command

    'ls'命令
  2. ‘df’ command

    'df'命令
  3. ‘du’ command

    'du'命令

It is very important for SQL Database administrators to know about basic commands in Linux for any day-to-day work or troubleshooting purpose.

对于SQL Database管理员来说,了解Linux的基本命令对于日常工作或故障排除非常重要。

Disk space monitoring is must-know skill DBAs. We can monitor disk space using SQL Server DMV’s but we must also know to monitor at OS level. In a Windows environment, we can directly open the file explorer and view the files inside it along with the used space but this is different in Linux.

磁盘空间监视是DBA必不可少的技能。 我们可以使用SQL Server DMV监视磁盘空间,但我们还必须知道在OS级别进行监视。 在Windows环境中,我们可以直接打开文件资源管理器并查看其中的文件以及使用的空间,但这在Linux中是不同的。

Linux中的'ls'命令 (‘ls’ command in Linux)

In Linux, we can use the ‘ls’ command to list the directories and the content of files. Most Linux users use this command frequently.

在Linux中,我们可以使用'ls'命令列出目录和文件内容。 大多数Linux用户经常使用此命令。

If we run the ‘ls’ command without any parameter, it lists out the files and directories. We do not get any other information such as size, file type, timestamp etc.

如果我们不带任何参数运行“ ls”命令,它将列出文件和目录。 我们没有其他任何信息,例如大小,文件类型,时间戳等。

In Linux SQL Server, by default, all the data and log files go into ‘/var/opt/mssql/data’. First, go to this path using the command

在Linux SQL Server中,默认情况下,所有数据和日志文件都位于“ / var / opt / mssql / data”中。 首先,使用以下命令转到此路径

# cd /var/opt/mssql/data

#cd / var / opt / mssql / data

#ls

#ls

In the output above, we can see all the files listed there.

在上面的输出中,我们可以看到其中列出的所有文件。

Let us run the command with -l parameter. ‘ls -l’ returns files, their size (in bytes), owner, permission and the timestamp.

让我们使用-l参数运行命令。 “ ls -l”返回文件,文件大小(以字节为单位),所有者,权限和时间戳。

By default, ls command returns the file size in bytes. It is not useful and easy to read the file size in bytes. Therefore, we can run the command ‘ls -lh’ to return the file size in human-readable format.

缺省情况下,ls命令以字节为单位返回文件大小。 以字节为单位读取文件大小既无用也不容易。 因此,我们可以运行命令“ ls -lh”以人类可读的格式返回文件大小。

Command: ls -lh

命令: ls -lh

In the output, you can notice that some of the files are in MB, KB or even in GB’s. The optimal unit for display is used by default.

在输出中,您会注意到某些文件的大小为MB,KB甚至GB。 默认情况下,使用显示的最佳单位。

We can sort out the results based on the modification time. The command ‘ls -lth’ returns the output with sorted data on the timestamp column in descending order.

我们可以根据修改时间来整理结果。 命令“ ls -lth”以降序返回时间戳列上具有排序数据的输出。

Command: ls -lth

命令: ls -lth

Linux中的'df'命令 (‘df’ command in Linux)

We can use ‘df’ command to list out the available and used space on the file system in Linux. We also call this command ‘disk filesystem’ command.

我们可以使用'df'命令列出Linux中文件系统上的可用空间和已用空间。 我们也将此命令称为“磁盘文件系统”命令。

If we do not specify any parameter with df command, it displays space on the current file system.

如果我们不使用df命令指定任何参数,它将显示当前文件系统上的空间。

Command: df

命令: df

Similar to ‘ls -h’ command, we can run the df command with ‘-h’ parameter to display results in human-readable format. By default, df command shows output file system size in KB’s. ‘df -h’ command automatically select the best unit to display for the particular file system. You can notice in the output file systems in MB, GB etc.

与“ ls -h”命令相似,我们可以使用带有“ -h”参数的df命令以人类可读的格式显示结果。 默认情况下,df命令以KB为单位显示输出文件系统大小。 'df -h'命令自动为特定文件系统选择最佳显示单位。 您会在输出文件系统中注意到MB,GB等。

If we specifically want size in KB’s, run the below command

如果我们特别想要KB大小,请运行以下命令

Command: df -k

命令: df -k

Similarly, we can run the command ‘df -m’ to show file system size in MB’s.

同样,我们可以运行命令'df -m'以MB为单位显示文件系统大小。

We might need additional information about the file system type in the output. We can get this information with ‘df -T’ command.

我们可能需要有关输出中文件系统类型的其他信息。 我们可以使用“ df -T”命令获取此信息。

We can get information about the disk space using any particular file as well. For example, if we specify the ‘tempdb.mdf’ along with the command, we get below output about the file system under which this file exists.

我们还可以使用任何特定文件来获取有关磁盘空间的信息。 例如,如果我们与命令一起指定“ tempdb.mdf”,则会在以下输出中获得有关此文件所在的文件系统的信息。

Command: df -h tempdb.mdf

命令: df -h tempdb.mdf

Linux中的'du'命令 (‘du’ command in Linux)

We can get disk usage of files and directories in the Linux system using the ‘du’ command. This command is a short form of disk usage.

我们可以使用“ du”命令获取Linux系统中文件和目录的磁盘使用情况。 此命令是磁盘使用情况的简短形式。

In the below example, we can see the disk usage for the directory.

在下面的示例中,我们可以看到目录的磁盘使用情况。

Similar to other commands, we can get the output in a human-readable format using the command ‘df -h’

与其他命令类似,我们可以使用命令'df -h'以人类可读的格式获取输出

We can get the total disk usage size for the underlying directory with the command ‘du -sh’. We can see in the out total 3.6GB.

我们可以使用命令“ du -sh”来获取基础目录的总磁盘使用量。 我们总共可以看到3.6GB。

We can get a breakdown of all the files and directories using the command ‘du -a’. In below output, we can see it lists out all the files under the /var/opt/mssql/data.

我们可以使用命令“ du -a”获得所有文件和目录的细分。 在下面的输出中,我们可以看到它列出了/ var / opt / mssql / data下的所有文件。

Again, we can convert the output in a human-readable format with the ‘-h’ parameter.

同样,我们可以使用'-h'参数将输出转换为人类可读的格式。

Command: du -ah

命令: du -ah

In the output, we see the files in various extensions. We can also exclude the files if we want for any particular extension. For example, in below screenshot, you can all files except *hkckp extension.

在输出中,我们看到各种扩展名的文件。 如果需要任何特定的扩展名,我们也可以排除文件。 例如,在下面的屏幕截图中,可以扩展名为* hkckp的所有文件。

Command: du -ah –exclude “*hkckp” –specify the extension we want to exclude from the result.

命令: du -ah –排除“ * hkckp” –指定我们要从结果中排除的扩展名。

You can get information about the particular file as well. For example, in below command, I have specified ‘tempdb.mdf’.

您还可以获取有关特定文件的信息。 例如,在下面的命令中,我指定了“ tempdb.mdf”。

Command: du -ha “tempdb.mdf”

命令: du -ha“ tempdb.mdf”

使用SQL查询检查磁盘空间的另一种方法 (An alternate way to check Disk space with a SQL query)

We can also check the disk space using the DMV ‘sys.dm_os_volume_stats’. We can join this DMV ‘sys.master_files’ to get details of the drive where DB files exist. We can only get information about the disk drive where we have the database files. We will not be able to monitor the other drives such as backup drive or disk mount points.

我们还可以使用DMV'sys.dm_os_volume_stats'检查磁盘空间。 我们可以加入这个DMV'sys.master_files'来获取存在DB文件的驱动器的详细信息。 我们只能获取有关拥有数据库文件的磁盘驱动器的信息。 我们将无法监视其他驱动器,例如备份驱动器或磁盘安装点。

Connect to the SQL instance running on Linux and run the below query.

连接到在Linux上运行SQL实例,然后运行以下查询。

As highlighted in the screenshot, we have a few columns with NULL values. In windows system, we have the disk drive and the logical disk name for each drive or partition. Therefore, if we run this query in Windows SQL, we get the output for these columns as well. In Linux, we do not have disk drive similar to the windows OS. Therefore, these columns are appearing as NULL values.

如屏幕快照中突出显示的那样,我们有几列为NULL值。 在Windows系统中,我们具有磁盘驱动器和每个驱动器或分区的逻辑磁盘名称。 因此,如果我们在Windows SQL中运行此查询,则也将获得这些列的输出。 在Linux中,我们没有类似于Windows操作系统的磁盘驱动器。 因此,这些列显示为NULL值。

结论 (Conclusion)

In this article, we explored the important and useful command for the database administrators to monitor the disk space utilization. These commands provide details information about the directories, files and file system disk space available and the used space. You can also use a query to get some information about the disk space in Linux environment too. Be familiar with these commands in your environment.

在本文中,我们探索了数据库管理员用来监视磁盘空间利用率的重要且有用的命令。 这些命令提供有关目录,文件和文件系统可用磁盘空间以及已用空间的详细信息。 您也可以使用查询来获取有关Linux环境中磁盘空间的一些信息。 在您的环境中熟悉这些命令。

翻译自: https://www.sqlshack.com/monitoring-disk-space-on-linux-helpful-commands-for-sql-server-dbas/

linux扩展磁盘空间命令

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值