@@ -0,0 +1 @@ | |||||
RinRi |
@@ -0,0 +1 @@ | |||||
RinRi |
@@ -0,0 +1 @@ | |||||
RinRi |
@@ -0,0 +1 @@ | |||||
lol |
@@ -0,0 +1,9 @@ | |||||
#!/bin/sh | |||||
rm -f _ex1* | |||||
echo "RinRi" > _ex1.txt | |||||
ln -f _ex1.txt _ex1_1.txt | |||||
ln -f _ex1.txt _ex1_2.txt | |||||
ls -i _ex1.txt > ex1.txt | |||||
ls -i _ex1_1.txt >> ex1.txt | |||||
ls -i _ex1_2.txt >> ex1.txt |
@@ -0,0 +1,3 @@ | |||||
6817598 _ex1.txt | |||||
6817598 _ex1_1.txt | |||||
6817598 _ex1_2.txt |
@@ -0,0 +1,8 @@ | |||||
#!/bin/sh | |||||
rm -f ../week01/file.txt _ex2.txt | |||||
echo "file" > ../week01/file.txt | |||||
ln -f ../week01/file.txt _ex2.txt | |||||
inode=$(find _ex2.txt -printf '%i') | |||||
find .. -inum "$inode" > ex2.txt | |||||
find .. -inum "$inode" -exec rm {} \; >> ex2.txt |
@@ -0,0 +1,2 @@ | |||||
../week10/_ex2.txt | |||||
../week01/file.txt |
@@ -0,0 +1,13 @@ | |||||
#!/bin/sh | |||||
rm -f _ex3.txt | |||||
echo "lol" > _ex3.txt | |||||
chmod a-x _ex3.txt | |||||
ls -l _ex3.txt > ex3.txt | |||||
chmod 707 _ex3.txt | |||||
ls -l _ex3.txt >> ex3.txt | |||||
chmod a=u _ex3.txt | |||||
ls -l _ex3.txt >> ex3.txt | |||||
echo "660 means read and write permissions (6) for user and the group" >> ex3.txt | |||||
echo "775 means read, write, and execute permissions (7) for user and the group, and read and execute permissions (5) for others" >> ex3.txt | |||||
echo "777 means read, write, and execute permissions (7) for everyone" >> ex3.txt |
@@ -0,0 +1,6 @@ | |||||
-rw-r--r-- 1 rinri users 4 Nov 15 21:08 _ex3.txt | |||||
-rwx---rwx 1 rinri users 4 Nov 15 21:08 _ex3.txt | |||||
-rwxrwxrwx 1 rinri users 4 Nov 15 21:08 _ex3.txt | |||||
660 means read and write permissions (6) for user and the group | |||||
775 means read, write, and execute permissions (7) for user and the group, and read and execute permissions (5) for others | |||||
777 means read, write, and execute permissions (7) for everyone |
@@ -0,0 +1,71 @@ | |||||
#include <stdio.h> | |||||
#include <stdlib.h> | |||||
#include <string.h> | |||||
#include <dirent.h> | |||||
#include <sys/stat.h> | |||||
struct file { | |||||
ino_t inode; | |||||
char names[64][256]; | |||||
int sz; | |||||
}; | |||||
int putToFiles(char name[256], ino_t inode, struct file *files, int sz) { | |||||
// if found the same inode | |||||
for (int i = 0; i < sz; ++i) { | |||||
if (files[i].inode == inode) { | |||||
memcpy(files[i].names[files[i].sz++], name, 256); | |||||
return sz; | |||||
} | |||||
} | |||||
// if not found | |||||
files[sz].inode = inode; | |||||
memcpy(files[sz].names[0], name, 256); | |||||
files[sz].sz = 1; | |||||
sz++; | |||||
return sz; | |||||
} | |||||
int main() { | |||||
DIR *d = opendir("./tmp"); | |||||
if (d == NULL) { | |||||
perror("opendir"); | |||||
exit(1); | |||||
} | |||||
struct file files[64]; | |||||
int sz = 0; | |||||
struct dirent *entry; | |||||
while ((entry = readdir(d))!= NULL) { | |||||
if (entry->d_name[0] == '.') | |||||
continue; | |||||
//printf("%s ", entry->d_name); | |||||
struct stat s; | |||||
char buf[256] = "./tmp/"; | |||||
strncpy(buf + strlen(buf), entry->d_name, 200); | |||||
if (stat(buf, &s) == -1) { | |||||
perror("stat"); | |||||
exit(1); | |||||
} | |||||
sz = putToFiles(entry->d_name, s.st_ino, files, sz); | |||||
} | |||||
printf("File --- Hard links\n"); | |||||
for (int i = 0; i < sz; ++i) { | |||||
if (files[i].sz > 1) { | |||||
for (int j = 0; j < files[i].sz; ++j) { | |||||
printf("%s --- ", files[i].names[j]); | |||||
for (int k = 0; k < files[i].sz; ++k) { | |||||
printf("%s ", files[i].names[k]); | |||||
} | |||||
printf("\n"); | |||||
} | |||||
} | |||||
} | |||||
} |
@@ -0,0 +1,9 @@ | |||||
#!/bin/sh | |||||
rm -rf tmp | |||||
mkdir tmp | |||||
touch tmp/file1 tmp/file2 | |||||
ln tmp/file1 tmp/link1 | |||||
gcc ex4.c -o ex4.out | |||||
./ex4.out |