shell - extract rar files to same folder name -
i have many .rar folders within particular directory. want extract contents of each rar folder in same directory , extracted files of rar folder should placed in new folder same name of rar folder name.
for example, if there 2 rar files: one.rar , two.rar, script should create 2 folders of same name: one , two. folder named one should contain files extracted one.rar , folder named two should contain files extracted two.rar.
the command: unrar e $filename extracts contents of rar file not create destination folder.
if use unrar e $filename $destination_path, since there can many rar files, manually creating folder name in destination path take lot of time. how can achieve shell script?
so far have written these lines:
loc="/home/desktop/code"` # directory path contains rar files extracted <br/> file in "$loc"/* unrar e $file done i don't know how create same folder name of rar name , extract files of rar in newly created folder of same name.
any appreciated. in advance !!
you can use sed remove file extension archives. @ following script sets destination corresponding name.
#!/bin/sh archive in "$(find $loc -name '*.rar')"; destination="$( echo $archive | sed -e 's/.rar//')" if [ ! -d "$destination" ] ; mkdir "$destination"; fi unrar e "$archive" "$destination" done if you're using bash, can use
#!/bin/bash archive in "$(find $loc -name '*.rar')"; destination="${archive%.rar}" if [ ! -d "$destination" ] ; mkdir "$destination"; fi unrar e "$archive" "$destination" done
Comments
Post a Comment