LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This 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


Reply
  Search this Thread
Old 11-16-2017, 07:48 AM   #1
grumpyskeptic
Member
 
Registered: Apr 2016
Posts: 472

Rep: Reputation: Disabled
Find and move particular files automatically


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?

I am using Linux Mint 17.3.

Thanks
 
Old 11-16-2017, 08:02 AM   #2
TenTenths
Senior Member
 
Registered: Aug 2011
Location: Dublin
Distribution: Centos 5 / 6 / 7
Posts: 3,483

Rep: Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556Reputation: 1556
I'd use bash scripting http://tldp.org/LDP/abs/html/index.html

Your other friends are likely to be find and mkdir -p
 
Old 11-16-2017, 08:16 AM   #3
agillator
Member
 
Registered: Aug 2016
Distribution: Mint 19.1
Posts: 419

Rep: Reputation: Disabled
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.
 
Old 11-16-2017, 08:38 AM   #4
Turbocapitalist
LQ Guru
 
Registered: Apr 2005
Distribution: Linux Mint, Devuan, OpenBSD
Posts: 7,337
Blog Entries: 3

Rep: Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732Reputation: 3732
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.
 
Old 11-16-2017, 09:16 AM   #5
grumpyskeptic
Member
 
Registered: Apr 2016
Posts: 472

Original Poster
Rep: Reputation: Disabled
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.
 
Old 11-21-2017, 07:22 AM   #6
giis
Member
 
Registered: Nov 2013
Location: Third Rock from Moon
Distribution: RPM/DEB based and LFS
Posts: 73

Rep: Reputation: Disabled
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Script to create folders automatically then move files there- scripted solution - Ubuntu seanbw Programming 9 07-02-2016 01:35 PM
find and move files AndrewNZ Linux - Newbie 4 06-23-2014 08:29 PM
find files but move the parent directory instead? Springs Linux - General 4 12-21-2012 11:27 AM
[SOLVED] How to find and move files to a dir azstyx Linux - Newbie 5 09-29-2012 02:54 PM
How to move files automatically to NFS? vwhk Linux - General 2 09-19-2002 05:28 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 12:49 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration