1. 程式人生 > 其它 >LeetCode-006-Z 字形變換

LeetCode-006-Z 字形變換

檔案查詢

# 查詢命令所在位置
which ls

# 根據檔案屬性查詢檔案(find)
	
	共用引數:
		-a : 並且
		-o : 或者
		[root@python test]# find ./ -size -30M -o -size +50M
        ./
        ./txt
        ./txt2


	1、按照檔名稱查詢
	[root@python ~]# find /root/ -name "txt*" -a -size +40M
    /root/txt2
    /root/a/b/c/txt2
    [root@python ~]# find /root/ -name "txt*"  -size +40M
    /root/txt2
    /root/a/b/c/txt2

	2、按照檔案的建立時間來查詢
	
	+7day	: 7天以前建立
	-7day	:7天以內建立
	7day	:正好7天
	
	-ctime : 按照建立時間查詢
	-mtime : 按照修改時間查詢
	-atime : 按照訪問的時間查詢
	
	# 3天以內建立
	[root@python ~]# find /root/ -ctime -3
	# 3天以前建立
	[root@python ~]# find /root/ -ctime +3
	
	3、按照檔案屬性查詢
		[root@python ~]# find /root/ -size +10M -user test
        /root/txt
        [root@python ~]# find /root/ -size +10M -group test
        /root/txt

	4、按照檔案的大小查詢
		find [查詢的路徑] -size [大小]
		find /root/ -size +50M : 查詢大於50M的檔案
		find /root/ -size 20M : 查詢等於20M的檔案
		find /root/ -size -60M : 查詢小於60M的檔案
		
	5、設定查詢最高的目錄層級(目錄層級引數必須放在第一位)
		[root@python ~]# find /root/  -maxdepth 3 -a  -size +40M
        /root/txt2
        [root@python ~]# find /root/  -maxdepth 6 -a  -size +40M
        /root/txt2
        /root/a/b/c/txt2
        
	6、按照檔案型別來查詢
		# 按照目錄查詢
		[root@python ~]# find /root/ -type d
		# 按照普通檔案來查詢
		[root@python ~]# find /root/ -type f
		# 檢視裝置檔案
		[root@python dev]# find /dev/ -type c

	7、按照許可權來查詢
	[root@python test]# ll
    總用量 122880
    -r--r-----. 1 test user1 20971520 6月  16 17:33 txt
    -rw-r--r--. 1 root root  41943040 6月  16 17:33 txt1
    -rwxr-xr-x. 1 root root  62914560 6月  16 17:33 txt2
    [root@python test]# find ./  -perm 440
    ./txt
    [root@python test]# find ./  -perm 644
    ./txt1
    ./txt2

rw-r--r--
6   4  4
所屬使用者  所屬使用者組  其他使用者

[root@python ~]# useradd user1
[root@python ~]# useradd user2
[root@python ~]# useradd user3

r(4)	: 只讀
w(2)	:只寫
x(1)	:執行

chmod : 修改檔案許可權
	chmod 755 [檔案路徑]
chown : 修改所屬使用者及使用者組
	chown 使用者.使用者組 [檔案路徑]

	8、處理查詢結果
		# 直接跟命令
		[root@python test]# find ./  -perm 755 -ls
        202362858    0 drwxr-xr-x   2 root     root           41 6月 16 17:59 ./
        134514204 61440 -rwxr-xr-x   1 root     root     62914560 6月 16 17:33 ./txt2
		
		# exec(推薦)
		# {}:代表前面查詢出來的內容
		find ./ -size +50M -exec cp {} /opt/ \;
		
		# 使用管道
		# xargs是將前面命令執行的結果先用一個{}來儲存,然後用{}取出來處理
		find ./ -size +50M | xargs -I {} cp {} /mnt/