RHCSA第二天作业

本文介绍了Linux中file和stat命令的使用,以及如何通过timedatectl管理时间。file命令用于识别文件类型,例如显示UTF-8 Unicode文本或MIME类别。stat命令则用于显示文件的inode内容,如在查看testfile的inode时使用stat命令。同时,文章还详细列举了ls命令的各种选项,如列出目录内容、按时间或大小排序等,并提供了示例。此外,还展示了如何使用timedatectl查看和修改系统时区,如设置为America/New_York。

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

作业

1、(问答题)file和stat命令的使用 文件类型:代表字符,以及英文

file命令

Linux file命令用于辨识文件类型。
语法:

file [-bcLvz][-f <名称文件>][-m <魔法数字文件>…][文件或目录…]

参数:

-b  列出辨识结果时,不显示文件名称。
-c  详细显示指令执行过程,便于排错或分析程序执行的情形。
-f<名称文件>  指定名称文件,其内容有一个或多个文件名称时,让file依序辨识这些文件,格式为每列一个文件名称。
-L  直接显示符号连接所指向的文件的类别。
-m<魔法数字文件>  指定魔法数字文件。
-v  显示版本信息。
-z  尝试去解读压缩文件的内容。

实例:
显示文件类型:

[root@localhost ~]# file install.log
install.log: UTF-8 Unicode text
[root@localhost ~]# file -b install.log <== 不显示文件名称
UTF-8 Unicode text
[root@localhost ~]# file -i install.log <== 显示MIME类别。
install.log: text/plain; charset=utf-8
[root@localhost ~]# file -b -i install.log
text/plain; charset=utf-8

stat命令

Linux stat 命令用于显示 inode 内容。
语法:

stat [文件或目录]

实例:假设查看 testfile 文件的inode内容内容,可以用以下命令

stat testfile

2、思维导图填空

在这里插入图片描述

学习总结

一、使用timedatectl

查看时间状态

 timedatectl status

在这里插入图片描述

列出所有已知时区

timedatectl list-timezones

在这里插入图片描述

修改时区为列出时区的某一个

timedatectl set-timezone "America/New_York"

在这里插入图片描述

二、使用ls

语法:

ls [OPTION]… [FILE]…

功能
列出目录的内容,包括文件和子目录的名称。

参数

  -a, --all                  do not ignore entries starting with .
  -A, --almost-all           do not list implied . and ..
      --author               with -l, print the author of each file
  -b, --escape               print C-style escapes for nongraphic characters
      --block-size=SIZE      scale sizes by SIZE before printing them; e.g.,
                               '--block-size=M' prints sizes in units of
                               1,048,576 bytes; see SIZE format below
  -B, --ignore-backups       do not list implied entries ending with ~
  -c                         with -lt: sort by, and show, ctime (time of last
                               modification of file status information);
                               with -l: show ctime and sort by name;
                               otherwise: sort by ctime, newest first
  -C                         list entries by columns
      --color[=WHEN]         colorize the output; WHEN can be 'never', 'auto',
                               or 'always' (the default); more info below
  -d, --directory            list directories themselves, not their contents
  -D, --dired                generate output designed for Emacs' dired mode
  -f                         do not sort, enable -aU, disable -ls --color
  -F, --classify             append indicator (one of */=>@|) to entries
      --file-type            likewise, except do not append '*'
      --format=WORD          across -x, commas -m, horizontal -x, long -l,
                               single-column -1, verbose -l, vertical -C
      --full-time            like -l --time-style=full-iso
  -g                         like -l, but do not list owner
      --group-directories-first
                             group directories before files;
                               can be augmented with a --sort option, but any
                               use of --sort=none (-U) disables grouping
  -G, --no-group             in a long listing, don't print group names
  -h, --human-readable       with -l, print sizes in human readable format
                               (e.g., 1K 234M 2G)
      --si                   likewise, but use powers of 1000 not 1024
  -H, --dereference-command-line
                             follow symbolic links listed on the command line
      --dereference-command-line-symlink-to-dir
                             follow each command line symbolic link
                               that points to a directory
      --hide=PATTERN         do not list implied entries matching shell PATTERN
                               (overridden by -a or -A)
      --indicator-style=WORD  append indicator with style WORD to entry names:
                               none (default), slash (-p),
                               file-type (--file-type), classify (-F)
  -i, --inode                print the index number of each file
  -I, --ignore=PATTERN       do not list implied entries matching shell PATTERN
  -k, --kibibytes            default to 1024-byte blocks for disk usage
  -l                         use a long listing format
  -L, --dereference          when showing file information for a symbolic
                               link, show information for the file the link
                               references rather than for the link itself
  -m                         fill width with a comma separated list of entries
  -n, --numeric-uid-gid      like -l, but list numeric user and group IDs
  -N, --literal              print raw entry names (don't treat e.g. control
                               characters specially)
  -o                         like -l, but do not list group information
  -p, --indicator-style=slash
                             append / indicator to directories
  -q, --hide-control-chars   print ? instead of nongraphic characters
      --show-control-chars   show nongraphic characters as-is (the default,
                               unless program is 'ls' and output is a terminal)
  -Q, --quote-name           enclose entry names in double quotes
      --quoting-style=WORD   use quoting style WORD for entry names:
                               literal, locale, shell, shell-always, c, escape
  -r, --reverse              reverse order while sorting
  -R, --recursive            list subdirectories recursively
  -s, --size                 print the allocated size of each file, in blocks
  -S                         sort by file size
      --sort=WORD            sort by WORD instead of name: none (-U), size (-S),
                               time (-t), version (-v), extension (-X)
      --time=WORD            with -l, show time as WORD instead of default
                               modification time: atime or access or use (-u)
                               ctime or status (-c); also use specified time
                               as sort key if --sort=time
      --time-style=STYLE     with -l, show times using style STYLE:
                               full-iso, long-iso, iso, locale, or +FORMAT;
                               FORMAT is interpreted like in 'date'; if FORMAT
                               is FORMAT1<newline>FORMAT2, then FORMAT1 applies
                               to non-recent files and FORMAT2 to recent files;
                               if STYLE is prefixed with 'posix-', STYLE
                               takes effect only outside the POSIX locale
  -t                         sort by modification time, newest first
  -T, --tabsize=COLS         assume tab stops at each COLS instead of 8
  -u                         with -lt: sort by, and show, access time;
                               with -l: show access time and sort by name;
                               otherwise: sort by access time
  -U                         do not sort; list entries in directory order
  -v                         natural sort of (version) numbers within text
  -w, --width=COLS           assume screen width instead of current value
  -x                         list entries by lines instead of by columns
  -X                         sort alphabetically by entry extension
  -1                         list one file per line

SELinux options:

  --lcontext                 Display security context.   Enable -l. Lines
                             will probably be too wide for most displays.
  -Z, --context              Display security context so it fits on most
                             displays.  Displays only mode, user, group,
                             security context and file name.
  --scontext                 Display only security context and file name.
      --help     display this help and exit
      --version  output version information and exit

显示说明
每行列出的信息依次是: 文件类型与权限、链接数、文件属主、文件属组、文件大小用byte来表示 、建立或最近修改的时间、名字

实例
列出根目录(\)下所有目录:

ls /

运行结果:

bin                                                    etc         mnt   srv
boot                                                   home        opt   sys
cloud-alibaba-djk-demo-sentinel-8401-1.0-SNAPSHOT.jar  lib         proc  tmp
data                                                   lib64       root  usr
dev                                                    lost+found  run   var
djk                                                    media       sbin  www
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值