Wednesday, December 23, 2015

My Shell Scripts

Traversing Directory

Below script traverses given directory, gets names of subdirectories, prepares name of zip file by appending zip to subdirectory name and copies zip those zip files to another directory.

IFS=$'\n';
for f in $(ls -l /home/taimoor/test | grep '^d' | sed 's/^.* //'); do
    cp /home/taimoor/toTest/$f.zip /home/taimoor/testLocation/;
    done

In above script, it traverses /home/taimoor/test, gets name of subdirectory, assign it to "f" and copies zip file with this name from /home/taimoor/toTest to /home/taimoor/testLocation

Print all files in directory n subdirectories (excluding svn)

test_dir=/home/taimoor/test
for f in $(find $test_dir -type f -a \! \( -path \*.svn\* \)); do
        echo $f
        done

No comments:

Post a Comment