1.文件管理

file 查看文件数据类型

#file +文件

cat
-n 显示行号
-A 包括控制字符(换行符/制表符)
linux $
Windows ^M$

grep 针对文件内容进行过滤
[root@Cly ~]# grep 'root' /etc/passwd
[root@Cly ~]# grep '^root' /etc/passwd
[root@Cly ~]# grep 'bash$' /etc/passwd
[root@Cly ~]# grep 'failure' /var/log/secure

-----

7种文件类型
查看文件类型 : ls -l 文件名

  • 普通文件
    d 目录文件
    b 块设备 block /dev/sda /dev/sda1 /dev/sr0
    c 字符设备 终端 tty 查看终端 /dev/pts/0 #tty //查看字符设备名称
    l symbolic link 符号连接 快捷方式/软连接
    p pipe 管道 本地进程间通信的一种方式
    s socket 套接字 网络通信的一种方式

-----

/目录结构: FSH (Filesystem Hierarchy Standard)

bin 普通用户使用的命令 /bin/ls, /bin/date
sbin 管理员使用的命令 /sbin/service
dev 设备文件 /dev/sda,/dev/sda1,/dev/tty1,/dev/tty2,/dev/pts/1, /dev/zero, /dev/null, /dev/random
root root用户的HOME
home 普通用户家Base目录
proc 虚拟的文件系统,反映出来的是内核,进程信息或实时状态
usr 系统文件,相当于C:\Windows
/usr/local 软件安装的目录,相当于C:\Program
/usr/bin 普通用户使用的应用程序
/usr/sbin 管理员使用的应用程序
/usr/lib 库文件Glibc 32bit
/usr/lib64 库文件Glibc 64bit
boot 存放的系统启动相关的文件,例如kernel,grub(引导装载程序)
etc 配置文件
系统相关如网络/etc/sysconfig/network /etc/hostname
应用相关配置文件如/etc/ssh/sshd_config...

lib 库文件Glibc
lib64 库文件Glibc

tmp 临时文件(全局可写:进程产生的临时文件)

var 存放的是一些变化文件,比如数据库,日志,邮件....
mysql: /var/lib/mysql
vsftpd: /var/ftp
mail: /var/spool/mail
cron: /var/spool/cron
log: /var/log
临时文件: /var/tmp(进程产生的临时文件)

==设备(主要指存储设备)挂载目录==
media 移动设备默认的挂载点
mnt 手工挂载设备的挂载点
misc automount进程挂载
net automount进程挂载

-----

命令存储位置:

/usr/bin 普通用户使用的应用程序
/usr/sbin 管理员使用的应用程序

库文件存储位置:

/usr/lib 库文件Glibc
/usr/lib64 库文件Glibc

-----文件管理之:创建/复制/移动/删除

==创建
文件 touch

[root@Cly ~]# touch file1.txt //无则创建,有则修改时间
[root@Cly ~]# touch file3 file4
[root@Cly ~]# touch /home/file10.txt
[root@Cly ~]# touch /home/file5 file6
[root@Cly ~]# touch /home/{zhuzhu,gougou}
[root@Cly ~]# touch file{1..20}
[root@Cly ~][root@Cly ~]# touch file{a..c}
[root@Cly ~]# touch yang{a,b,c} //{}集合,等价touch yanga yangb yangc

目录 mkdir
[root@Cly ~]# mkdir dir1
[root@Cly ~]# mkdir /home/dir2 /home/dir3
[root@Cly ~]# mkdir /home/{dir4,dir5}
[root@Cly ~]# mkdir -v /home/{dir6,dir7}
[root@Cly ~]# mkdir -v /hoem/dir8/111/22
[root@Cly ~]# mkdir -pv /hoem/dir8/111/222 //包括其父母的创建,不会有任何消息输出
[root@Cly ~]# mkdir -pv /home/{yang/{dir1,111},tianyun}

==复制 cp
Usage: cp [OPTION]... [-T] SOURCE DEST
[root@Cly ~][root@Cly ~]# cd
[root@Cly ~]# mkdir /home/dir{1,2}
[root@Cly ~]# cp -v anaconda-ks.cfg /home/dir1 //目录
[root@Cly ~]# cp -v anaconda-ks.cfg /home/dir1/yang.txt //文件
[root@Cly ~]# cp -rv /etc /home/dir1
[root@Cly ~]# cp -v anaconda-ks.cfg /home/dir90 //没有/home/dir90
[root@Cly ~]# cp -v anaconda-ks.cfg /home/dir2
[root@Cly ~]# cp -v file1 !$
[root@Cly ~]# cp -rv /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/passwd /etc/hostname /home/dir2 //将多个文件拷贝到同一个目录
[root@Cly ~]# cp -rv /etc/sysconfig/network-scripts/ifcfg-eth0 /etc/passwd /etc/hostname /etc/hosts .
[root@Cly ~]# cp -r /etc /tmp
[root@Cly ~]# cp -rf /etc /tmp

==移动 mv
Usage: mv [OPTION]... [-T] SOURCE DEST
[root@Cly ~][root@Cly ~][root@Cly ~]# mv file1 /home/dir3 将file2移动到/home/dir3
[root@Cly ~][root@Cly ~]# mv file2 /home/dir3/file20 将file2移动到/home/dir3,并改名为file20
[root@Cly ~]# mv file4 file5 将file4重命名为file5,当前位置的移动就是重命名

==删除 rm
示例1:
手动删除: /home/dir1

cd /home

rm -rf dir1

-r 递归
-f force强制
-v 详细过程
脚本删除: /home/dir1
rm -rf /home/dir1

-----文件管理之:查看文件内容

/etc/profile //设置系统环境变量
/etc/bashrc //影响bash shell环境
/var/log/messages //系统主日志文件
/var/log/secure //跟安全相关的日志如ssh登录,本地登录...

猜你喜欢

转载自blog.51cto.com/13737089/2120418
1.