14.04 - Rename files to their BASE64 - Ask Ubuntu


i want rename filenames base64, not extension. created script doesn't work. can tell problem please?

#!/bin/bash #initialize random text onlyfilename="abc" extension="def" #go through files in directory filename in ./*;         #avoid script files (enc & dec)         if [ $filename != "./enc" ] && [ $filename != "./dec"  ];                 #remove ./ beginning , filename                 $onlyfilename=$(basename ${filename:2})                 #get extension                 $extension=${onlyfilename##*.}                 #check if correct                 echo $onlyfilename                 echo $extension                 #rename filename base64                 mv "$filename" "$(echo -n $onlyfilename | base64).$extension"         fi done 

purpose: want rename files base64 , download them. base64 filename valid filename download? if not, there alternative base64?

as one-liner

$ file in * ; echo  "$file" "$(basename $file | base64 )"."${file##*.}" ; done file1.png zmlszteucg5ncg==.png file2.jpeg zmlsztiuanblzwo=.jpeg file3.txt zmlsztmudhh0cg==.txt 

replace first echo mv rename them


Comments

Popular posts from this blog

download - Firefox cannot save files (most of the time), how to solve? - Super User

windows - "-2146893807 NTE_NOT_FOUND" when repair certificate store - Super User

sql server - "Configuration file does not exist", Event ID 274 - Super User