linux命令pri,linux基本命令

建立新目录:mkdir

格式为 mkdir [目录名]

mkdir 可以建立多层目录

[caibei@localhost ~]$ mkdir C

[caibei@localhost C]$ mkdir -p  c1/c2/c3

建立新文档 :touch

[caibei@localhost C]$ touch pri

[caibei@localhost C]$ ls

c1  pri

设置文件的访问权限 chmod

格式:用户符号+(-)权限   文件名

u:拥有者 g:组 o:其他

给u加权限:

[caibei@localhost C]$ chmod u+r+w pri

-rw-rw-r--. 1 caibei caibei    0 May 14 04:55 pri

给u减权限:

[caibei@localhost C]$ chmod u-r pri

[caibei@localhost C]$ ll

total 4

--w-rw-r--. 1 caibei caibei    0 May 14 04:55 pri

也可以利用八进制表示权限,0表示没有,1表示具有这个权限

给u,g,o加上所有的权限:

[caibei@localhost C]$ chmod 777 pri

[caibei@localhost C]$ ll

total 4

-rwxrwxrwx. 1 caibei caibei    0 May 14 04:55 pri

改变文件拥有者 chown

注:只有root才有权限使用

将pri文件改成caibei拥有:

[caibei@localhost C]$ chown root pri

chown: changing ownership of `pri': Operation not permitted

[caibei@localhost C]$ su

Password:

[root@localhost C]# chown caibei pri

[root@localhost C]# ll

total 4

drwxrwxr-x. 3 caibei caibei 4096 May 14 04:44 c1

-rwxrwxrwx. 1 caibei caibei    0 May 14 04:55 pri

改变文件的所属组 chgrp

[root@localhost C]# chgrp caibei pri

[root@localhost C]# ll

total 4

drwxrwxr-x. 3 caibei caibei 4096 May 14 04:44 c1

-rwxrwxrwx. 1 caibei caibei    0 May 14 04:55 pri

查看或者修改掩码 umask

新建文件夹默认权限:0666-掩码

新建目录默认权限:0777-掩码

[root@localhost C]# umask 0422

[root@localhost C]# ll

total 4

drwxrwxr-x. 3 caibei caibei 4096 May 14 04:44 c1

-rwxrwxrwx. 1 caibei caibei    0 May 14 04:55 pri

-rw-r--r--. 1 caibei root      0 May 14 05:32 pro

[root@localhost C]# umask

0422

文件和目录的显示 ls

ls -a 显示全部文件名包括以.开头隐藏的文件名

ls -i 列出文件inode号码

ls -F 在每个文件名后附上一个字符说明文件类型,'*'可执行普通文件,'/'目录,'@’链接

[root@localhost C]# ls -a

.  ..  c1  pri  pro

[root@localhost C]# ls -i

787323 c1  787332 pri  787304 pro

[root@localhost C]# ls -F

c1/  pri*  pro

变换目录 cd

格式;cd 文件名

cd.. 返回上级目录

cd ~ 返回自己家

cd - 返回刚刚的目录

[root@localhost C]# cd

[root@localhost ~]# cd..

bash: cd..: command not found

[root@localhost ~]# cd ~

时间 date

格式: date +%Y_%m_%d_%H:%M:%S

[root@localhost ~]# date

Sat May 14 05:59:19 PDT 2016

[root@localhost ~]# date +%Y_%m_%d_%H:%M:%S

2016_05_14_06:00:19

时间戳 :从开始到现在总秒数

[root@localhost ~]# date +%s

1463231013

[root@localhost ~]# date +%Y:%m:%d -d @1463231013

2016:05:14

删除空目录 rmdir

-p 连上层目录一起删除

[root@localhost ~]# mkdir p

[root@localhost ~]# rmdir p

删除文件 rm

rm -r 删除目录及以下所有文件

rm -i 删除时会询问

rm -f 强制删除

[root@localhost ~]# rm -i c

rm: remove regular empty file `c'?

复制文件或者目录 cp

格式; cp 源文件 目录

cp 源文件 源文件

[root@localhost ~]# cp c c1

[root@localhost ~]# touch b

[root@localhost ~]# cp c b

cp: overwrite `b'?

返回文件名和目录名 dirname basename

格式:basename 文件名

[root@localhost ~]# basename c

c

[root@localhost ~]# dirname c

.

移动文件或目录或者更名 mv

mv -f强制移动

mv -i会询问是否移动

[root@localhost ~]# mv c c2

16.显示文件内容 more

[root@localhost ~]# count=0; while [ $count -lt 100 ];do echo "$count">>file;

> let count++; done

17.查看文件 less

格式:less 文件名

[root@localhost ~]# less file

18.日历  cal

[root@localhost ~]# cal

May 2016

Su Mo Tu We Th Fr Sa

1  2  3  4  5  6  7

8  9 10 11 12 13 14

15 16 17 18 19 20 21

22 23 24 25 26 27 28

29 30 31

19.查看文件头几行  head

[root@localhost ~]# head file

0

1

2

3

4

5

6

7

8

9

20.查看文件类型 file

[root@localhost ~]# file file

file: ASCII text

21.查看文件位置 which

whereis:

[root@localhost ~]# which file

/usr/bin/file

[root@localhost ~]# whereis file

file: /usr/bin/file /usr/share/file /usr/share/man/man1/file.1.gz      /usr/share/man/man1p/file.1p.gz

22.find 寻找特定文件路径

find . -name 文件名

.表示当前目录 /表示根目录

find / -mtime n 按n天以前修改查找文件

find / -atime n 按访问文件时间查找文件

find / -ctime n 按文件创建时间查找

[root@localhost ~]# find . -name file

./file

[root@localhost ~]# find / -name file

/root/file

/usr/share/file

/usr/bin/file

/usr/src/kernels/2.6.32-431.el6.i686/include/config/pnfs/file

/usr/src/kernels/2.6.32-431.el6.i686/include/config/security/file

/usr/src/kernels/2.6.32-431.el6.i686/include/config/file

/selinux/class/file

/selinux/initial_contexts/file

/file

find -print:将匹配的文件输出

[caibei@localhost ~]$ find -print

.

./c

./c/3

./c/.file

./c/2

./c/1

./c/b

./c/pei

./c/pri

./test

find -user username:按username查找

[caibei@localhost ~]$ find -user caibei

.

./c

./test

./.pulse

find -nouser :按没有username查找

[caibei@localhost ~]$ find -nouser caibei

find: paths must precede expression: caibei

Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

find -newer f1 !f2 查找比f1新比f2旧的文件

[caibei@localhost ~]$ find -newer test.c !c

find -newer test.c chown root pri

find: paths must precede expression: chown

Usage: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]

find -type b  按照文件的类型查找

[caibei@localhost ~]$ find -type d

.

./c

./c/pei

./.pulse

./Videos

./.gnote

./.gnote/addins

./.gnome2

./.gnome2/keyrings

./.gnome2/gedit

./.gnome2/panel2.d

./.gnome2/panel2.d/default

./.gnome2/panel2.d/default/launchers

./.gnome2/nautilus-scripts

./.dbus

./.dbus/session-bus

./Templates

./Music

./.config

./.config/gtk-2.0

./.config/gnome-session

./.config/gnome-session/saved-session

./.config/gnome-disk-utility

./.config/gnome-disk-utility/ata-smart-ignore

./.gstreamer-0.10

./.mozilla

./.mozilla/plugins

./.mozilla/extensions

./Pictures

./Documents

./.local

./.local/share

./.local/share/applications

./.local/share/gvfs-metadata

./.local/share/Trash

./.local/share/Trash/expunged

./.local/share/Trash/info

./.local/share/Trash/files

./.gconf

./.gconf/desktop

./.gconf/desktop/gnome

./.gconf/desktop/gnome/accessibility

find -size n 查找文件是n块的文件

[caibei@localhost ~]$ find -size  2

./.pulse/f844858f676102d9b6631da400000039-card-database.tdb

./.xsession-errors

./.config/user-dirs.dirs

./.local/share/gvfs-metadata/home

./.viminfo

./.gconf/apps/gnome-terminal/profiles/Default/%gconf.xml

./.gconf/apps/panel/applets/window_list/prefs/%gconf.xml

./.bash_history

find _depth 使文件在查找子目录前先查找本目录

[caibei@localhost ~]$ find -depth

./c/3

./c/.file

./c/2

./c/1

./c/b

./c/pei

./c/pri

./c

./test

find -follow 遇到符号链接文件,就跟踪链接所指的文件

[caibei@localhost ~]$ find -follow

.

./c

./c/3

./c/.file

./c/2

./c/1

./c/b

./c/pei

./c/pri

./test

find -mount 查找文件的时候不跨越文件系统mount点

[caibei@localhost ~]$ find -mount

.

./c

./c/3

./c/.file

./c/2

./c/1

./c/b

./c/pei

./c/pri

./test

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值