linux script Archives - Memory Dump

Sed, grep and other commands

Replace string in several files

sed -i ‘s/text to be replaced/new text/g’ *
Share
By Marco Constâncio on April 15, 2011 | Linux | A comment?
Tags:

Scripts

extract_rar

Extracts every rar file in the directory.

#!/bin/bash
for f in *.rar; do
	echo "Processing $f"
	unrar x -y -p"password" $f
done

remove_special_char

Rename the files by removing special characters like spaces and other characters.

#!/bin/bash
ls | while read -r FILE
do
    mv -v "$FILE" `echo $FILE | tr '\[' ' ' | tr '\]' ' ' | tr '\)' ' ' | tr '(' ' ' | tr ' ' '_'`;
done

compress_dirs

Compress every sub-directory on the current directory to a zip file to the same name.

#!/bin/bash
ls | while read -r FILE
do
    zip -9 $FILE.zip $FILE/*
done

convert_archive

Convert a files from a archive file type to the archive file tpye specified. The a atool package must installed to work.

#!/bin/bash
arepack -e --format=$2 *.$1

Example: to convert all 7z files to zip files, use the command:

convert_archive 7z zip
Share
By Marco Constâncio on | Linux | A comment?
Tags: