For instance, if there is dir 3:
mkdir 4; cp file 4
The dir could also be called 3 other text. Still no text needs to be in mkdir 4 besides the incremented number. The highest number needs to be detected.
For instance, if there is dir 3:
mkdir 4; cp file 4
The dir could also be called 3 other text. Still no text needs to be in mkdir 4 besides the incremented number. The highest number needs to be detected.
Lets assume you have sequentially numbered directories like: 'dirnameN',
where 'N' is the number.
You can find the highest number (from the parent directory) by,
find . -type d -name dirname\* | sed 's|dirname||' | sort -n | tail -1
So, you use the pattern in your directory names to filter it out (with 'sed') and leave the number.
Then, you sort numerically to find the last number.
After that, you would add one to that and proceed to make your next directory using the same pattern.
Say, something like,
dirnamePattern=dirname
lastDirname=11
newDirname=$((lastDirname+1))
newDirname=${dirnamePattern}${newDirname}
will give you 'dirname12'.
The following should do the thing in one line:
mkdir $(($(find . -type d | sed -e 's/[^0-9]*//g' | sort -n | tail -n 1)+1))
Given the folders:
1 something
3 other text
some 5 thing
2 test
this creates a folder named 6.
If you then want to copy a file named file, just do something like this:
name=$(($(find . -type d | sed -e 's/[^0-9]*//g' | sort -n | tail -n 1)+1)); mkdir $name; cp file $name