List file name patterns and residing directories - osx-mavericks

Using Mac OS X Mavericks, how do I find file name patterns residing in different, unknown, directories (ie: would be equivalent of Windows/DOS command: dir /b \x*.y*) ?

Using find(1):
find /path/to/directory -name \*.y\* -print

Related

Unrar all files from a folder using Windows terminal

I am looking for a command in the windows terminal that allows me to unrar all the files from a folder. Precisely I want to replicate this bash command on windows
find . -name "*.rar" -exec unrar x -o+ {} \;
thank u
I would prefer RS Finance's answer: a power shell provides an easy and clean solution. However, if that's not an option, you may achieve the same with command prompt like this (first cd to the correct directory),
for %i in (*.rar) do "C:\Program Files\7-Zip\7z.exe" e "%i"
I use 7z as my zip program. You just have to replace the path to whatever you use. If you have the path stored in you environment path, "7z.exe" without the absolute path may be enough.
Note that,
e is an argument specifically for 7zip, meaning extract.
if you intend to do this in a batch script (file), you'll need double "%"-signs. See this one: Iterate all files in a directory using a 'for' loop
Well Powershell would be a great option, something like this should do the trick:
Get-ChildItem -File *.rar | Foreach {unrar x -o+ $_.fullname}
It's better to use UnRAR.exe supplied with WinRAR Trial. This console utility is freeware, and definitely supports all RAR format versions
e.g.
for %i in (*.rar) do "C:\Program Files (x86)\WinRAR\UnRAR.exe" x "%i"
to extract all archives contents with relative paths or
for %i in (*.rar) do "C:\Program Files (x86)\WinRAR\UnRAR.exe" e "%i"
to extract everything to the same folder

Python - Resolve to an absolute path relative to a script file

I am using a find statement to execute python scripts which are in sub folders of all sub folders of the current directory
The find statement is find . -name \process.py -type f -exec python3 {} \;
The problem I am encountering is that the script is using relative paths e.g ..\data for retrieving other resources. These relative paths are resolved as required when the script is executed individually by running it from its directory but when running the script from a parent directory two levels up using the find command the path resolves relative to that parent directory causing errors
You can use -execdir option of the find command:
Having the following folder structure in /tmp:
/test
/test/subdir1
/test/subdir1/subdir2
/test/subdir1/subdir2/subdir3
and a r.py file in each folder:
# r.py
import os
dirpath = os.path.dirname(os.path.realpath(__file__))
print(dirpath)
You have the output:
/tmp/test
/tmp/test/subdir1
/tmp/test/subdir1/subdir2
/tmp/test/subdir1/subdir2/subdir3
If you need to do this in python I suggest looking at this answer:
How to get an absolute file path in Python
It is always better to find an absolute path, If using bash:
readlink -f filename

Script to find files in subdirectories

I need a script that will find and get me all files in all subdirectories (and leave them in the folder structure as they are now). I know how to find and print that files:
find . -name "something.extension"
The point is, in those directories are lots files that was used before, but I don't want to get those, so the script should only find me files that matches some kind of path pattern which is:
xxx/trunk/xxx/src/main/resources
xxx is different everytime, and after resources there are still some folders that directories are different based on xxx.
Every top xxx folder contains folder named 'tags' (the same level as trunk) that stores previous releases of module (and every release has files that name I am looking for, but I don't want outdated files).
So I want to find all that files in subdirectories of that path pattern that I specified and copy to new location but leave folder structure as it is right now.
I am using Windows and cygwin.
Update
I combined answer commands that 'that other guy' posted below, and it works. Just to be clear I have something like this:
find */trunk/*/src/main/resources -name "something.extension" -exec mkdir -p /absolute/target/path/{} \; -exec cp {} /absolute/target/path/{} \;
Thanks.
Instead of searching under the entire current directory (.), just search under the directories you care about:
find */trunk/*/src/main/resources -name "something.extension"

mac osx copy command for copying only files with a given subname?

I want to copy (and overwrite) files and folders from a directory hierarch, only if they have a common string in name like 'fabrik'.
Example directory: com_fabrik, example file: fabriklist.php
Which terminal command should I use to execute this copy?
Use find
find /your/directory -name="*.php" -exec cp -R {} ../otherfolder \;

copy files across directories using terminal in mac

How to copy all files with an specific extension .SAV from one directory (including all subdirectories within that directory) to another one? I am using the terminal from mac. I have tried
/Users/tournillon/my_directory/research_projects/dissertation_related/inequality
Antonio-P-Tournillon-Ramoss-iMac:inequality tournillon$ ls
Brazil dhs_dados imr201101app.pdf
GHME_Education_final.pptx dhs_sav_files
Antonio-P-Tournillon-Ramoss-iMac:inequality tournillon$ dhs_dados /*.SAV/ dhs_sav_files/
I would assume this is a trivial task but I just can't get the syntax right.
Many thanks,
Antonio Pedro.
find /source/directory -iname \*.sav -exec cp {} /destination/directory/ \;
If you mean a UNIX copy,
cp -R <dirA>/*.sav <dirB>/
I'm not sure what dhs_dados is in your question..
Why not just use cp *.SAV directory

Resources