天天看點

linux怎麼複制檔案到etc,/etc下找到1兆以上檔案并且将其複制到/tmp下的4種方法-摘自李導...

在/etc下面的找大于1M的檔案,複制到/tmp下面。

mkdir /tmp/dir{a..d}      #/tmp/a /tmp/b /tmp/c /tmp/d

第一步:找到這些檔案

find /etc/ -type f -size +1M

/etc/selinux/targeted/modules/active/policy.kern

/etc/selinux/targeted/policy/policy.24

第二步:把找到的檔案複制到/tmp 下面

方法一 find+|xargs

[[email protected] logs]# find /etc/ -type f -size +1M|xargs cp /tmp/

cp: target `/etc/selinux/targeted/policy/policy.24' is not a directory

[[email protected] logs]# find /etc/ -type f -size +1M|xargs

/etc/selinux/targeted/modules/active/policy.kern /etc/selinux/targeted/policy/policy.24

[[email protected] logs]# #cp /tmp /etc/selinux/targeted/modules/active/policy.kern /etc/selinux/targeted/policy/policy.24

[[email protected] logs]# cp /tmp /etc/selinux/targeted/modules/active/policy.kern /etc/selinux/targeted/policy/policy.24

cp: target `/etc/selinux/targeted/policy/policy.24' is not a directory

[[email protected] logs]# #cp 蘋果 蘋果 蘋果  筐(目錄)

[[email protected] logs]# find /etc/ -type f -size +1M|xargs cp {} /tmp/

cp: target `/etc/selinux/targeted/policy/policy.24' is not a directory

[[email protected] logs]# find /etc/ -type f -size +1M|xargs -i cp {} /tmp/dir

dira/ dirb/ dirc/ dird/

[[email protected] logs]# find /etc/ -type f -size +1M|xargs -i cp {} /tmp/dira/

[[email protected] logs]# ll /tmp/dira/

total 16456

-rw-r--r-- 1 root root 8424080 Nov 10 18:43 policy.24

-rw-r--r-- 1 root root 8424080 Nov 10 18:43 policy.kern

方法二:

[[email protected] logs]# #cp find指令的結果放在這裡  筐(目錄)

[[email protected] logs]# cp $(find /etc/ -type f -size +1M) /tmp/dirb/

[[email protected] logs]# ls -l /tmp/dirb/

total 16456

-rw-r--r-- 1 root root 8424080 Nov 10 18:44 policy.24

-rw-r--r-- 1 root root 8424080 Nov 10 18:44 policy.kern

方法三:

[[email protected] logs]# find /etc/ -type f -size +1M -exec cp {} /tmp/dirc/ \;

[[email protected] logs]# date

Thu Nov 10 18:46:34 CST 2016

[[email protected] logs]# ll /tmp/dirc

total 16456

-rw-r--r-- 1 root root 8424080 Nov 10 18:46 policy.24

-rw-r--r-- 1 root root 8424080 Nov 10 18:46 policy.kern

方法四:

#cp 蘋果 蘋果 蘋果  筐(目錄)

#cp -t  筐(目錄)  蘋果 蘋果 蘋果

[[email protected] logs]# find /etc/ -type f -size +1M|xargs cp -t /tmp/dird/

[[email protected] logs]# date

Thu Nov 10 18:49:27 CST 2016

[[email protected] logs]# ll /tmp/dird

total 16456

-rw-r--r-- 1 root root 8424080 Nov 10 18:49 policy.24

-rw-r--r-- 1 root root 8424080 Nov 10 18:49 policy.kern

###獲得1M檔案

[[email protected] logs]# cat /etc/services /etc/services >/tmp/1m.txt

[[email protected] logs]# ll -h /tmp/1m.txt

-rw-r--r-- 1 root root 1.3M Nov 10 18:51 /tmp/1m.txt