cal: calendar,cal命令可以用来显示公历(阳历)日历。公历是现在国际通用的历法,又称格列历,通称阳历。“阳历”又名“太阳历”,系以地球绕行太阳一周为一年,为西方各国所通用,故又名“西历”

1.命令格式:
cal [参数][月份][年份]

2.命令功能:
用于查看日历等时间信息,如只有一个参数,则表示年份(1-9999),如有两个参数,则表示月份和年份

3.命令参数:
-1 显示一个月的月历
-3 显示系统前一个月,当前月,下一个月的月历
-s  显示星期天为一个星期的第一天,默认的格式
-m 显示星期一为一个星期的第一天
-j  显示在当年中的第几天(一年日期按天算,从1月1号算起,默认显示当前月在一年中的天数)
-y  显示当前年份的日历

4.使用实例:
实例1:显示当前月份日历
命令:cal
输出:

复制代码

代码如下:


[root@localhost ~]# cal
十二月 2012
日 一 二 三 四 五 六
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31
[root@localhost ~]#

实例2:显示指定月份的日历
命令:cal 9 2012
输出:

复制代码

代码如下:


[root@localhost ~]# cal 9 2012
九月 2012
日 一 二 三 四 五 六
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30

实例3:显示2013年日历
命令:

复制代码

代码如下:


cal -y 2013
cal 2013


输出:
Linux命令篇之cal命令和file命令_file实例4:显示自1月1日的天数
命令:cal -j
输出:

复制代码

代码如下:


[root@localhost ~]# cal -j
十二月 2012
日 一 二 三 四 五 六
336
337 338 339 340 341 342 343
344 345 346 347 348 349 350
351 352 353 354 355 356 357
358 359 360 361 362 363 364
365 366
[root@localhost ~]#

实例5:星期一显示在第一列
命令:cal -m
输出:

复制代码

代码如下:


[root@localhost ~]# cal -m
十二月 2012
一 二 三 四 五 六 日
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31[root@localhost ~]#

file命令简介:


该命令用来识别文件类型,也可用来辨别一些文件的编码格式。它是通过查看文件的头部信息来获取文件类型,而不是像Windows通过扩展名来确定文件类型的。

执行权限 :All User

指令所在路径:/usr/bin/file


命令语法:



file [ -bchikLnNprsvz ] [ -f namefile ] [ -F separator ] [ -m magicfiles ] file ...

命令参数:


下表列出了部分常用的参数。

参数

长参数

描叙

-b


列出文件辨识结果时,不显示文件名称。

-c


详细显示指令执行过程,便于排错或分析程序执行的情形

-f


列出文件中文件名的文件类型

-F


使用指定分隔符号替换输出文件名后的默认的“:”分隔符。

-i


输出mime类型的字符串

-L


查看对应软链接对应文件的文件类型

-z


尝试去解读压缩文件的内容


--help

显示命令在线帮助


--version

显示命令版本信息

使用示例:


1:查看file命令的帮助信息

[root@DB-Server ~]# file --help
Usage: file [OPTION]... [FILE]...
Determine file type of FILEs.
 
  -m, --magic-file LIST      use LIST as a colon-separated list of magic
                               number files
  -z, --uncompress           try to look inside compressed files
  -b, --brief                do not prepend filenames to output lines
  -c, --checking-printout    print the parsed form of the magic file, use in
                               conjunction with -m to debug a new magic file
                               before installing it
  -f, --files-from FILE      read the filenames to be examined from FILE
  -F, --separator string     use string as separator instead of `:'
  -i, --mime                 output mime type strings
  -k, --keep-going           don't stop at the first match
  -L, --dereference          causes symlinks to be followed
  -n, --no-buffer            do not buffer output
  -N, --no-pad               do not pad output
  -p, --preserve-date        preserve access times on files
  -r, --raw                  don't translate unprintable chars to \ooo
  -s, --special-files        treat special (block/char devices) files as
                             ordinary ones
      --help                 display this help and exit
      --version              output version information and exit

当然你也可以使用 man file 获取更加详细的帮助文档信息。

2:查看文件类型

例如,如下所示,Temp.txt 文件类型为text,编码为UTF-8 Unicode

[root@DB-Server ~]# file Temp.txt 
 
Temp.txt: UTF-8 Unicode text, with very long lines, with CRLF line terminators
 

3:不输出文件名称,只显示文件格式以及编码

通过下面两个命令对时,就可以清晰的了解参数-b的作用。

[root@DB-Server ~]# file Temp.txt 
Temp.txt: UTF-8 Unicode text, with very long lines, with CRLF line terminators
[root@DB-Server ~]# file -b Temp.txt
UTF-8 Unicode text, with very long lines, with CRLF line terminators

Linux命令篇之cal命令和file命令_cal_02

 

4: 输出mime类型的字符串

[root@DB-Server ~]# file -i Temp.txt 
Temp.txt: text/plain; charset=utf-8

 

5: 查看文件中的文件名的文件类型

这个参数非常适合shell脚本去查找、判别某种文件类型的数据。

[root@DB-Server ~]# cat >test
/root/install.log 
it is only one test file
 
[2]+  Stopped                 cat > test
[root@DB-Server ~]# file -f  test
/root/install.log:        ASCII text
it is only one test file: ERROR: cannot open `it is only one test file' (No such file or directory)
[root@DB-Server ~]# 
[root@DB-Server ~]# 

Linux命令篇之cal命令和file命令_cal_03

 

5: 使用指定分隔符号替换输出文件名后的默认的“:”分隔符。

感觉这个参数很鸡肋!我搞明白这个参数的作用时,很是纳闷。

Linux命令篇之cal命令和file命令_file_04

 

6:尝试去解读压缩文件的内容

[root@DB-Server ~]# file -z Temp.txt.gz 
Temp.txt.gz: UTF-8 Unicode text, with very long lines, with CRLF line terminators (gzip compressed data, was "Temp.txt", from Unix, last modified: Tue Jun 24 00:34:15 2014)
[root@DB-Server ~]# 

 

7: 查看软链接对应文件的文件类型

如下所示,创建一个软链接sfile,然后分别用file 和带参数的file -L查看


 
[root@DB-Server ~]# ln -s Temp.txt.gz sfile
[root@DB-Server ~]# file sfile 
sfile: symbolic link to `Temp.txt.gz'
[root@DB-Server ~]# file -L sfile 
sfile: gzip compressed data, was "Temp.txt", from Unix, last modified: Tue Jun 24 00:34:15 2014
[root@DB-Server ~]# 



想了解更多技术,请关注淘宝店铺“鹏哥技术店”

鹏哥技术店祝您早日成为技术大牛

【店铺链接】http://tb.onlychitu.com/shopPage.html?id=23660

Linux命令篇之cal命令和file命令_file_05