-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathREADME
156 lines (111 loc) · 5.47 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
transform-mv
Originally hosted on http://tmv.sourceforge.net
Author: Gene Pavlovsky <[email protected]>
This is an old tool of mine that I still use daily.
It could use some improvements and minor bug fixes.
One day I might decide to put some more love in it.
1. Introduction
Renames files/directories according to sed script(s). Optionally,
converts pathnames to upper/lower-case, from/to the specified
character set, or even pipes them through arbitrary command(s).
2. Documentation
The 'tmv' shell script applies a number of transformations to a list
of pathnames (files/directories). The list of pathnames is specified
on a command line. Pathnames will also be read from standard input
in case none were found on command line, or '-' was specified on
command line. Transformations are commands that read their input,
process it, and output the results. This architecture allows for
several built-in transformations and a multitude of external ones,
by specifying arbitrary command(s) to process the pathnames.
Please note that only the last slash-delimited portion of the name
is transformed (e.g. 'tmv -l /A/B' will move '/A/B' to '/A/b').
Usage: tmv [options] pathname [pathname]*
2.1. Transformation using sed
This transformation, the most flexible of the built-in ones,
uses sed to perform a sed script on the pathnames.
Options:
-e SCRIPT, --expression=SCRIPT
add the SCRIPT to the sed script
-f FILE, --file=FILE
add the contents of FILE to the sed script
-r, --regexp-extended
use extended regular expressions in the sed script
All these options are taken as-is from sed itself. Like sed, multiple
scripts can be specified. But, unlike sed, '-e/--expression' option
must be specified even when using only one expression.
Examples:
# For all files/directories in the current directory, change spaces to
# underscores, change sequences of several underscores to one underscore.
find . -depth | tmv -e 'y/ /_/' -e 's/_\{2,\}/_/g'
2.2. Conversion to upper/lower-case
Pathnames are converted to upper/lower-case using 'dd conv=[lu]case'.
Options:
-l, --lcase
convert pathnames to lower case (using 'dd conv=lcase')
-u, --ucase
convert pathnames to upper case (using 'dd conv=ucase')
I never use '--ucase', but I had to add it for the symmetry with '--lcase'.
Examples:
# For all files/directories (not recursively) in new_music, convert
# pathnames to lowercase.
tmv -l new_music/*
2.3. Character set conversion
Pathnames are converted from one character set to another using iconv.
Options:
--iconv=FROM:TO
convert pathnames from charset FROM to charset TO
--iconv=FROM
convert pathnames from charset FROM to locale (user) charset
--iconv=:TO
convert pathnames from locase (user) charset to charset TO
Examples:
# For all file/directories in copy_of_joliet_cd_with_russian_pathnames,
# convert the pathnames' charset from CP1251 to locale (user) charset
find copy_of_joliet_cd_with_russian_pathnames -depth | tmv --iconv=cp1251
2.4. Transformation with external command(s)
Pathnames can be transformed by arbitrary external command(s).
Options:
--pipe=COMMAND
pipe pathnames through COMMAND; several '--pipe' options can be
specified; commands will be executed in order of their specification
Examples:
# Actually, all processing command useful for me are already done as
# built-in transformations, so I'll give an example with sed again.
# For all files in the current directory, change the extension from
# 'htm' to 'html'. Nothing will be done with files not ending with 'htm'.
find . -maxdepth 1 -type f | tmv --pipe='sed "s/htm$/html/"'
2.5. Other options
-b, --backup
mv is always run with '-f' option, so if you are afraid tmv might
overwrite some files, you can (with GNU version of mv) use '-b'
option; for details see mv(1)
-q, --quiet
by default, verbose mode is on, displaying some progress information,
and the names of source/destination files; this options makes tmv silent
-n, --dry-run
no files are renamed, but source/destination files are printed (if
not '--quiet', which is pointless in conjunction with this option);
this mode is useful when you're not sure about the correctness of your
sed script(s), don't know the FROM charset and are just guessing etc.
2.6. Options processing notes
If you want to specify non-option arguments starting with '-', write them after
a '--', after which all the remaining arguments are treated as options.
2.7. Little scripts built around tmv
2.7.1. tmv-ul
Usage: tmv-ul path [path]*
'tmv-ul' script finds all files/directories in given path(s), and
change spaces to underscores, converting text to lower case. Accepts
no options (not even '--help' and '--version').
2.7.2. tmv-strip
Usage: tmv-strip string
'tmv-strip' script finds all files in the current directory, containing
a given string, and removes it from them. Accepts no options (not even
'--help' and '--version').
2.8. Reporting bugs / Sending patches / Requesting enhancements
If you think you've found a bug, written a patch or want a new
feature badly, feel free to mail me at <[email protected]>.
Be sure to set the subject to 'tmv: bugreport: blah blah blah',
'tmv: patch: blah blah blah' or 'tmv: rfe: blah blah blah'
for bugreport, patch or RFE respectively.
When writing bugreports, be sure to include as much information as
possible. Be absolutely sure to write how to reproduce the bug.