i have a directory full of sub-directories with names like 01 - title of folder 02 - second title03 - etc04 - etc...30 - final folderi want to truncate all of these folder names to just be the numbers so they would appear like so:010203is there a way to write a script or a simple command that will accomplish this?
Truncating folder names after first space
ubuntu;directory;rename;mv
Using the Perl-based rename utility (which appears to be what Ubuntuprovides), you could do the renaming operation like this (replacing* with whichever list of directories you actually want):rename 's/^(\S+).*/$1/' *(I suggest using rename -n at first to see what would be done beforeactually renaming anything.)The replacement string asks to match a sequence of non-spacecharacters (\S+) at the start (^) of the original file name,followed by anything (.*), and replacing it with the first matchedgroup ($1), which was the initial space-free segment.