Writing Scripts
echo "What is your name?"
read name
echo "Hello, $name"#!/bin/bash
# Make variables for directory to loop through
# and directory where files should be moved.
directory="/home/asoberan/unixclass"
new_directory="/home/asoberan/bigfiles"
# If the new directory doesn't exist, then
# create the directory
if [ ! -d $new_directory]; then
mkdir $new_directory;
fi;
# Loop through the contents in the directory.
# Only move files, skip directories.
# Store the size of the file (in KB), in
# file_size. If the file size is greater
# than 400000 KB, move the file to the
# new directory
for file in $directory/*;
do
if [ -f "$file" ]; then
file_size=$(du "$file" | cut -f1)
if [ "$file_size" -gt 400000 ]; then
mv "$file" "$new_directory"
fi;
fi;
done;Last updated
Was this helpful?
