Linux - SoftwareThis forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I want to have something that can look through a tree of folders on my computer, find all the files that contain a particular text string in the file name, and then move these files to a particular folder.
So something searches through a folder called "business" for example (including all the sub folders) for all the files that include both the strings "receipt" and "2017", and then moves all the found files to another folder called "receipts2017" which is a sub-folder of the folder "cashflow", creating a new sub-folder if it does not already exist.
I would like to supply a text file that lists all the strings I want found, so that a whole list of strings can be processed, rather than doing it one by one manually.
What would be most suited to doing this please? Unless there is a program specifically designed to do this, I expect it requires using some sort of language or script.
But which language or script would be easiest for a beginner to use please?
If you are willing and able to learn a language you might take a look at PERL. Bash can do it, but I find perl's syntax makes more sense and this would not be difficult with its powerful use of regular expressions. I suppose most any language would be possible, but if you are looking at learning one, I have found PERL to be very useful.
I second both perl and shell scripting, but figure this can be done in the shell which is less advanced. grep has several options that might be relevant, such as -r and -l. The output can be fed into xargs with a pipe and then that can launch mv, maybe with the -t option.
Give things a try and say where you are running into barriers.
Edit: there are quite a few different approaches even with just the shell.
Last edited by Turbocapitalist; 11-16-2017 at 08:43 AM.
Thanks. "....most any language would be possible". Could the "R" statistical language do this? I am trying to learn R, and an exercise like this may help that.
If it cannot be done with R, could it be done with Python? But I would prefer R.
Sure, Python should be fine here. If you have large no.of files in directory check out scandir https://github.com/benhoyt/scandir
instead of os.walkdir() and use regex on files to proceed further.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.