文件管理命令
ls -l
第一列是文件類型
-:普通文件
c:字符文件
l:鏈接
p:管道文件
b:塊設備
ls -m
逗號隔開
[root@localhost ~]# ls -m /var/
adm, cache, crash, db, empty, games, gopher, kerberos, lib, local, lock, log, mail, nis, opt, preserve, run, spool,
tmp, var, yp
ls --time=atime
訪問時間
--time=ctime
修改時間
--full-time
詳細訪問時間
[root@localhost ~]# ls --full-time
total 16
-rw-------. 1 root root 1163 2017-10-23 22:53:42.398974266 +0800 anaconda-ks.cfg
-rw-r--r--. 1 root root 33 2017-09-09 12:34:08.001916663 +0800 a.txt
-rw-r--r--. 1 root root 32 2017-09-09 12:34:27.883915853 +0800 b.txt
drwxr-xr-x. 2 root root 4096 2017-10-23 23:05:44.724975372 +0800 initial_repo_backup
[root@localhost ~]#
-R
同時列出所有子目錄層
-h
將列出文件的大小以人性化格式輸出
--sort time
按時間排序
--sort size
按大小排序
rmdir
刪除空目錄
rmdir -p
刪除多級空目錄
增刪除用戶
useradd 用戶名
passwd 用戶名
給用戶加密碼
userdel 用戶名
刪除用戶
-r 刪除家目錄
date
-R, --rfc-2822
output date and time in RFC 2822 format. Example: Mon, 07 Aug 2006 12:34:56 -0600
-u
UTC(Universal Time Coordinated)
與GMT含義一樣
CST是我們自己的標準時間
date [+format]
[root@localhost ~]# date +%c
Mon 23 Oct 2017 05:37:33 PM EDT
[root@localhost ~]#
%s 以1970年1月1日0時0分開始計算到目前所經過的時間
%j 顯示一年中的第幾天 %M 分鐘(00-59)
[root@localhost ~]# date +%D
10/24/17
[root@localhost ~]# date +%A
Tuesday
[root@localhost ~]# date +%H
14
[root@localhost ~]# date +%H%D
1410/24/17
[root@localhost ~]#
例:1. 查看1945年8月15日是星期幾(當前時間爲2017-10-24)
[root@localhost ~]# date -d "-72 year -2 month -9 days"
Wed Aug 15 15:01:16 CST 1945
[root@localhost ~]#
2. 查看2045年8月15日是星期幾(當前時間爲2017-10-24)
[root@localhost ~]# date -d "+28 years -2 months -9 days"
Tue Aug 15 15:30:11 CST 2045
[root@localhost ~]#
hwclock 硬件時鐘
hwclock -w systohc
hwclock -s hctosys
tzselect 時區選擇
[root@localhost ~]# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent or ocean.
1) Africa
2) Americas
3) Antarctica
4) Arctic Ocean
5) Asia
6) Atlantic Ocean
7) Australia
8) Europe
9) Indian Ocean
10) Pacific Ocean
11) none - I want to specify the time zone using the Posix TZ format.
#?
timedatectl 顯示各項時間
[root@localhost ~]# timedatectl
Local time: Tue 2017-10-24 15:36:43 CST
Universal time: Tue 2017-10-24 07:36:43 UTC
RTC time: Tue 2017-10-24 07:36:43
Timezone: n/a (CST, +0800)
NTP enabled: n/a
NTP synchronized: no
RTC in local TZ: no
DST active: n/a
[root@localhost ~]#
顯示系統所支持的時間區域
[root@localhost ~]# timedatectl list-timezones | more
Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
........
設置當前時區
[root@localhost ~]# timedatectl set-timezone Asia/Shanghai
[root@localhost ~]#
設置當前系統時間
[root@localhost ~]# timedatectl set-time "2017-9-9 12:00:00"
[root@localhost ~]# date
Sat Sep 9 12:00:01 CST 2017
[root@localhost ~]#
設置ntp時間同步是否開啓(前提ntp服務器開啓)
[root@localhost ~]# timedatectl set-ntp true
cat [選項] 文件名
-b 顯示文件內容的時候顯示行數
-n 顯示文件內容包括空行
-s 將多個空行合併成一個空行輸出
more [選項] 文件名
+行數 直接從給定的行數開始顯示
-s 將多個空行壓縮成一個空行
-p 清除屏幕後再顯示
head [選項] 文件
-n <行數> 顯示文件的最前指定的行
-c <字節數> 顯示文件前N個字節數裏的內容
-q 不輸出文件頭的內容
-v 輸出文件頭的內容
[root@localhost ~]# head -10 -v /etc/fstab
==> /etc/fstab <==
#
# /etc/fstab
# Created by anaconda on Mon Oct 23 14:49:30 2017
#
# Accessible filesystems, by reference, are maintained under '/dev/disk'
# See man pages fstab(5), findfs(8), mount(8) and/or blkid(8) for more info
#
UUID=debeb2cd-b005-4c53-87e9-8f78a4a33c00 / ext3 defaults 1 1
UUID=732a5dec-be83-4581-bba0-29395eed3552 /boot xfs defaults 0 0
[root@localhost ~]#
tail [選項] 文件
-f 循環讀取
-c <字節數> 顯示文件前N個字節數裏的內容
-q 不輸出文件頭的內容
-n <行數> 指定所顯示的行數
-v 輸出文件頭的內容
diff [選項] file1 file2
顯示信息:
a 爲需要附加
d 爲需要刪除
c 爲需要修改
[root@localhost ~]# diff a.txt b.txt
4d3
< d
7c6
< this is what we want
---
> you know that's tough
[root@localhost ~]# cat a.txt
a
b
c
d
1
2
this is what we want
[root@localhost ~]# cat b.txt
a
b
c
1
2
you know that's tough
[root@localhost ~]#
mv [選項] 源文件 目的路徑
-i 如果目的地有相同文件名時會出現提示
-v 在搬移文件時顯示進度,在移動多文件
時非常有用
-u 當移動時只有源文件比目的文件新的時候
纔會移動
-f 強制覆蓋已有的文件
cp [選項] 文件名(原件) 目的文件名(複印件)
-R 複製整個目錄裏的內容
-p 複製完後保持目錄的權限值
-v 在複製文件的時候顯示進度
-f 在複製的時候如果碰到目的文件名有重複就將原先的刪除
rm [選項] 文件名
-i 在刪除文件之前需要手工確認
-v 在刪除文件的時候顯示信息
-r 刪除目錄 -f 忽略提示
示例: rm -v filename
常用選項: rm -rf 目錄名
ln [選項] 源文件 鏈接文件
-f 刪除已存在的目的文件
-i 如果碰到有重複名字的提示如何操作
-v 顯示操作信息
-s 軟鏈接選項