Last active
December 29, 2015 10:29
-
-
Save tsironis/7656866 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# | |
# Date: 26/11/2013 | |
# Dimitris Tsironis | |
# Bash lesson for ECS OSLab | |
# | |
# Choice 1 | |
function printPermissions { | |
echo "> Printing file's permissions" | |
ls -l $path | cut -c 1-10 | |
} | |
# Choice 2 | |
function changePermissions { | |
echo "> Changing permissions" | |
echo "> Gimme some permissions:" | |
read permissions | |
chmod $permissions $path | |
} | |
# Choice 3 | |
function showLines { | |
echo "> Showing last [n] lines" | |
echo "> Gimme how many lines:" | |
read lines | |
tail -n $lines $path | |
} | |
# Choice 4 | |
function copyFiles { | |
echo "> Copying files" | |
echo "> Give source file:" | |
read source | |
echo "> Give destination file:" | |
read dest | |
cp $source $dest | |
} | |
# Choice 5 | |
function renameFiles { | |
echo "> Renaming files" | |
echo "> Give old filename:" | |
read source | |
echo "> Give new filename:" | |
read dest | |
mv $source $dest | |
} | |
# Choice 6 | |
function showProcesses { | |
echo "> Showing user's processes" | |
echo "> Give username:" | |
read username | |
ps -ef | grep $username | |
} | |
# Choice 7 | |
function removingFiles { | |
echo "> Removing file" | |
echo "> Give filename to be deleted:" | |
read file | |
rm $file | |
} | |
# Choice 8 | |
function showFiletype { | |
echo "> Showing filetype" | |
stat -c%F $path | |
} | |
# Choice 9 | |
function killProcesses { | |
echo "> Killing process" | |
echo "> Gimme a process name:" | |
read process | |
killall $process | |
} | |
echo "Give me a choice:" | |
echo " 1. Print permissions for all files and subfolders" | |
echo " 2. Change permissions" | |
echo " 3. Print the last [n] lines of a file" | |
echo " 4. Copy a file from a folder to another" | |
echo " 5. Change name of a file or folder" | |
echo " 6. Print all processes for a given user" | |
echo " 7. Delete a given file" | |
echo " 8. Prin the filetype for a given file" | |
echo " 9. Kill a process based on its name" | |
read choice | |
echo "Give me a file:" | |
read path | |
if [ $choice -eq 1 ] | |
then | |
printPermissions | |
elif [ $choice -eq 2 ] | |
then | |
changePermissions | |
elif [ $choice -eq 3 ] | |
then | |
showLines | |
elif [ $choice -eq 4 ] | |
then | |
copyFiles | |
elif [ $choice -eq 5 ] | |
then | |
renameFiles | |
elif [ $choice -eq 6 ] | |
then | |
showProcesses | |
elif [ $choice -eq 7 ] | |
then | |
removingFiles | |
elif [ $choice -eq 8 ] | |
then | |
showFiletype | |
elif [ $choice -eq 9 ] | |
then | |
killProcesses | |
fi | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment