mvcommon

package module
v1.0.8 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 6, 2026 License: GPL-3.0 Imports: 7 Imported by: 0

README

mvcommon

mvcommon tidies directories by detecting a shared prefix in file names and automatically moving those files into a folder named after that prefix. It exists so you don't need to keep writing throwaway scripts or manually sort files one by one.

Installation

Go Install

If you have Go installed, you can install mvcommon directly:

go install github.com/arran4/mvcommon/cmd/mvcommon@latest
Build from Source
git clone https://github.com/arran4/mvcommon.git
cd mvcommon
go build ./cmd/mvcommon

Usage

mvcommon [flags] <file1> <file2> ...
Flags
  • -stopword: Stop word to stop common prefix detection. Can be specified multiple times. Defaults: -, ] , [.
  • -trim: Characters to trim from the start/end of the prefix. Default: -_ ..
  • -min: Minimum size of common segment. Default: 3.
  • -dry-run: Show what would change without modifying files.
  • -interactive: Enable interactive mode for file selection.

Features

  • Automatically detects common filename prefixes
  • Optionally remove stop words and trimming characters
  • -interactive mode to confirm operations
  • -dry-run shows what would change without modifying files

Why use mvcommon?

mvcommon shines when you regularly download or create files that share a common prefix. Instead of manually creating folders and dragging files around, a single command sorts everything for you. Typical scenarios include:

  • Grouping invoices or reports that start with the same project code
  • Collecting export files that all begin with a date or build number
  • Tidying up camera downloads so your holiday photos end up in their own directory

By automating these chores, mvcommon keeps folders organised and saves you the tedious clicks of moving files individually.

Examples

$ touch 2024-02-34 2024-04-02 2024-04-03
$ ls -lh
total 2.4M
-rw-r--r-- 1 arran arran    0 Dec  9 10:35 2024-02-34
-rw-r--r-- 1 arran arran    0 Dec  9 10:35 2024-04-02
-rw-r--r-- 1 arran arran    0 Dec  9 10:35 2024-04-03
-rwxr-xr-x 1 arran arran 2.3M Dec  9 10:34 mvcommon
$ ./mvcommon -stopword=- 20* 
Creating folder: 2024
Moved 2024-02-34 -> 2024/2024-02-34
Moved 2024-04-02 -> 2024/2024-04-02
Moved 2024-04-03 -> 2024/2024-04-03
Operation completed successfully.
$ ls
mvcommon
$ touch "Report 234 - Draft1.txt" "Report 234 - Draft2.txt" "Report 234 - Final.txt"
$ ./mvcommon *.txt                                                                  
Creating folder: Report 234
Moved Report 234 - Draft1.txt -> Report 234/Report 234 - Draft1.txt
Moved Report 234 - Draft2.txt -> Report 234/Report 234 - Draft2.txt
Moved Report 234 - Final.txt -> Report 234/Report 234 - Final.txt
Operation completed successfully.
$ ls -lR                                                                            
.:
total 2384
-rwxr-xr-x 1 arran arran 2440869 Dec  9 13:45  mvcommon
drwxr-xr-x 1 arran arran     136 Dec  9 13:46 'Report 234'

'./Report 234':
total 0
-rw-r--r-- 1 arran arran 0 Dec  9 13:45 'Report 234 - Draft1.txt'
-rw-r--r-- 1 arran arran 0 Dec  9 13:45 'Report 234 - Draft2.txt'
-rw-r--r-- 1 arran arran 0 Dec  9 13:45 'Report 234 - Final.txt'
$ touch "[Draft] Report 234.txt" "[For Review a] Report 234 - Version 2.txt" "[Final] Report 234.txt"
$ ls -l
total 2384
-rw-r--r-- 1 arran arran       0 Dec  9 13:46 '[Draft] Report 234.txt'
-rw-r--r-- 1 arran arran       0 Dec  9 13:46 '[Final] Report 234.txt'
-rw-r--r-- 1 arran arran       0 Dec  9 13:46 '[For Review a] Report 234 - Version 2.txt'
-rwxr-xr-x 1 arran arran 2440869 Dec  9 13:45  mvcommon
$ ./mvcommon *.txt                                                                                   
Creating folder: Report 234
Moved [Draft] Report 234.txt -> Report 234/[Draft] Report 234.txt
Moved [Final] Report 234.txt -> Report 234/[Final] Report 234.txt
Moved [For Review a] Report 234 - Version 2.txt -> Report 234/[For Review a] Report 234 - Version 2.txt
Operation completed successfully.
$ find .
.
./mvcommon
./Report 234
./Report 234/[Draft] Report 234.txt
./Report 234/[Final] Report 234.txt
./Report 234/[For Review a] Report 234 - Version 2.txt
$ touch "file_one.txt" "file_two.txt" "file_three.txt"                                               
$ ls -l
total 2384
-rw-r--r-- 1 arran arran       0 Dec  9 13:47 file_one.txt
-rw-r--r-- 1 arran arran       0 Dec  9 13:47 file_three.txt
-rw-r--r-- 1 arran arran       0 Dec  9 13:47 file_two.txt
-rwxr-xr-x 1 arran arran 2440869 Dec  9 13:45 mvcommon
$ ./mvcommon *.txt                                    
Creating folder: file
Moved file_one.txt -> file/file_one.txt
Moved file_three.txt -> file/file_three.txt
Moved file_two.txt -> file/file_two.txt
Operation completed successfully.
$ tree .
.
├── file
│   ├── file_one.txt
│   ├── file_three.txt
│   └── file_two.txt
└── mvcommon

2 directories, 4 files

Interactive mode

% touch "file_one.txt" "file_two.txt" "file_three.txt"
% ./mvcommon -interactive *.txt

Interactive Mode Enabled:
The following files are detected:
1. file_one.txt
2. file_three.txt
3. file_two.txt

Enter file numbers to include (e.g., 1,2,3 or 1-3,5-6) or press 'a' to confirm all:
Your choice: 1-2
Selected files:
 - file_one.txt
 - file_three.txt
Creating folder: file
Moved file_one.txt -> file/file_one.txt
Moved file_three.txt -> file/file_three.txt
Operation completed successfully.
% tree .
.
├── file
│   ├── file_one.txt
│   └── file_three.txt
├── file_two.txt
└── mvcommon

2 directories, 4 files

Download

See Github releases here: https://github.com/arran4/mvcommon/releases

Gentoo

See: https://github.com/arran4/arrans_overlay

$ eselect repository enable arrans-overlay
$ emerge -va app-misc/mvcommon-bin 

Licensed under the terms of the GPL-3.0.

Documentation

Index

Constants

View Source
const (
	DefaultTrim = "-_ ."
)

Variables

View Source
var (
	DefaultStopWords = []string{
		" - ",
		"] ",
		"[",
	}
)

Functions

func CommonPrefixSplit

func CommonPrefixSplit(names []string, stopWords []string, trim string, minMatch int) string

CommonPrefixSplit finds the common prefix of strings, stopping at a stopWords if encountered, removing trim characters from the start and end, and ensuring that the match is minMatch in size minimum.

func MoveFilesToFolder

func MoveFilesToFolder(folder string, files []string, dryRun bool) error

MoveFilesToFolder moves files into a specified folder. In dry-run mode, it only prints actions.

func ParseNumberRanges added in v1.0.3

func ParseNumberRanges(input string, max int) ([]int, error)

Types

This section is empty.

Directories

Path Synopsis
cmd
mvcommon command

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL