Category Archives: Shell Script

Shell – String replace

Previously we talked about how to submit a Google Form by the curl command.


In the url, we have to encode the special characters such as whitespace. In shell script, we could do string replace as follow.


Continue reading Shell – String replace


Submit Google Forms by curl command

Google Forms is a very common way to collect user data nowadays. After you have created the form, you could insert it to your web site and present it with your own style.

Other than that, we could integrate Google Forms with the backend job since we could submit the form through command line. Let’s take a look on the following example.

1. Create a new form on your Google drive. The edit page url should be in the following format.


Continue reading Submit Google Forms by curl command

Shell Script – Check file owner and other attributes

Here is a simple shell script which would read a user input and return you the owner and group of the input path.


echo "Please enter a file/folder path:"
read target_path
echo "You have entered $target_path"

if [ -e $target_path ]; then
  target_owner=$(stat -c %U $target_path)
  target_group=$(stat -c %G $target_path)

  echo "$target_path owner is: $target_owner"
  echo "$target_path group is: $target_group"
  echo "$target_path is not a valid path"

Continue reading Shell Script – Check file owner and other attributes

Shell Script – Delete Old Files

For housekeeping the backup files on a server, we can write a shell script to remove files which were created some days ago and scheduled it by cron job.

The following code is an example to remove backup files which were created 90 days ago. Please note that the target folder is just the same as the .sh file location and the .sh file is excluded in the command.
Continue reading Shell Script – Delete Old Files