Reorganize files on the server
Useful commands to use when reorganizing large datasets to be prepped to be uploaded using datapack
This is run in the terminal
Basics
Moving around
Go up one directory using ..
Get the contents of the current directory
Get the directory structure for this folder
-d
flag shows only the directories
Rename file based on file path
For example you have some files organized like this:
../../visitor/Lastname
└── RU_ALN_TR1_FL007R
│ └── rgb_images
| └──image.png
└── RU_ALN_TR1_FL008B
└── micasense_preflight_calibration_images
└──image.png
We want to rename the files.
- Find all the files with the same file name
- First extract the file name in parts (
(.*)/(.*)/(.*)/(.*)
) by using the./
as a separator.
- Each part is represented by
$#
. If you want the last part of the file name:$4
. Rearrange this section as needed:$2/$3/$2-$3-$4
- Set the flag as
-n
while testing to see the result of the renaming first before committing to it using-v
rename -n -- 's|(.*)/(.*)/(.*)/(.*)$|$2/$3/$2-$3-$4|'
rename -v -- 's|(.*)/(.*)/(.*)/(.*)$|$2/$3/$2-$3-$4|'
- Putting it together by taking the results from find and renaming those files
|
the pipe is like the%>%
in R