forked from iahmad-khan/LPIC1-LABS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
managing-files
143 lines (71 loc) · 4.49 KB
/
managing-files
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
1. On one line create three files and list the directory output. The file names should be file1, file2, and file 3.
touch file1; touch file2; touch file3; ls
2. Write the output of a command to list ALL files in the home directory of your user to a file called "directory.out".
ls -a > directory.out
You can also list the files using a wild card since the first part of each file we created was "file". Do so by ls file* > directory.out
3. List all the three files you've created above. Then move those files into a new directory called "myfiles"
ls file*; mkdir myfiles; mv file* myfiles/
4. Create a compressed archive of your 'myfiles" directory. Then using the tar command and gzip compression option, create a compressed archive of myfiles/. Once done, verify the contents of the file by listing the contents to the console.
tar -cvzf myfiles.tar.gz myfiles/
tar -ztvf myfiles.tar.gz
5. Create a soft link of the file '/etc/ld.so.conf' in your home directory. Type ls -al to view the link has been created. Then delete the link. Verify whether the original file was deleted or not.
ln -s /etc/ld.so.conf ld.so.conf
ls -al
rm ld.so.conf
ls /etc/ | grep ld.so.conf
6. Create a file called "testhardlink.txt". Create a hard link to that file called "testhardlinkupdate.txt" and then update the contents of that file. Display the contents of the original file and indicate whether they match or not.
touch testhardlink.txt
ln testhardlink.txt testhardlinkupdate.txt
echo "random text" > testhardlinkupdate.txt
cat testhardlink.txt (Should show your "random text)"
7. Create a new directory in your home directory called "course3_video4". In one command, create the following path:
course3_video4/my/new/directory/appeared/like/magic
mkdir course3_video4
mkdir -p course3_video4/my/new/directory/appeared/like/magic
ls -R course3_video4 This will show us what just happened.
8. Change to the 'magic' directory as created above and create a text file called "myfile.txt" with some text content in it. Change the group ownership of the file you just created, assign the group 'wheel'. Remove the entire directory tree we just created.
cd course3_video4/my/new/directory/appeared/like/magic
echo "some text" > myfile.txt
chown user.wheel myfile.txt
cd ~/
rm -rf course3_video4
9. Create a file called "myfile.sh". Give it world readable read, write and execute permissions. Assign the 'wheel' group as the default group for that file. Protect the file from being deleted by anyone not a member of the wheel group WITHOUT changing the default attributes of the file (using one of the special permission bits from the video).
touch myfile.sh
chmod 777 myfile.sh
chown user.wheel myfile.sh
chmod 1777 myfile.sh (or chmod +t)
10. Use the 'chmod' command to change the attribute of the script above to run using the same GROUP permissions as the group owner.
chmod 3777 myfile.sh (or chmod g+s)
Note: 3 in '3777' incorporates both the setgid bit (2), and the sticky bit (1).
11. Create a new group called 'linuxacademy' on your server. Change the default group that all files created by your user will be owned by to this new group. Create a new file that demonstrates the ownership is changed to the 'linuxacademy' group upon creation.
sudo groupadd linuxacademy
sudo usermod -g linuxacademy user
logout of the system and log back in
touch test
ls -al
12. Display the default 'umask' permissions on your system. Change the default umask so that files have world read/write/ and folders have world read/write/execute only. Create a new file that demonstrates that change. Change the attribute of that file so that the time it is modified is never updated.
umask
umask 000 (666-000) = 666 which is read/write for files and (777-000) = 777 which is read/write/execute for dir
touch newfile
chattr -A newfile
13. Using one of the special directories from the video, output the following information to your lab file:
Kernel version and kernel compilation
Number of CPUs in the system
A listing of supported filesystems
Running processes
sudo cat /proc/version
sudo cat /proc/cpuinfo or sudo ls -al /sys/devices/system/cpu
sudo cat /proc/filesystems
sudo ls -al /proc
14. Finding Files In Linux Using Find, Locate, Whereis, Which and Type
Using two different methods, find the following files or directories:
/etc
ld.so.conf
bash
/sbin
Mount
locate /etc
locate ld.so.conf or find / -name 'ld.so.conf'
which bash
locate /sbin
whereis mount or type mount