linux简单命令整理及其 file命令和stat命令的使用

这篇博客整理了Linux中的基本命令,包括查看帮助列表、文件管理、file命令和stat命令的详解。file命令用于检测文件类型,stat则用于获取文件的属性如大小、修改时间等。同时介绍了date和timedatectl命令,用于查看和设置系统日期与时间。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1.思维导图

2简单命令

  1. 查看帮助列表
  2. 文件的管理

3.file命令的详解

4.stat命令的详解

5.

一。思维导图

 二.查看帮助列表

1,--help
如:ls --help 这个命令会出现有关ls命令的全部信息,也是相当权威的
2,自动补全
在敲出命令的前几个字母的同时,按下tab键,系统会自动帮我们补全命令
但是如果前几个字母与其他命令有重复,系统将会将可能得命令都给你列出来供你选择。
两个tab所有满足条件的都列出出来。
3,历史命令
当系统执行过一些命令后,可按上下键翻看以前的命令,history将执行过的命令列举出来
 

 文件的管理

1,查看文件信息:ls
ls是英文单词list的简写,其功能为列出目录的内容,是用户最常用的命令之一,它类似于DOS下的dir命令。
Ls 的常用命令:
(1)Ls -a: 显示指定目录下所有子目录与文件(包括隐藏文件)
(2) Ls –l: 以列表方式显示文件的详细信息。
(3) Ls –h: 配合字母 –l 以人性化的方式显示文件大小。
Linux文件或者目录名称最长可以有265个字符,“.”代表当前目录,“..”代表上一级目录,以“.”开头的文件为隐藏文件,需要用 -a 参数才能显示。
2,切换工作目录: cd
在使用Unix/Linux的时候,经常需要更换工作目录。cd命令可以帮助用户切换工作目录。
Linux所有的目录和文件名大小写敏感
cd后面可跟绝对路径,也可以跟相对路径。如果省略目录,则默认切换到当前用户的主目录。
 Cd :后跟切换的目录。
./ 当前目录   ../上级目录  
~ 家目录     - 返回上次所在的目录  
  Cd / 使用绝对路径  cd ./ 文件夹(相对路径)
  Pwd 查看当前路径
使用pwd命令可以显示当前的工作目录,该命令很简单,直接输入pwd即可,后面可不带参数
 

file命令的详解

1.file命令是用来检测并显示文件类型(determine file type)。

2.

-b  不显示文件名称,只显示文件类型。在shell脚本中时有用。

-i 显示MIME类别。

-L  直接显示符号连接所指向的文件的类别。

-f namefile 指定名称文件(namefile),该文件每一行为一个文件名,file命令将按每一行的文件名辨别该文件的类型

Linux的stat(status)命令详解

功能说明:获取文件的属性,例如大小,最后的修改时间等inode内容, stat以文字的格式来显示inode的内容。

语法:stat [文件或目录]

1.参数:
# stat --help

Usage: stat [OPTION] FILE...

Display file or file system status.

-L, --dereference follow links

-Z, --context print the security context information if available

-f, --file-system display file system status instead of file status

-c --format=FORMAT use the specified FORMAT instead of the default;

output a newline after each use of FORMAT

--printf=FORMAT like --format, but interpret backslash escapes,

and do not output a mandatory trailing newline.

If you want a newline, include \n in FORMAT.

-t, --terse print the information in terse form

--help display this help and exit

--version output version information and exit

The valid format sequences for files (without --file-system):

%a Access rights in octal

%A Access rights in human readable form

%b Number of blocks allocated (see %B)

%B The size in bytes of each block reported by %b

%d Device number in decimal

%D Device number in hex

%f Raw mode in hex

%F File type

%g Group ID of owner

%G Group name of owner

%h Number of hard links

%i Inode number

%n File name

%N Quoted file name with dereference if symbolic link

%o I/O block size

%s Total size, in bytes

%t Major device type in hex

%T Minor device type in hex

%u User ID of owner

%U User name of owner

%x Time of last access

%X Time of last access as seconds since Epoch

%y Time of last modification

%Y Time of last modification as seconds since Epoch

%z Time of last change

%Z Time of last change as seconds since Epoch

Valid format sequences for file systems:

%a Free blocks available to non-superuser

%b Total data blocks in file system

%c Total file nodes in file system

%d Free file nodes in file system

%f Free blocks in file system

%C Security context in SELinux

%i File System ID in hex

%l Maximum length of filenames

%n File name

%s Block size (for faster transfers)

%S Fundamental block size (for block counts)

%t Type in hex

%T Type in human readable form
 

date命令的讲解

2、命令功能:date 可以用来显示或设定系统的日期与时间。

3、命令参数

-d<字符串>:显示字符串所指的日期与时间。字符串前后必须加上双引号;
-s<字符串>:根据字符串来设置日期与时间。字符串前后必须加上双引号;
-u:显示GMT;
–help:在线帮助;
–version:显示版本信息。
4、日期格式字符串列表

%H 小时(以00-23来表示)。
%I 小时(以01-12来表示)。
%K 小时(以0-23来表示)。
%l 小时(以0-12来表示)。
%M 分钟(以00-59来表示)。
%P AM或PM。
%r 时间(含时分秒,小时以12小时AM/PM来表示)。
%s 总秒数。起算时间为1970-01-01 00:00:00 UTC。
%S 秒(以本地的惯用法来表示)。
%T 时间(含时分秒,小时以24小时制来表示)。
%X 时间(以本地的惯用法来表示)。
%Z 市区。
%a 星期的缩写。
%A 星期的完整名称。
%b 月份英文名的缩写。
%B 月份的完整英文名称。
%c 日期与时间。只输入date指令也会显示同样的结果。
%d 日期(以01-31来表示)。
%D 日期(含年月日)。
%j 该年中的第几天。
%m 月份(以01-12来表示)。
%U 该年中的周数。
%w 该周的天数,0代表周日,1代表周一,异词类推。
%x 日期(以本地的惯用法来表示)。
%y 年份(以00-99来表示)。
%Y 年份(以四位数来表示)。
%n 在显示时,插入新的一行。
%t 在显示时,插入tab。
MM 月份(必要)
DD 日期(必要)
hh 小时(必要)
mm 分钟(必要)

timedatectl命令的讲解

1.显示系统的当前时间和日期# timedatectl  status

结果中RTC time就是硬件时钟的时间。

2.Linux系统上的time总是通过系统的timezone设置的,查看当前时区:# timedatectl | grep Time

3.查看所有可用的时区:# timedatectl list-timezones

4.根据地理位置找到本地的时区:# timedatectl list-timezones |  egrep  -o “Asia/B.*”

# timedatectl list-timezones |  egrep  -o “Europe/L.*”

# timedatectl list-timezones |  egrep  -o “America/N.*”

5.在Linux中设置本地时区,使用set-timezone开关:# timedatectl set-timezone “Asia/shagnhai”

如何在Linux中设置时间和日期

6.可以使用timedatectl命令设置系统的日期和时间:

只设置时间的话可以使用set-time开关以及HH:MM:SS(小时,分,秒)的时间格式。# timedatectl set-time 15:58:30

7.只设置日期的话可以使用set-time开关以及YY:MM:DD(年,月,日)的日期格式。# timedatectl set-time 20151120

8.设置日期和时间:# timedatectl set-time '16:10:40 2015-11-20'

在Linux中查找和设置硬件时钟

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值