文件的传输和浏览

使用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自带的文字编辑器)

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章