天天看点

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