Exclude certain files by mv

Source: Internet
Author: User
For example, if you want to move all files in the current directory to a subdirectory, you must first create the directory mkdirmyfolder and then use the mv to move all the files. Wait. I don't want to move myfolder to myfolder. (in fact, this doesn't happen. linux will prompt an error music video... for example, if you want to move all files in the current directory to a subdirectory, you must first create the directory mkdir myfolder and then use mv to move all files. Wait. I don't want to move myfolder to myfolder. (in fact, no. in linux, an error mv is prompted: The Directory "myfolder" cannot be moved to its subdirectory ". /myfolder ). But what about rm? I want to delete files and directories other than myfolder under this directory. What's the trick? First, find-maxdepth 1-not-name myfolder-not-name.-exec rm-rf {}\; you can also write it as find-maxdepth 1 \! -Name myfolder \! -Name.-exec rm-rf {}\; see \! It is equivalent to the second action of-not find-not-regex '\. /myfolder. * '-not-regex '\. '-exec rm-rf {}\; you need to know a little bit about the regular expression.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.