linux常用的文件处理与管理命令有,详解linux文件处理的的常用命令

原创Blog,转载请注明出处

附上之前访问量比较高的几篇linux博客

linux中所有的东西都是文件,命令就是一个一个二进制文件

1、ls

/bin/ls

常用选项

-a 所有文件(包括隐藏文件)

-l 详细信息

-d 目录属性

-i 查看inode

举例

[root@localhost testForCsdn]# ls

fileList first second

[root@localhost testForCsdn]# ls -a

. .. fileList first second

[root@localhost testForCsdn]# ls -l

total 16

-rw-r--r-- 1 root root 100 Oct 18 23:12 fileList

-rw-r--r-- 1 root root 0 Oct 24 18:04 first

-rw-r--r-- 1 root root 0 Oct 24 18:04 second

[root@localhost testForCsdn]# ls -al

total 32

drwxr-xr-x 2 root root 4096 Oct 24 18:04 .

drwxr-x--- 17 root root 4096 Oct 24 17:56 ..

-rw-r--r-- 1 root root 100 Oct 18 23:12 fileList

-rw-r--r-- 1 root root 0 Oct 24 18:04 first

-rw-r--r-- 1 root root 0 Oct 24 18:04 second

[root@localhost testForCsdn]# ls -d

.

[root@localhost testForCsdn]# ls -i

2256719 fileList 2256718 first 2256730 second分析下

-rw-r--r-- 1 root root 100 Oct 18 23:12 fileList对于这一行来说,从左至右分析

-表示这是一个二进制文件

rw-r--r-- 分别r表示读权限,w表示写权限,-表示没有权限,如果是x表示可执行权限,一共9个,三个一组,分别表示创建者,所属组,其他人

所以,对于创建者来说是rw-就是可读写不可执行,对于所属组就是r--只有读的权限,其他人只有读的权限

1表示硬链接数目

第一个root表示用户

第二个root表示用户组

100表示文件大小,如果是目录就是目录和子目录大小

Oct 18 23:13:12 表示最后修改的时间

fileList 表示文件名

2、cd

change direction

和cd配合的常用命令还有

pwd  查看当前目录

改变目录

首先讲解下目录

/根分区,所有的文件和目录都由此开始

/bin用户可执行文件

/sbin系统可执行文件,主要供管理员使用,s为super

/etc配置文件

/dev设备文件

/proc进程信息,如/proc/cpuinfo包含了处理器信息

/var 变量文件如log,mail

/usr用户程序,为用户应用程序存放文件

/home用户主目录

/boot启动加载项

/opt可选应用

/mnt挂载目录

/media可移动媒体 如/media/cdrom

/srv服务数据

举例

[root@localhost etc]# cd /etc/

[root@localhost etc]# pwd

/etc

[root@localhost etc]# cd ~

[root@localhost ~]# pwd

/root这里要说明的是

cd ~代表回到当前登陆用户的主目录

如果是root回到/root/

如果是普通用户,回到/home/

3、touch

创建空白文件文件或者修改文件的时间戳

常用选项

-a 只更改存取时间

-c 不建立任何文档

-d 使用指定的日期

-m只更改变动时间

-r 把指定文档的或者目录的日期时间改为和参考文档的相同

-t 设置指定的时间戳

举例

[root@localhost testForCsdn]# ls -l

total 16

-rw-r--r-- 1 root root 100 Oct 18 23:12 fileList

-rw-r--r-- 1 root root 0 Oct 24 18:04 first

-rw-r--r-- 1 root root 0 Oct 24 18:04 second

[root@localhost testForCsdn]# touch thrid

[root@localhost testForCsdn]# ls -l

total 20

-rw-r--r-- 1 root root 100 Oct 18 23:12 fileList

-rw-r--r-- 1 root root 0 Oct 24 18:04 first

-rw-r--r-- 1 root root 0 Oct 24 18:04 second

-rw-r--r-- 1 root root 0 Oct 24 18:34 thrid

[root@localhost testForCsdn]# touch -t 201410250935.40 thrid

[root@localhost testForCsdn]# ls -l

total 20

-rw-r--r-- 1 root root 100 Oct 18 23:12 fileList

-rw-r--r-- 1 root root 0 Oct 24 18:04 first

-rw-r--r-- 1 root root 0 Oct 24 18:04 second

-rw-r--r-- 1 root root 0 Oct 25 2014 thrid可以看到,用-t更改了时间戳

4 mkdir

创建一个目录

常用选项

-m创建时候指定权限

-p指定路径,如果该路径上有些目录不存在,则会创建,就是可以一次创建多层目录

-v显示详细信息

举例

[root@localhost testForCsdn]# mkdir -m 777 firstDir

[root@localhost testForCsdn]# ls -al

total 44

drwxr-xr-x 3 root root 4096 Oct 24 18:41 .

drwxr-x--- 17 root root 4096 Oct 24 17:56 ..

-rw-r--r-- 1 root root 100 Oct 18 23:12 fileList

-rw-r--r-- 1 root root 0 Oct 24 18:04 first

drwxrwxrwx 2 root root 4096 Oct 24 18:41 firstDir

-rw-r--r-- 1 root root 0 Oct 24 18:04 second

-rw-r--r-- 1 root root 0 Oct 25 2014 thrid

[root@localhost testForCsdn]# mkdir -p firstDir/secondDir/thridDir

[root@localhost testForCsdn]# cd firstDir/secondDir/thridDir/

[root@localhost thridDir]# pwd

/root/testForCsdn/firstDir/secondDir/thridDir可以看到,通过-p一次创建了多层目录,-m在创建目录的同时给予777的权限

5 cp

copy

常用选项

-b删除覆盖目的文件的时候先备份

-i 询问是否覆盖

-P保留源文件的或者目录的属性:所有者,所属组,权限时间

-r拷贝目录

举例

[root@localhost testForCsdn]# ls

fileList firstDir second thrid

[root@localhost testForCsdn]# ls firstDir/

fileList second

[root@localhost testForCsdn]# cp thrid firstDir/

[root@localhost testForCsdn]# cp -b fileList firstDir/

cp: overwrite `firstDir/fileList'? y

[root@localhost testForCsdn]# ls firstDir/

fileList fileList~ second thrid

[root@localhost testForCsdn]# mkdir secondDic

[root@localhost testForCsdn]# cp -r firstDir/ secondDic/

[root@localhost testForCsdn]# ls secondDic/

firstDir

顺便说下scp:举个例子

scp是远程拷贝,如果要远程拷贝目录用-r

scp -r root@192.168.0.12:~/testCSDN/ localCSDN/

把192.168.0.12的~/testCSDN拷贝到localCSND下

6、mv

剪切和重命名

举例

[root@localhost testForCsdn]# ls

fileList firstDir second secondDic thrid

You have new mail in /var/spool/mail/root

[root@localhost testForCsdn]# mkdir tempDic

[root@localhost testForCsdn]# ls

fileList firstDir second secondDic tempDic thrid

[root@localhost testForCsdn]# mv fileList newName

[root@localhost testForCsdn]# mv newName tempDic/

[root@localhost testForCsdn]# ls

firstDir second secondDic tempDic thrid

[root@localhost testForCsdn]# ls tempDic/

newName

7 cat more

都是用来查看文件内容

cat适合较短的文件

More会分页查看:空格翻页,回车下一行,q退出

cat filename

more filename

A111105119-108136.png_small.png

8 head tail

查看文件的前几行,后几行

tail -f可以用来动态查看文件的后几行

举例

A111107369-108136.png_small.png

9 ln

创建软连接和硬链接

软链接:类似于windows中的快捷方式

硬链接:两个文件同步更新

软链接可以跨文件系统,硬链接不可以

举例

创建一个软连接

[root@localhost ~]# ln -s file.txt file.hardlink

创建一个硬链接

[root@localhost ~]# ln file.txt file.hardlink

可以看到,file.txt的硬链接数目变成了2

-rw-r--r-- 2 root root 210 Oct 19 07:54 file.hardlink

lrwxrwxrwx 1 root root 8 Oct 24 19:14 file.softlink -> file.txt

-rw-r--r-- 2 root root 210 Oct 19 07:54 file.txt

然后,修改file.txt

在文件开始键入testCSDN

再查看硬链接

[root@localhost ~]# head -5 file.hardlink

testForCSDN

backup

bin

boot

dev可以看到,同步更新了内容

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值