1.查看目录和文件
(1)显示当前目录:pwd
[root@hostline /]# pwd
/
(2)改变目录:cd
[root@hostline /]# cd usr
[root@hostline usr]#
在/usr/bin子目录时,可以用命令进入/usr子目录
[root@hostline bin]# cd ..
[root@hostline usr]# ls
在/usr/bin子目录中还可以使用命令进入根目录
[root@hostline usr]# cd /
[root@hostline /]#
2.列出目录内容: ls
[root@hostline /]# ls
a.txt boot etc lib media opt root sbin sys tmp var
bin dev home lib64 mnt proc run srv test usr
不带ls的命令,列出的目录下所有文件和子目录
[root@hostline /]# ls -l
总用量 44
-rw-r--r--. 1 root root 88 5月 18 20:32 a.txt
lrwxrwxrwx. 1 root root 7 5月 17 19:24 bin -> usr/bin
dr-xr-xr-x. 3 root root 4096 5月 17 19:48 boot
drwxr-xr-x. 20 root root 3260 5月 24 18:26 dev
drwxr-xr-x. 137 root root 8192 5月 24 18:26 etc
drwxr-xr-x. 4 root root 43 5月 19 20:09 home
lrwxrwxrwx. 1 root root 7 5月 17 19:24 lib -> usr/lib
lrwxrwxrwx. 1 root root 9 5月 17 19:24 lib64 -> usr/lib64
drwxr-xr-x. 2 root root 6 5月 25 2015 media
drwxr-xr-x. 2 root root 6 5月 25 2015 mnt
drwxr-xr-x. 3 root root 15 5月 17 19:42 opt
dr-xr-xr-x. 499 root root 0 5月 24 18:26 proc
dr-xr-x---. 18 root root 4096 5月 24 18:30 root
drwxr-xr-x. 38 root root 1160 5月 24 18:31 run
lrwxrwxrwx. 1 root root 8 5月 17 19:24 sbin -> usr/sbin
drwxr-xr-x. 2 root root 6 5月 25 2015 srv
dr-xr-xr-x. 13 root root 0 5月 24 18:26 sys
drwxr-xr-x. 2 root root 21 5月 20 11:14 test
drwxrwxrwt. 73 root root 8192 5月 24 19:27 tmp
drwxr-xr-x. 14 root root 4096 5月 20 11:35 usr
drwxr-xr-x. 21 root root 4096 5月 24 18:26 var
ls列出的是目录和文件的详细信息
ls -f 在每个目录上加/,在可执行文件后加*,在连接文件后加@。
[root@hostline /]# ls -f
. boot proc sys root var bin lib home mnt srv a.txt
.. dev run etc tmp usr sbin lib64 media opt test
ls -a列出隐藏文件
[root@hostline /]# ls -a
. a.txt boot etc lib media opt root sbin sys tmp var
.. bin dev home lib64 mnt proc run srv test usr
2.列出目录内容:dir和vdir
[root@hostline /]# dir usr
bin games lib libexec mysoft share tmp
etc include lib64 local sbin src
vdir相当于ls命令上加-l
[root@hostline /]# vdir usr
总用量 256
dr-xr-xr-x. 2 root root 45056 5月 17 19:43 bin
drwxr-xr-x. 2 root root 6 5月 25 2015 etc
drwxr-xr-x. 2 root root 6 5月 25 2015 games
drwxr-xr-x. 36 root root 4096 5月 17 19:41 include
dr-xr-xr-x. 43 root root 4096 5月 17 19:41 lib
dr-xr-xr-x. 139 root root 69632 5月 17 19:43 lib64
drwxr-xr-x. 35 root root 8192 5月 17 19:41 libexec
drwxr-xr-x. 13 root root 4096 5月 21 21:30 local
drwxr-xr-x. 8 root root 4096 5月 21 21:31 mysoft
dr-xr-xr-x. 2 root root 20480 5月 17 19:43 sbin
drwxr-xr-x. 240 root root 8192 5月 17 19:42 share
drwxr-xr-x. 4 root root 32 5月 17 19:24 src
lrwxrwxrwx. 1 root root 10 5月 17 19:24 tmp -> ../var/tmp
3.查看文本文件:cat和more
cat命令用于查看文件内容(通常是一个文本文件),后跟文件名作为参数
[root@hostline /]# cat a.txt
ddddddddddddddddddddddsfnasjva
adfasdfandfajfda
asdfasfafasdfasdfasfdanihapcongdidididi
cat -n 在每行前面显示行号
[root@hostline /]# cat -n a.txt
1 ddddddddddddddddddddddsfnasjva
2 adfasdfandfajfda
3 asdfasfafasdfasdfasfdanihapcongdidididi
4.阅读文件的开头和结尾:head和tail
[root@hostline /]# head -n 2 a.txt
ddddddddddddddddddddddsfnasjva
adfasdfandfajfda
说明:-n显示行号,2显示前面两行
[root@hostline /]# tail -n 2 a.txt
adfasdfandfajfda
asdfasfafasdfasdfasfdanihapcongdidididi
说明:同上,显示下面两行
5.查找文件内容:grep
[root@hostline /]# cat a.txt
ddddddddddddddddddddddsfnasjva
adfasdfandfajfda
asdfasfafasdfasdfasfdanihapcongdidididi
nihaoi
[root@hostline /]# grep nihao a.txt
nihaoi
说明:nihao是查找的内容
6.我的东西在哪里 find命令
[root@hostline /]# find /usr/bin -name zip -print
/usr/bin/zip
说明:find在寻找过程中,需要指定路径 /usr/bin 说明在bin文件夹下面查找
-name zip 是要查找的名称未zip的文件
-print表示将结果标准输出
7.定位功能 locate命令
[root@hostline /]# locate *.doc
/usr/lib/kbd/keymaps/legacy/i386/qwerty/no-latin1.doc
/usr/lib64/python2.7/pdb.doc
/usr/mysoft/openssl-1.0.1t/crypto/rc2/rrc2.doc
/usr/mysoft/openssl-1.0.1t/crypto/rc4/rrc4.doc
/usr/share/doc/doxygen-1.8.5/examples/page.doc
说明:该命令可以更快的查找你想要的文件