JIYIK CN >

Current Location:Home > Learning > OPERATING SYSTEM >

Linux application - find files to copy [case]

Author:JIYIK Last Updated:2025/04/08 Views:

This article shares a Linux application case with you. The requirements are as follows:

/aContents under the directory

/a/login1.txt
/a/login2.txt
/a/login3.txt
/a/login4.txt
/a/b/login5.txt
/a/b/login6.txt

We find all the file names starting with login under the /a directory and copy them to the /login directory.

This problem can be solved well by using the find command, which can be used in two ways.

First, use the -exec option of the find command to execute the corresponding command

$ find /a –name login* -exec cp {} /b \;

{}Indicates the content found by find

-execIt is the beginning of the extra action of the find command; ; indicates the end of the extra action. The part between -exec and ; is the command executed by the extra action.

Second, using pipelines | and xargscommands

$ find /a –name login* | xargs cp –t /b

xargs reads the result of find as the input data of cp. It should be noted that the cp command must be added with the -t option. Because the directory followed by the -t option is the target directory. If -t is not added, -b will be considered as the source directory, and the file read by xargs becomes the target directory. This will report an error.

The above two methods can solve our needs. I hope this article will be helpful to you.

For reprinting, please send an email to 1244347461@qq.com for approval. After obtaining the author's consent, kindly include the source as a link.

Article URL:

Related Articles

Finding the installed version of Pandas

Publish Date:2025/04/12 Views:190 Category:Python

Pandas is one of the commonly used Python libraries for data analysis, and Pandas versions need to be updated regularly. Therefore, other Pandas requirements are incompatible. Let's look at ways to determine the Pandas version and dependenc

Using CASE in PostgreSQL

Publish Date:2025/04/11 Views:124 Category:PostgreSQL

This article shows how to use the statement in PostgreSQL CASE . CASE How to use the statement in PostgreSQL case Statements are similar to those in general-purpose programming languages if-else . But in SQL, if you want to write IF-ELSE ,

Restart PostgreSQL in Ubuntu 18.04

Publish Date:2025/04/09 Views:72 Category:PostgreSQL

This short article shows how to restart PostgreSQL in Ubuntu. Restart PostgreSQL Server in Ubuntu You can restart Postgres server in Ubuntu using the following command. Order: sudo service postgres restart Sometimes the above command does n

Find the disk size of a PostgreSQL table and its indexes

Publish Date:2025/04/09 Views:105 Category:PostgreSQL

This article will discuss how to find the disk size of a PostgreSQL table and its indexes. Find the disk size of PostgreSQL tables and databases using PSQL You can use \l+ to view the database size and use to \d+ show table size. But before

Finding Duplicate Records in a MySQL Table

Publish Date:2025/04/09 Views:88 Category:MySQL

This tutorial discusses how to check for duplicates in a MySQL table and retrieve the number of duplicates using the SELECT DISTINCT and statements, respectively. SELECT COUNT SELECT DISTINCT Check for duplicates in a MySQL table using The

Find the last inserted ID from a table in MySQL

Publish Date:2025/04/09 Views:133 Category:MySQL

There are many articles about finding the last inserted ID of a table in MySQL. However, it is hard to find any tutorials about finding the last inserted ID using two tables. In this article, we will try to solve this special case, and of c

Issues to note when installing Apache on Linux

Publish Date:2025/04/08 Views:78 Category:OPERATING SYSTEM

As the most commonly used web server, Apache can be used in most computer operating systems. As a free and open source Unix-like operating system, Linux and Apache are a golden pair. This article will introduce the installation and use of A

How to decompress x.tar.xz format files under Linux

Publish Date:2025/04/08 Views:186 Category:OPERATING SYSTEM

A lot of software found today is in the tar.xz format, which is a lossless data compression file format that uses the LZMA compression algorithm. Like gzip and bzip2, it supports multiple file compression, but the convention is not to compr

Summary of vim common commands

Publish Date:2025/04/08 Views:115 Category:OPERATING SYSTEM

In Linux, the best editor should be vim. However, the complex commands behind vim's powerful functions also make us daunted. Of course, these commands do not need to be memorized by rote. As long as you practice using vim more, you can reme

Scan to Read All Tech Tutorials

Social Media
  • https://www.github.com/onmpw
  • qq:1244347461

Recommended

Tags

Scan the Code
Easier Access Tutorial