Last active
July 30, 2019 17:03
-
-
Save jeffjohnson9046/7c8fd010b49455727a137d5727e6e940 to your computer and use it in GitHub Desktop.
Rename files/directories so that the first letter is upper-case on OS X
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Assume you have a directory structure that looks something like this: | |
ls -alh /path/to/my/directory | |
drwxr-xr-x 38 jeffjohnson staff 1.2K Jul 18 11:07 ./ | |
drwxr-xr-x 6 jeffjohnson staff 192B Jun 23 15:00 ../ | |
drwxr-xr-x 10 jeffjohnson staff 320B Aug 28 2017 foo/ | |
drwxr-xr-x 12 jeffjohnson staff 384B Dec 18 2017 bar/ | |
drwxr-xr-x 11 jeffjohnson staff 352B Feb 26 2018 baz/ | |
-rw-r--r-- 1 jeffjohnson staff 1.8M Aug 14 2017 some-update.sql | |
# list continues... | |
# For whatever reason, you need to update the directory names so the first letter is upper-case. The rename command is what's called for here. | |
# To do a dry run and see what the change will look like (without actually making the change), use the `rename` command with -n: | |
rename -n 's/./\U$&/' * | |
# Output of rename with -n: | |
foo renamed as Foo | |
bar renamed as Bar | |
baz renamed as Baz | |
some-update.sql renamed as Some-update.sql | |
# If you're satisfied with the preview, run the rename command without the -n: | |
rename 's/./\U$&/' * | |
# Examine the results: | |
ls -alh /path/to/my/directory | |
drwxr-xr-x 38 jeffjohnson staff 1.2K Jul 18 11:07 ./ | |
drwxr-xr-x 6 jeffjohnson staff 192B Jun 23 15:00 ../ | |
drwxr-xr-x 10 jeffjohnson staff 320B Aug 28 2017 Foo/ | |
drwxr-xr-x 12 jeffjohnson staff 384B Dec 18 2017 Bar/ | |
drwxr-xr-x 11 jeffjohnson staff 352B Feb 26 2018 Baz/ | |
-rw-r--r-- 1 jeffjohnson staff 1.8M Aug 14 2017 Some-update.sql | |
# To change from upper-case to lower-case, use the following: | |
rename 's/./\l$&/' * | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment