I’m wondering if anybody knows how to find a pattern and then move it to a different location.
For example,
I have many files named:
odbc.ini_20110630 odbc.ini_20110639 odbc.ini_20110643 etc...
I want to search the pattern of just odbc.ini and move all of them to a different folder.
I’m not too familiar with how to execute two commands at one time (piping).
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You can use
find . -name "odbc.ini*" -exec mv {} destination ;
This is assuming that your files are in the directory hierarchy starting at current directory ..
Method 2
if the files are all in a single directory and you don’t need any recursion:
shopt -s nullglob mv odbc.ini* /new/directory/
if you need recursion:
find "${dir:-.}" -type f -name 'odbc.ini*' -exec mv {} /new/directory ;
Another approach could be with extglob but i’ll leave that as an exercise for the reader =]
Method 3
If all the files are in the same directory:
mv /path/to/source/odbc.ini* /path/to/destination
If you want to move files in subdirectories as well:
shopt -s globstar # put this line in your ~/.bashrc mv /path/to/source/**/obdc.ini* /path/to/destination
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0