Last active
September 7, 2020 14:59
-
-
Save SkymeFactor/b92d5d34c1df38d540650a0145ad12f5 to your computer and use it in GitHub Desktop.
Linux administration: Lab_1
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/sh | |
# 1 Create the "test" directory if it doesnt already exist | |
if [ ! -d ~/test ]; then mkdir ~/test; fi | |
# 2 Write the list of all sub-files and folders of /etc | |
ls -a -g /etc > ~/test/list | |
# 3 Show the number of folders in /etc | |
echo "directories: $(grep -c -e "^d" ~/test/list)" >> ~/test/list | |
# 3 Show the number of files in /etc | |
echo "files: $(grep -c -v "^d" ~/test/list)" >> ~/test/list | |
# 4 Create the "links" directory inside of "test" | |
if [ ! -d ~/test/links ]; then mkdir ~/test/links; fi | |
# 5 Create a hard-link to "list" as "list_hlink" inside ~/test/list | |
if [ -e ~/test/links/list_hlink ]; then | |
rm ~/test/links/list_hlink; | |
fi | |
ln ~/test/list ~/test/links/list_hlink; | |
# 6 Create a symbolic link to "list" as "list_slink" inside ~/test/list | |
if [ ! -e ~/test/links/list_slink ]; then | |
ln -s ~/test/list ~/test/links/list_slink; | |
fi | |
# 7 Display the info about number of hard links to all three files | |
echo "Hard links to ~/test/list: " | |
find ~/test/ -inum $(ls -i ~/test/list | awk '{print $1}') | |
echo "" && echo "Hard links to ~/test/links/list_hlink: " | |
find ~/test/ -inum $(ls -i ~/test/links/list_hlink | awk '{print $1}') | |
echo "" && echo "Hard links to ~/test/links/list_slink: " | |
find ~/test/ -inum $(ls -i ~/test/links/list_slink | awk '{print $1}') | |
# 8 Write num of lines of list to the end of list_hlink | |
wc -l ~/test/list | awk '{print $1}'>> ~/test/links/list_hlink | |
# 9 Compare ~/test/list and ~/test/links/list_hlink, print YES if equal | |
echo "" | |
if diff -N ~/test/links/list_hlink ~/test/links/list_slink >/dev/null ; then | |
echo "YES_1"; | |
fi | |
# 10 Rename list into list1 | |
mv ~/test/list ~/test/list1 | |
# 11 Compare ~/test/list and ~/test/links/list_hlink, print YES if equal | |
if diff -N ~/test/links/list_hlink ~/test/links/list_slink >/dev/null ; then | |
echo "YES_2"; | |
fi | |
# 12 Creating a hard link to "links" directory inside ~/ is impossible | |
echo "" | |
ln -F ~/test/links ~/links | |
# 12 So I mounted it instead | |
if [ ! -d ~/links ]; then mkdir ~/links; fi | |
sudo mount -o bind ~/test/links ~/links | |
# 12 Dont forget to umount it after usage!!! | |
sudo umount ~/links | |
# 13 Create a "list_conf" file with all .conf files from /etc | |
sudo ls -la /etc | grep -e "\.conf$" > ~/list_conf | |
# 14 Create a "list_d" file containing all sub-folders from all /etc/*.d folders | |
sudo ls -lda /etc/*.d/* | grep -e "^d" > ~/list_d | |
# 15 Create a "list_conf_d" file with all info from "list_conf" and "list_d" | |
cat ~/list_conf ~/list_d > ~/list_conf_d | |
# 16 Create a hidden folder "sub" inside ~/test | |
if [ ! -d ~/test/.sub ]; then | |
mkdir ~/test/.sub; | |
fi | |
# 17 Copy "list_conf_d" into ~/test/.sub | |
cp ~/list_conf_d ~/test/.sub/ | |
# 18 Copy "list_conf_d" into ~/test/.sub again creating a backup if exist | |
cp -b ~/list_conf_d ~/test/.sub/ | |
# 19 Show the entire structure of ~/test | |
echo "" | |
ls -Ral ~/test | |
# 20 Create "man.txt" in ~/ containing the documentation for man | |
man man > ~/man.txt | |
# 21 Split "man.txt" by 1000 Bytes | |
split ~/man.txt -b 1000 | |
# 22 Create a "man.dir" folder inside the ~/test | |
if [ ! -d ~/test/man.dir ]; then | |
mkdir ~/test/man.dir; | |
fi | |
# 23 Move all the shards of splitted "man.txt" into ~/test/man.dir | |
mv x[a-z][a-z] ~/test/man.dir | |
# 24 Assemble all files within ~/test/man.dir back into "man.txt" | |
if [ -e ~/test/man.dir/man.txt ]; then | |
rm ~/test/man.dir/man.txt; | |
fi | |
cat ~/test/man.dir/x[a-z][a-z] > ~/test/man.dir/man.txt | |
# 25 Compare "man.txt" within ~/ and ~/test/man.dir, show YES if equal | |
echo "" | |
if diff ~/man.txt ~/test/man.dir/man.txt >/dev/null; then | |
echo "YES_3"; | |
fi | |
# 26 Add multiple random lines to the beginning and the end of ~/man.txt | |
echo "ghrgh ht hrtn\n rndn dn\nn erns zde\n$(cat ~/man.txt)" > ~/man.txt | |
echo "gerhg rjsgerg\neakjebkqjblzv' 'dhe;lrrr\n" >> ~/man.txt | |
# 27 Get the difference of both of man.txt ready to patch | |
diff -u ~/test/man.dir/man.txt ~/man.txt > diff.patch | |
# 28 Move patch file into man.dir | |
mv diff.patch ~/test/man.dir/ | |
# 29 Patch the ~/test/man.dir/man.txt file | |
echo "" | |
patch -u <~/test/man.dir/diff.patch ~/test/man.dir/man.txt | |
# 30 Compare "man.txt" within ~/ and ~/test/man.dir, show YES if equal | |
echo "" | |
if diff -N ~/man.txt ~/test/man.dir/man.txt > /dev/null; then | |
echo "YES_4"; | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment