Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mftsf.sh
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Richard Torenvliet
mftsf.sh
Commits
ce1120e6
Commit
ce1120e6
authored
Sep 07, 2017
by
Richard Torenvliet
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update help and add a readme
parent
991a6462
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
63 additions
and
9 deletions
+63
-9
README.md
README.md
+49
-0
mftsf.sh
mftsf.sh
+14
-9
No files found.
README.md
0 → 100644
View file @
ce1120e6
## Move Files to Separate Folders:
The motivation for this small bash script is that when you want to make a big
backup of files, let's say to google drive, dropbox, icloud etc., it can simply
take forever before your files are uploaded. In my case, I wanted to backup
32000 separate files (photo's) from an external drive directly to the cloud.
This can take a couple of days to be uploaded, so the idea is to create smaller
batches so that you can also turn your computer off and continue later.
So, I wanted to move / copy these separate 32000 files into separate folders of
size
`N`
.
## Usage
Make part directories of size 10 (default is 10 per folder)
> 10 files
~~~
shell
./mftsf.sh
-i
inputDir
-o
outputDir
~~~
Make part directories of size 500 (default is 10 per folder)
> 500 files
~~~
shell
./mftsf.sh
-i
inputDir
-o
outputDir
-n
500
~~~
An example of how this looks like:
~~~
shell
├── folder
(
here all your files are located
for
example
)
.
└── output
├── part_0
├── part_1000
├── part_1500
└── part_500
~~~
> Skip the first 100 and then make folders of size 100
~~~
shell
./mftsf.sh
-i
inputDir
-o
outputDir
-s
100
-n
100
~~~
## Disclaimer
I used this myself to make it work for my purpose, I'm not guaranteeing
anything for anyone else with respect to the result. I deliberately use the
`cp`
command instead of the
`mv`
because I don't want to remove files. With the
skip command you can easily start off.
mftsf.sh
View file @
ce1120e6
#!/bin/bash
#!/bin/bash
N
=
50
0
N
=
1
0
#Set Script Name variable
#Set Script Name variable
SCRIPT
=
`
basename
${
BASH_SOURCE
[0]
}
`
SCRIPT
=
`
basename
${
BASH_SOURCE
[0]
}
`
function
HELP
{
function
HELP
{
echo
-e
\\
n
"Help documentation for
${
SCRIPT
}
."
\\
n
echo
-e
\\
n
"Help documentation for
${
SCRIPT
}
."
\\
n
echo
-e
"Basic usage:
$SCRIPT
gradebook.zip
"
\\
n
echo
-e
"Basic usage:
$SCRIPT
-o <inputDir> <outputDir>
"
\\
n
echo
"Command line switches are optional. The following switches are
echo
"Command line switches are optional. The following switches are
recognized."
recognized."
echo
"-d --Set output directory.
${
BOLD
}
$OUTPUT_DIR
${
NORM
}
."
echo
"-i - Set input directory."
echo
-e
"-h --Displays this help message. No further functions
echo
"-o - Set output directory (here all part directories will be made.)"
are performed."
\\
n
echo
"-n - Set the size of all the part directories (how many files are
\
going to be put in the new directory)"
echo
"-s - How many files to skip until we start making directories and
\
moving files"
echo
-e
"-h - Displays this help message. No further functions are performed."
\\
n
echo
-e
"Example:
${
BOLD
}
$SCRIPT
-d assignment1
echo
-e
"Example:
${
BOLD
}
$SCRIPT
-d assignment1
gradebook.zip
${
NORM
}
"
\\
n
gradebook.zip
${
NORM
}
"
\\
n
exit
1
exit
1
...
@@ -30,12 +34,12 @@ skip=0
...
@@ -30,12 +34,12 @@ skip=0
while
getopts
:i:o:n:s:h FLAG
;
do
while
getopts
:i:o:n:s:h FLAG
;
do
case
$FLAG
in
case
$FLAG
in
s
)
skip
=
$OPTARG
;;
i
)
i
)
findDir
=
$OPTARG
findDir
=
$OPTARG
;;
;;
s
)
skip
=
$OPTARG
;;
o
)
o
)
outputDir
=
$OPTARG
outputDir
=
$OPTARG
;;
;;
...
@@ -67,9 +71,10 @@ fi
...
@@ -67,9 +71,10 @@ fi
echo
finddir
$findDir
echo
finddir
$findDir
echo
outputDir
$outputDir
echo
outputDir
$outputDir
# shift ops, all optional args are now removed $1 will have to be the filename
# shift ops, all optional args are now removed $1 will have to be the filename
shift
$((
OPTIND-1
))
shift
$((
OPTIND-1
))
#
echo
"Creating folder '
$outputDir
' .. "
echo
"Creating folder '
$outputDir
' .. "
mkdir
-p
$outputDir
mkdir
-p
$outputDir
#
#
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment