文件目录管理1

1.System Category Structure

ls = list

useradd XXX (home category is /home)

authorized_keys must be under .ssh (stipulated by sshd configuration ----- ls /etc/ssh/sshd_config)

1.1 Catalogue

1.1.1 bin & sbin

command under sbin is basically used by root account and bin is used by normal account (sbin means super bin)

存储于系统的常用命令,sbin下存储的为仅供root用户使用的命令,其他用户不能用

1.1.2 boot

系统启动相关的文件

boot up related files (grub- like singleuser mode)

1.1.3 dev

系统特有的一些设备文件

device files(mouse, keyboard etc..)

1.1.4 etc

system configuration files (Network card setup files: ls /etc/sysconfig/network-scripts/ifcfg-ens33 & ls /etc/ssh/sshd_config)

Excerpted from https://zhidao.baidu.com/question/398779738.html

1.1.5 home

home category of users

1.1.6 lib & lib 64

for dll (Dynamic Link Library)

Excerpted from https://baike.baidu.com/item/%E5%BA%93%E6%96%87%E4%BB%B6/2550595

1.1.7 proc

Excerpted from https://www.cnblogs.com/DswCnblog/p/5780389.html

1.1.8 run

Temp file when system progressing, only exsit before system reboot

1.1.9 sys

core related files

1.1.10 tmp

temp directory

1.1.11 usr

user files

自己编译的一些文件会放在/usr/local

1.1.12 var

Excerpted from https://zhidao.baidu.com/question/398779738.html

/var/log : log files

2. Frequent command

2.1 LS

*inode please refer to https://www.cnblogs.com/itech/archive/2012/05/15/2502284.html

2.2 CD

cd - alternate to previous command

cd move to the home directory of current directory

cd ~ go back to user's home directory

cd .. go back to previous directory

2.3 MV

file move and name change

*如果在同一个目录下那就是改名字,如果目标的文件已经存在就会问是否会覆盖,如果目标是一个目录且目录不存在它就会更该目录名字,如果目标是目录源也是一个存在的目录那它就会放在目标目录里面去

2.4 mkidr/ rmdir and rm

&mkdir -p 级联创建

if directory 1/2 needed to be created simultaneously, try to use -p after mkdir/rmdir, (-pv for visually)

&touch for file creating

touch /tmp/1/2/1.txt

&rm unsed to remove the files,

use -f after rm command and skip the notification and delete directly

notes ! command also can be used, refer to most recent command in history

!$ refer to the last character in most recent command in history

&rmdir only can be used as blank directory removal, so normally we dunt use it, and we use rm instead

&rm -r to remove all directory and files

2.5 CP

把一个文件复制到一个目标文件中,而且目标文件已存在,该目标文件内容将被破坏,此命令中所有参数可以是绝对路径或相对路径通常以。或。。的形式.

eg. cp ../fred/222/1.txt .

cp指定的目录必须是已经存在的,cp无法创建目录

cp aaa/* /bbb :复制目录aaa下所有到/bbb下

拷贝一个目录时,左边目录会放在右边的目录下,不存在是会改名字

cp A B

cp -r if copy a directory

2.6 File related file command.

2.6.1 Cat check file details

to add contents from cat /etc/passwd into anaconda-ks.cfg.1 追加重定向

2.6.2 tac check file details reversely

2.6.3 more check file details by screen (space move forward, CTRL+B move back)

2.6.4 less command more like "more". but can use search under less (N for next page)

example /cdrom ?cdrom search from bottom to up ("n"键会追踪下一个符合搜索选项的词)

shift g and G, set to front row and end row (g定位到行首和行尾)

2.6.5 wc -l check how many rows they have in a file

2.6,6 head check a file with top 10 rows

2.6.7 tail check a file with last 10 rows

tail -n 2 anaconda-ks.cfg.1 check the last 2 rows

tail -f real-time update the latest info

2.7 alias

alias命令可以查看系统中所有的alias

Add new command (fred) into alias: alias fred='ls -lha' / unalias to cxl the comand add-in

如何简化 /root/123/abc 命令

alias fred="/root/123/abc"

ln /root/123/abc /bin/abc

加入环境变量path

2.8 Find 命令*****

其他搜索文件命令: which/ whereis(只有更新后的文件才能找到)/ locate(未安装, yum install -y mlocate-需要每天生成 updatedb手动生成)

Please input text here

文件种类有很多: d, f, l, s, c and b

find / -mtime(modify), -ctime(change) and -atime(access)

mtime 是指更改文件内容,ctime,是指更改权限。 更改文件内容mtime,ctime一定会随之变化

cat 1.txt 访问1.txt内容

state + file 查看文件3个time

文件的 Access time,atime 是在读取文件或者执行文件时更改的。

文件的 Modified time,mtime 是在写入文件时随文件内容的更改而更改的。

文件的 Create time,ctime 是在写入文件、更改所有者、权限或链接设置时随 Inode 的内容更改而更改的。

eg. 如果更改权限则对应Ctime会改变,如果增加内容,则ctime/mtime会改变

+1/_1 表示文件更改时间一天以外/以内,同时也可以尝试按分钟搜索(同理+/-10k 也是按文件大小搜索)

通过inode搜索硬链接文件

搜索某文件目录并list 出来(针对于某种需求就是要某文件)

Fine总结

(1)Find工具-name参数案列:

find /data/ -name "*.txt" #查找/data/目录以.txt结尾的文件;

find /data/ -name "[A-Z]*" #查找/data/目录以大写字母开头的文件;

find /data/ -name "test*" #查找/data/目录以test开头的文件;

(2)Find工具-type参数案列:

find /data/ -type d #查找/data/目录下的文件夹;

find /data/ ! -type d #查找/data/目录下的非文件夹;

find /data/ -type l #查找/data/目录下的链接文件。

find /data/ -type d|xargs chmod 755 -R #查目录类型并将权限设置为755;

find /data/ -type f|xargs chmod 644 -R #查文件类型并将权限设置为644;

(3)Find工具-size参数案列:

find /data/ -size +1M #查文件大小大于1Mb的文件;

find /data/ -size 10M #查文件大小为10M的文件;

find /data/ -size -1M #查文件大小小于1Mb的文件;

(4)Find工具-perm参数案列:

find /data/ -perm 755 #查找/data/目录权限为755的文件或者目录;

find /data/ -perm -007 #与-perm 777相同,表示所有权限;

find /data/ -perm +644 #文件权限在644以上;

(5)Find工具-mtime参数案列:

atime,access time 文件被读取或者执行的时间;

ctime,change time 文件状态改变时间;

mtime,modify time 文件内容被修改的时间;

find /data/ -mtime +30 -name "*.log" #查找30天以前的log文件;

find /data/ -mtime +30 -name "*.log" #查找30天以前的log文件;

find /data/ -mtime 30 -name "*.txt"#查找第30天的log文件;

find /data/ -mmin +30-name "*.log" #查找30分钟以前修改的log文件;

find /data/ -

-30 -name "*.txt" #查找30分钟以内被访问的log文件;

find /data/ -cmin 30 -name "*.txt"#查找第30分钟改变的log文件。

(6)Find工具参数综合案列:

#查找/data目录以.log结尾,文件大于10k的文件,同时cp到/tmp目录;

find /data/ -name "*.log" –type f -size +10k -exec cp {} /tmp/ /;

#查找/data目录以.txt结尾,文件大于10k的文件,权限为644并删除该文件;

find /data/ -name "*.log" –type f -size +10k -m perm 644 -exec rm –rf {} /;

#查找/data目录以.log结尾,30天以前的文件,大小大于10M并移动到/tmp目录;

find /data/ -name "*.log" –type f -mtime +30 –size +10M -exec mv {} /tmp/ /;

3. File type

capital letter

"d" for directory

"-" for normal file (can be checked by "cat" command directly)

"c" for character device (yellow color), mouse keyboard, tty file

Excerpted from https://baike.baidu.com/item/%E5%AD%97%E7%AC%A6%E8%AE%BE%E5%A4%87/6637035

"b" for block device (disk)

“s” for socket file. communication, data transmission

"l" for symbolic link. 符号链接 又称软连接,包含了另一个文件的绝对路径或者相对路径

Excerpted from https://baike.baidu.com/item/%E5%A5%97%E6%8E%A5%E5%AD%97/9637606?fr=aladdin

4. Path

Absolute Path & Relative Path

Excerpted from https://baike.baidu.com/item

简单理解绝对路径就是从根开始的就是绝对路径,相对路径就是相对当前位置的路径

if your command is under one of below directory, we dunt need to input absolute Path

How to add /tmp/ into PATH? (temprorary)

PATH=/usr/local/sbin:/usr/local/bin:/us/sbin:/usr?bin:/root/bin:/(tmp/)通过重新定义PATH=来临时更改环境变量

How to add /tmp/ into PATH? (permenant)

5. Authority

5.1 File & Directory Auth chmod

r-read w-write x-executable

eg.

前三位为所有者权限user:可读写不可执行

中间三位为所属组权限group:仅可读

后三位为其他用户权限other:仅可读

r=4 w=2 x=1, rw-r--r-- =644

change auth for 2.txt

chmod -R 700 fred revise all sub directories under fred

chmod a/g/o/u+x fred/ 会把fred目录的所有/所有者/所属组/其他用户权限赋予可执行

5.2 Chown -change owner

chown and chgrp

chown -R 选项级联的更改所选目录以及子目录/文件的所有者所属组

change owener and group

chwon :user1 XXX 命令可以直接用来修改组,类似于命令 chgrp user1 xxx

5.3 Umask

新创建的文件权限为644,而新创建的目录权限为755

所有的目录都会有x(可执行)权限,因为只有可执行才可以浏览,这里与文件不一样

umask 022 by default , directory = 777 file =666

Excerpted from https://baike.baidu.com/item/umask/6048811

猜你喜欢

转载自blog.csdn.net/nongfuchui/article/details/83155074