Linux - 目錄結構與查看,複製,刪除,剪切指令

Linux當中,一切皆文件。linux

Linux目錄結構

/ 根分區,只有root用戶對此目錄擁有寫權限。session

/etc 配置文件less

/boot 啓動文件ide

/var 可增加的目錄 。日誌,文件等。ui

/root 管理員全部數據 root用戶的家目錄。unix

/tmp 臨時文件 (大概15天清空一次。)日誌

/usr unix software source /usr/src 源代碼目錄。/usr/local 本身的軟件安裝位置。code

/bin 命令 二進制可執行文件。進程

/sbin 系統命令。string

/mnt 掛載目錄。

/dev 設備文件。 一切皆文件,終端,磁盤等。鍵盤,鼠標等。

/home 普通用戶文件存放位置。

/proc 虛擬目錄。能夠查看每一個進程的狀況。

/lib 存放系統的庫文件(動態庫,靜態庫。 .a靜態庫,.so動態庫)。相似於.dll文件。

絕對路徑與相對路徑

絕對路徑是從/ 開始的。

相對路徑是以. .. 開始的。

建立,刪除複製文件

touch a.txt

建立一個文件

mkdir test

建立一個目錄

[root@local ~]# cat a.txt
hello linux

查看文件

[root@local ~]# less /var/log/messages

less 能夠上下左右查看。enter,空格都是下一頁。q退出查看。

[root@local ~]# more /var/log/messages

more只能向下翻頁查看。

[root@local ~]# cat /var/log/messages

cat一次性展現全部內容。

[root@local ~]# tail -n 10 /var/log/messages 
Jan  5 15:30:01 local systemd: Started Session 14 of user root.
Jan  5 15:30:01 local systemd: Starting Session 14 of user root.
Jan  5 15:40:01 local systemd: Started Session 15 of user root.
Jan  5 15:40:01 local systemd: Starting Session 15 of user root.
Jan  5 15:50:01 local systemd: Started Session 16 of user root.
Jan  5 15:50:01 local systemd: Starting Session 16 of user root.
Jan  5 16:00:01 local systemd: Started Session 17 of user root.
Jan  5 16:00:01 local systemd: Starting Session 17 of user root.
Jan  5 16:01:01 local systemd: Started Session 18 of user root.
Jan  5 16:01:01 local systemd: Starting Session 18 of user root.

tail 最後多少行。

[root@local ~]# head -n 10 /var/log/messages 
Jan  2 16:17:58 local rsyslogd: [origin software="rsyslogd" swVersion="7.4.7" x-pid="887" x-info="http://www.rsyslog.com"] start
Jan  2 16:17:47 local journal: Runtime journal is using 8.0M (max allowed 99.2M, trying to leave 148.9M free of 984.9M available → current limit 99.2M).
Jan  2 16:17:47 local journal: Runtime journal is using 8.0M (max allowed 99.2M, trying to leave 148.9M free of 984.9M available → current limit 99.2M).
Jan  2 16:17:47 local kernel: Initializing cgroup subsys cpuset
Jan  2 16:17:47 local kernel: Initializing cgroup subsys cpu
Jan  2 16:17:47 local kernel: Initializing cgroup subsys cpuacct
Jan  2 16:17:47 local kernel: Linux version 3.10.0-327.el7.x86_64 (mockbuild@x86-034.build.eng.bos.redhat.com) (gcc version 4.8.3 20140911 (Red Hat 4.8.3-9) (GCC) ) #1 SMP Thu Oct 29 17:29:29 EDT 2015
Jan  2 16:17:47 local kernel: Command line: BOOT_IMAGE=/vmlinuz-3.10.0-327.el7.x86_64 root=UUID=87b51ffa-2f57-4ac2-99e7-e491bb257520 ro rhgb quiet LANG=zh_CN.UTF-8
Jan  2 16:17:47 local kernel: Disabled fast string operations
Jan  2 16:17:47 local kernel: e820: BIOS-provided physical RAM map:

head 開頭多少行。

[root@local ~]# tail -f -n 10 /var/log/messages 
Jan  5 15:30:01 local systemd: Started Session 14 of user root.
Jan  5 15:30:01 local systemd: Starting Session 14 of user root.
Jan  5 15:40:01 local systemd: Started Session 15 of user root.
Jan  5 15:40:01 local systemd: Starting Session 15 of user root.
Jan  5 15:50:01 local systemd: Started Session 16 of user root.
Jan  5 15:50:01 local systemd: Starting Session 16 of user root.
Jan  5 16:00:01 local systemd: Started Session 17 of user root.
Jan  5 16:00:01 local systemd: Starting Session 17 of user root.
Jan  5 16:01:01 local systemd: Started Session 18 of user root.
Jan  5 16:01:01 local systemd: Starting Session 18 of user root.
Jan  5 16:03:51 local systemd-logind: New session 19 of user root.
Jan  5 16:03:51 local systemd: Started Session 19 of user root.
Jan  5 16:03:51 local systemd: Starting Session 19 of user root.
Jan  5 16:03:51 local dbus[887]: [system] Activating service name='org.freedesktop.problems' (using servicehelper)
Jan  5 16:03:51 local dbus-daemon: dbus[887]: [system] Activating service name='org.freedesktop.problems' (using servicehelper)
Jan  5 16:03:51 local dbus[887]: [system] Successfully activated service 'org.freedesktop.problems'
Jan  5 16:03:51 local dbus-daemon: dbus[887]: [system] Successfully activated service 'org.freedesktop.problems'

tail -f 動態的查看數據。這個很實用。

[root@local ~]# rm -r test2
rm:是否刪除目錄 "test2"?y
[root@local ~]# rm -rf test

rm -r 包括子目錄,-f 強制刪除。

cp 複製。

[root@local ~]# cp b.txt a.txt

mv 重命名。剪切。

[root@local ~]# mv a.txt b.txt
相關文章
相關標籤/搜索