Skip to content

Instantly share code, notes, and snippets.

@arthuroe
Created March 7, 2018 14:24
Show Gist options
  • Save arthuroe/6371067ab8220256355381e58aec7ce2 to your computer and use it in GitHub Desktop.
Save arthuroe/6371067ab8220256355381e58aec7ce2 to your computer and use it in GitHub Desktop.
Shell script that creates directories, files, moves between the different directories and directs user input
#!/bin/bash
read -p "Enter name of folder you want to create: " folderOne
read -p "Enter name of second folder you want to create: " folderTwo
echo "-----Creating directories now"
mkdir $folderOne && mkdir $folderTwo
echo "-----Creating text files now"
touch fileone.txt filetwo.txt
#- Writes into fileone
text="this is file one"
echo $text > fileone.txt
echo "-----file one content"
cat fileone.txt
#- Writes into filetwo
text="this is file two"
echo $text > filetwo.txt
echo "-----file two content"
cat filetwo.txt
#echo "Copying fileone to ${folderOne} copying filetwo to ${folderTwo}"
cp fileone.txt ~/$folderOne/ && cp filetwo.txt ~/$folderTwo/
echo "----- ${folderOne} contents"
cd $folderOne && ls -a
echo "----- ${folderTwo} contents"
cd ..
cd $folderTwo && ls -a
# Copies the content of file1.txt into file2.txt
echo "----- Copying file1.txt into file2.txt"
cd ..
cat fileone.txt > filetwo.txt
echo "----- filetwo content"
cat filetwo.txt
#Move files to folders
mv fileone.txt ~/$folderOne/ && mv filetwo.txt ~/$folderTwo/
#- prompt user to enter a folder/file name
read -p "Enter a folder or file name to search in ~/ " keyword
#- filter file list by keyword passed above
ls -l ~/ | grep $keyword
echo "****thanks****"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment