文件的傳輸和瀏覽
使用file命令確定文件中是數據的類型
file命令確定一個文件的類型
file 文件名
在Linux系統中,文件的類型可以是正文、目錄、可執行文件、和符號鏈接等
[dag@dog ~]$ file game.txt
game.txt: ISO-8859 English text, with very long lines, with CRLF line terminators
[dag@dog ~]$ file flowers.JPG
flowers.JPG: JPEG image data, EXIF standard 2.2
[dag@dog ~]$ file lists200
lists200: UTF-8 Unicode text
[dag@dog ~]$ ls
babydog dog.JPG learning.txt 公共的 文檔
boydog epel-release-6-8.noarch.rpm lists 模板 下載
cal2038 flowers.JPG lists200 視頻 音樂
cal3009 game.txt NewZealand.JPG 圖片 桌面
[dag@dog ~]$ file lists
lists: UTF-8 Unicode text
[dag@dog ~]$ file babydog
babydog: directory
[dag@dog ~]$ ls -F /bin
alsaunmute* dnsdomainname@ ls* rview@
arch* domainname@ lsblk* sed*
awk@ dumpkeys* lscgroup* setfont*
basename* echo* lssubsys* setserial*
bash* ed* mail@ sh@
......
[dag@dog ~]$ file /bin/pwd
/bin/pwd: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.18, stripped
[dag@dog ~]$ file /bin/awk
/bin/awk: symbolic link to `gawk'
使用cat命令瀏覽正文文件的內容
如果這個文件是一個正文文件,就可使用cat(Concatenate的縮寫)命令列出這個文件的內容。cat命令將一個或多個文件內容顯示在屏幕上,該命令會不停頓的以制度的方式顯示顯示整個文件的內容。如果是顯示多個文件,則所有的文件會連續的顯示在屏幕上。
cat [options] [files]
[dag@dog ~]$ cat game.txt
How important is gaming in teaching to become an expert��
An old Chinese proverb, ��Tell me and I will forget, show me and I will remember, involve me and I will understand�� (Danchak, Jennings, Johnson & Scalzo, 1999, p. 4).
Learning is an integration of insight, experience, cognition, and actions (Kolb, 1984; Lainema, 2009). Learning through direct experience has been found to produce the most effective learning outcomes, whereby learners take action in the learning process and sees the consequences of their action (Friedman & Deek, 2002; Fu & Yu, 2006; Lainema, 2009). These individuals have better understanding and problem solving abilities (Gonen, Brill, & Frank, 2008). Hence, instructional design needs to be based on the concepts of learning and the learning process of an individual, and all noticeable instances of learning should be supported by some form of means or tools that facilitates the learning process (Lainema, 2009).
......
[dag@dog ~]$ cat -A game.txt
How important is gaming in teaching to become an expertM-#M-?^M$
^M$
An old Chinese proverb, M-!M-0Tell me and I will forget, show me and I will remember, involve me and I will understandM-!M-1 (Danchak, Jennings, Johnson & Scalzo, 1999, p. 4).^M$
^M$
Learning is an integration of insight, experience, cognition, and actions (Kolb, 1984; Lainema, 2009). Learning through direct experience has been found to produce the most effective learning outcomes, whereby learners take action in the learning process and sees the consequences of their action (Friedman & Deek, 2002; Fu & Yu, 2006; Lainema, 2009). These individuals have better understanding and problem solving abilities (Gonen, Brill, & Frank, 2008). Hence, instructional design needs to be based on the concepts of learning and the learning process of an individual, and all noticeable instances of learning should be supported by some form of means or tools that facilitates the learning process (Lainema, 2009).^M$
^M$
......
[dag@dog ~]$ cat -A lists
M-fM-^@M-;M-gM-^TM-(M-iM-^GM-^O 104$
dr-xr-xr-x. 2 root root 4096 5M-fM-^\M-^H 13 17:33 bin$
dr-xr-xr-x. 5 root root 4096 3M-fM-^\M-^H 25 00:12 boot$
drwxr-xr-x. 2 root root 4096 10M-fM-^\M-^H 15 2014 cgroup$
drwxr-xr-x. 18 root root 3780 5M-fM-^\M-^H 13 16:12 dev$
drwxr-xr-x. 118 root root 12288 5M-fM-^\M-^H 13 17:33 etc$
drwxr-xr-x. 4 root root 4096 5M-fM-^\M-^H 13 17:30 home$
drwxr-xr-x. 11 root root 4096 9M-fM-^\M-^H 10 2014 lib$
dr-xr-xr-x. 9 root root 12288 5M-fM-^\M-^H 13 17:33 lib64$
drwx------. 2 root root 16384 3M-fM-^\M-^H 24 23:46 lost+found$
drwxr-xr-x. 2 root root 4096 5M-fM-^\M-^H 13 15:55 media$
drwxr-xr-x. 2 root root 0 5M-fM-^\M-^H 13 16:12 misc$
......
[dag@dog ~]$ cat -s lists
總用量 104
dr-xr-xr-x. 2 root root 4096 5月 13 17:33 bin
dr-xr-xr-x. 5 root root 4096 3月 25 00:12 boot
drwxr-xr-x. 2 root root 4096 10月 15 2014 cgroup
drwxr-xr-x. 18 root root 3780 5月 13 16:12 dev
drwxr-xr-x. 118 root root 12288 5月 13 17:33 etc
drwxr-xr-x. 4 root root 4096 5月 13 17:30 home
drwxr-xr-x. 11 root root 4096 9月 10 2014 lib
dr-xr-xr-x. 9 root root 12288 5月 13 17:33 lib64
drwx------. 2 root root 16384 3月 24 23:46 lost+found
drwxr-xr-x. 2 root root 4096 5月 13 15:55 media
drwxr-xr-x. 2 root root 0 5月 13 16:12 misc
......
[dag@dog ~]$ cat -b lists
1 總用量 104
2 dr-xr-xr-x. 2 root root 4096 5月 13 17:33 bin
3 dr-xr-xr-x. 5 root root 4096 3月 25 00:12 boot
4 drwxr-xr-x. 2 root root 4096 10月 15 2014 cgroup
5 drwxr-xr-x. 18 root root 3780 5月 13 16:12 dev
6 drwxr-xr-x. 118 root root 12288 5月 13 17:33 etc
7 drwxr-xr-x. 4 root root 4096 5月 13 17:30 home
8 drwxr-xr-x. 11 root root 4096 9月 10 2014 lib
9 dr-xr-xr-x. 9 root root 12288 5月 13 17:33 lib64
10 drwx------. 2 root root 16384 3月 24 23:46 lost+found
11 drwxr-xr-x. 2 root root 4096 5月 13 15:55 media
12 drwxr-xr-x. 2 root root 0 5月 13 16:12 misc
13 drwxr-xr-x. 3 root root 4096 5月 13 16:08 mnt
......
[dag@dog ~]$ cat > news
wo are family
i like you
ni hao ma [dag@dog ~]$ cat news
wo are family
i like you
ni hao ma [dag@dog ~]$
[dag@dog ~]$ cat news
wo are family
i like you
ni hao ma [dag@dog ~]$
使用head命令瀏覽文件中的內容
[dag@dog ~]$ head /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
adm:x:3:4:adm:/var/adm:/sbin/nologin
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
mail:x:8:12:mail:/var/spool/mail:/sbin/nologin
uucp:x:10:14:uucp:/var/spool/uucp:/sbin/nologin
[dag@dog ~]$ head -n 2 /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
[dag@dog ~]$ head ---line 2 /etc/passwd
head:無法識別的選項“---line”
請嘗試執行"head --help"來獲取更多信息。
[dag@dog ~]$ head --line 2 /etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
[dag@dog ~]$ head -15 /usr/share/dict/words
1080
10-point
10th
11-point
12-point
16-point
18-point
1st
2
20-point
2,4,5-t
2,4-d
2D
2nd
30-30
[dag@dog ~]$
[dag@dog ~]$ head game.txt
How important is gaming in teaching to become an expert��
An old Chinese proverb, ��Tell me and I will forget, show me and I will remember, involve me and I will understand�� (Danchak, Jennings, Johnson & Scalzo, 1999, p. 4).
Learning is an integration of insight, experience, cognition, and actions (Kolb, 1984; Lainema, 2009). Learning through direct experience has been found to produce the most effective learning outcomes, whereby learners take action in the learning process and sees the consequences of their action (Friedman & Deek, 2002; Fu & Yu, 2006; Lainema, 2009). These individuals have better understanding and problem solving abilities (Gonen, Brill, & Frank, 2008). Hence, instructional design needs to be based on the concepts of learning and the learning process of an individual, and all noticeable instances of learning should be supported by some form of means or tools that facilitates the learning process (Lainema, 2009).
Knowledge and action exists concurrently, where action helps learners to enforce and understand the knowledge learnt, and action itself helps an individual to discover new knowledge (Crookall & Thorngate, 2009; Greitzer, Kuchar, & Huston, 2007). The key objective of ��knowledge�� is ��action��, as knowledge retention depends on action, which without it, would not be possible (Crookall & Thorngate, 2009).
��Give the pupils something to do, not something to learn; and the doing is of such a nature as to demand thinking; learning naturally results.�� �� John Dewey (1859-1952)
[dag@dog ~]$ head -2 game.txt
How important is gaming in teaching to become an expert��
使用tail命令瀏覽文件中的內容
顯示文中最後幾行使用的命令是tail,該命令默認顯示一個文件最後10行的內容,可以通過在tail命令中使用 -n或+n選項來改變顯示的行數,-n選項顯示從文件末尾顯示從文件末尾算起的第n行,而+n選項顯示從文件的第n行算起到文件結尾的內容。
[dag@dog ~]$ tail /etcpasswd
tail: 無法打開"/etcpasswd" 讀取數據: 沒有那個文件或目錄
[dag@dog ~]$ tail /etc/passwd
nfsnobody:x:65534:65534:Anonymous NFS User:/var/lib/nfs:/sbin/nologin
abrt:x:173:173::/etc/abrt:/sbin/nologin
haldaemon:x:68:68:HAL daemon:/:/sbin/nologin
gdm:x:42:42::/var/lib/gdm:/sbin/nologin
pulse:x:497:495:PulseAudio System Daemon:/var/run/pulse:/sbin/nologin
oprofile:x:16:16:Special user account to be used by OProfile:/home/oprofile:/sbin/nologin
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/sbin/nologin
tcpdump:x:72:72::/:/sbin/nologin
dag:x:500:500:dad dog:/home/dag:/bin/bash
cat:x:501:501::/home/cat:/bin/bash
[dag@dog ~]$ su root
密碼:
[root@dog dag]# useradd fox
[root@dog dag]# tail -n 2 /etc/passwd
cat:x:501:501::/home/cat:/bin/bash
fox:x:502:502::/home/fox:/bin/bash
[root@dog dag]# tail --line 2 /etc/passwd
cat:x:501:501::/home/cat:/bin/bash
fox:x:502:502::/home/fox:/bin/bash
[root@dog dag]# tail -2 /etc/passwd
cat:x:501:501::/home/cat:/bin/bash
fox:x:502:502::/home/fox:/bin/bash
[root@dog dag]# tail -l2 /usr/share/dict/words
tail:無效選項 -- l
請嘗試執行"tail --help"來獲取更多信息。
[root@dog dag]# tail -l2 /usr/share/dict/words
tail:無效選項 -- l
請嘗試執行"tail --help"來獲取更多信息。
[root@dog dag]# tail -2 /usr/share/dict/words
zZt
ZZZ
[root@dog dag]# tail -f /var/log/messages
May 16 10:45:37 dog NetworkManager[1959]: <info> gateway 192.168.40.2
May 16 10:45:37 dog NetworkManager[1959]: <info> nameserver '192.168.40.2'
May 16 10:45:37 dog NetworkManager[1959]: <info> domain name 'localdomain'
May 16 10:45:37 dog NetworkManager[1959]: <info> Activation (eth0) Stage 5 of 5 (IP Configure Commit) scheduled...
......
使用wc命令顯示文件行、單詞和字符數
we命令 用來顯示一個文件中的行數、單詞數和字符數。
格式如下:
-l(line))僅顯示行數
-w (word)僅顯示單詞數
-c(character) 僅顯示字符數
[root@dog dag]# wc learning.txt
18 670 4720 learning.txt
[root@dog dag]# wc lists200
24 209 1208 lists200
[root@dog dag]# wc -w learning.txt
670 learning.txt
[root@dog dag]# wc -l /etc/passwd
37 /etc/passwd
[root@dog dag]# wc -l /usr/share/dict/words
479829 /usr/share/dict/words
使用more命令瀏覽文件
如果一個文件很大,能不能讓文件內容在屏幕上只顯示一頁,在需要時再翻到下一頁或者上一頁呢
使用more命令
空格鍵:向前(向下)移動一個屏幕
Enter鍵:一次移動一行,
b :往回走
h:顯示一個幫助菜單
/字符串:向前搜索這個字符串
n:發現這個字符串的下一次出現
q:退出more命令並返回操作系統提示符下
v:在當前行啓動usr/bin/vi(vi是linux或UNIX自帶的文字編輯器)