I am using
ls | cut -c 5-
This does return a list of the file names in the format i want them, but doesn't actually perform the action. Please advise.
I am using
ls | cut -c 5-
This does return a list of the file names in the format i want them, but doesn't actually perform the action. Please advise.
rename -n 's/.{5}(.*)/$1/' *
The -n
is for simulating; remove it to get the actual result.
you can use the following command when you are in the folder where you want to make the renaming:
rename -n -v 's/^(.{5})//' *
-n
is for no action and -v
to show what will be the changes. if you are satisfied with the results you can remove both of them
rename 's/^(.{5})//' *
Something like this should work:
for x in *; do
echo mv $x `echo $x | cut -c 5-`
done
Note that this could be destructive, so run it this way first, and then remove the leading echo
once you're confident that it does what you want.
Kebman's little code is nice for if you want to cut off the leading dot of hidden files and folders in the current dir, before 7zipping or zipping.
I put this in a bash script, but this is wat I mean:
for f in .*; do mv -v "$f" "${f:1}"; done # cut off the leading point of hidden files and dirs
7z a -pPASSWORD -mx=0 -mhe -t7z ${DESTINATION}.7z ${SOURCE} -x!7z_Compress_not_this_script_itself_*.sh # compress all files and dirs of current dir to one 7z-file, excluding the script itself.
zip and 7z can have trouble with hidden files at top level in the current dir. Hidden files in the subdirs are accepted.
mydir/myfile = ok
mydir/.myfile = ok
.mydir/myfile = nok
.mydir/.myfile = nok
If you get an error message saying,
rename is not recognized as the name of a cmdlet
This might work for you,
get-childitem * | rename-item -newname { [string]($_.name).substring(5) }