MacOS – Listing/Moving certain files

bashmacosterminal

My current path is /Users/UserName/Downloads/Downloaded_Path. In Downloaded_Path Folder i have multiple folders like F1, F2 etc and each folder contain rar part-files from rar to r99. What I want to do is to list all files which are either rar or r* extension type and copy them from those respective folder to a new folder.

Best Answer

It's very easy to do,

The * acts as a wildcard so that we are copying every files that has .r in it ie 133.rar or 123.r99. The cp function more properly looks like this

cp /path/from/*.r* /path/to

Edit: upon re reading the question you will want to add the recursive tag -R

cp -R /path/from/*.r* path/to

More specifically for you

cp -R /Users/UserName/Downloads/Downloaded_Path/*.r* new/path/location

Additionally what you can do to list all these files as well is

ls  /Users/UserName/Downloads/Downloaded_Path/*.r*

ls allows for some tags to give you more information about the files being listed. -a -l -t Or -alt all together. -a shows all files including the files starting with . Or .. -l lists the files in a long format -t lists them in time order (in which I believe is last touched or modified) The following code will explain more about the ls tags if you want to read more about it.

man ls

Another helpful tip is to get out of man within terminal, just press the q button.

Cheers!