Linux之文件命令

复制单个文件至某个文件夹

cp /home/demo/apache-tomcat-7.0.81.tar.gz /home/demo/folder

复制一个文件夹下的所有文件至另一个文件夹
假设原文件夹为src,目标文件夹为target,复制src文件夹下的所有文件至target文件夹

a. 如果target目录不存在, 则 cp -r src target
b. 如果target目录存在, 则 cp -r src/. target
c. 如果target目录存在, 执行 cp -r src target;则会将A文件夹一并复制到target文件夹

移动文件夹

mv /home/demo/jdk1.7.0_80 /home/demo/downloads

文件重命名
文件名就由 file_2 修改成了 file_1

mv /home/demo/file_2 ./file_1

清空文件
-s 参数用来设定文件的大小,清空文件,就设定为0

truncate -s 0 test.txt

统计文件夹、文件数量命令

查看当前目录下的文件数量(不包含子目录中的文件)

ls -l|grep "^-"| wc -l 

查看当前目录下的文件数量(包含子目录中的文件) 注意:R(得大写),代表子目录

ls -lR|grep "^-"| wc -l

查看当前目录下的文件夹目录个数(不包含子目录中的目录),同上述理,如果需要查看子目录的,加上R

ls -l|grep "^d"| wc -l

查询当前路径下的指定前缀名的目录下的所有文件数量
例如:统计所有以“20161124”开头的目录下的全部文件数量

ls -lR 20161124*/|grep "^-"| wc -l

对每个命令参数做一下说明备注:

ls -l

该命令表示以长列表输出指定目录下的信息(未指定则表示当前目录),R代表子目录中的“文件”,这个“文件”指的是目录、链接、设备文件等的总称

grep "^d"表示目录,"^-"表示文件
wc -l

表示统计输出信息的行数,因为经过前面的过滤已经只剩下普通文件,一个目录或文件对应一行,所以统计的信息的行数也就是目录或文件的个数

原文链接:,转发请注明来源!

发表评论

  • 14 Responses to “Linux之文件命令”
    • cheap cialis canada jckzdu

      highest rated canadian pharmacies <a href="http://edpharmacystore.com/">get more</a> us pharmacy cialis
      <a href=http://edpharmacystore.com/>special info</a>

      回复
    • CharlesHob

      tinder login, tinder app
      <a href=http://tinderdatingsiteus.com/?>tinder website </a>

      回复
    • best viagra vspydq

      viagra online canadian pharmacy <a href="http://edpharmacystore.com/">recommended site</a> internet pharmacy
      <a href=http://edpharmacystore.com/>prev</a>

      回复
    • cheap viagra without prescription znutgx

      us pharmacy cialis <a href=http://www.canada1drugstore.com/tadalafil/>cialis from usa pharmacy</a> viagra for men
      <a href="http://www.canada1drugstore.com/tadalafil/">low price viagra</a> internet pharmacy

      回复
    • CharlesHob

      tinder online , tinder dating app
      <a href=http://tinderdatingsiteus.com/?>tider </a>

      回复
    • Charlesedity

      generic cialis canada <a href="http://www.askpavel.co.il/qa/index.php?qa=user&qa_1=horowitzduus6">www.walmart.com</a> cialis-canadian pharmacy <a href=http://gitlab.asap.um.maine.edu/stuartkolding6>viagra and women</a> ordering viagra
      cialis from.canada <a href="https://youradblaster.com/member.php?action=profile&uid=23371">cialis for daily use</a> brand viagra online canada pharmacy <a href=https://unsplash.com/@koldingbeasley8>online generic viagra</a> generic viagra
      cialis mexico pharmacy <a href="http://answers.codelair.com/index.php?qa=user&qa_1=stuartabdi1">canada online drugs</a> buy viagra canada <a href=http://board.rogue-war.de/member.php?action=profile&uid=49441>generic viagra reviews</a> canada drug stores
      cialis generic to canada

      回复
    • new free dating site

      free dating sites

      回复
    • Tinder dating site

      tinder dating app , tinder date
      <a href=http://tinderdatingsiteus.com/?>tinder online </a>

      回复
    • viagra sample azrbpo

      discount meds <a href="http://www.1torontoclassifieds.com/index.php/author/abernathy06timmermann/">do you need a prescription for cialis</a> best price for viagra <a href=http://xn--80acvxh8am.net/index.php?action=profile;area=forumprofile>mail order prescriptions from canada</a> canada-cialis
      price of cialis canada <a href="https://zimmermanmartinsen4.bravejournal.net/post/2021/01/28/Leading-Tips-To-Solve-Any-Hairy-Situation">how to get viagra without a prescription</a> viagra canadian <a href=https://whatsondigest.com/members/gissel01hendrix/activity/169656/>real viagra</a> viagra canada
      tadalafil from canada <a href="http://www.feedbooks.com/user/6984902/profile">best price on cialis prescription</a> canada drugs <a href=http://www.kab3.com/home.php?mod=space&uid=479650>natural alternatives to viagra</a> generic viagra india
      non prescription viagra

      回复
    • viagra brand sale iqwiav

      natural alternative to viagra <a href=http://www.canada1drugstore.com/tadalafil/>order viagra online</a> canada pharmacy for viagra
      <a href="http://www.canada1drugstore.com/tadalafil/">low cost cialis</a> online drug

      回复
    • Tinder dating site

      tinder dating app , browse tinder for free

      回复
    • Stephenpeaky

      how much viagra should i take the first time? <a href=" http://sild100fast.com/# ">buy generic viagra online</a> buy generic viagra

      回复
    • cialis 5mg

      Buy Accutane Generic Ovekly https://cialisse.com/ - buy cialis online reviews DICIVE Priligy Yahoo Answers Oppone <a href=https://cialisse.com/#>order cialis</a> immazy Pepfiz

      回复
    • buy online cialis

      Doxycycline 10mg Ovekly https://biracialism.com/ - Cialis DICIVE Amoxil 20mg Duree Oppone <a href=https://biracialism.com/#>Cialis</a> immazy cialis fin de semana

      回复