Assignment 03 Sol (1)
Assignment 03 Sol (1)
Assignment 03 Sol (1)
dictionary Music drwxrw-r-- shows that , Owner can read, write and execute
Usergroup can read and write
World can only read
Setting permission to other user:
Command Permission
Chmod a=rwx myfile.txt rwxrwxrwx
Chmod o= myfiles.txt -rwxrwx-
Chmod g=w myfiles.txt -rwx-w--
Chmod go=r myfiles.txt -rwxr-r--
Chmod g+x myfiles.txt -rwxr-xr--
Chmod o-r myfiles.txt -rwxr-x--
Give the file owner read and write permissions and only read permissions to group
members and all other users:
Give read, write, and execute permissions, and a sticky bit to a given directory:
set read, write, and execute permissions to the file owner and no permissions for
all other users on a given directory:
change the permissions of all files and subdirectories under the directory
to755you would use:
6. Type umask 000 and then create a file called world.txt containing the words
"hello world". Look at the permissions on the file. What's happened? Now
type umask 022 and create a file called world2.txt. When might this feature
be useful?
ANS 6:
8. Use find to display the names of all files in the /home subdirectory
tree. Can you do this without displaying errors for files you can't read?
Ans 8:
To search for files based on their type, use the -type option one of the following
descriptors to specify the files type:
f: a regular file
d: directory
l: symbolic link
c: characters devices
b: block devices
p: named pipe (FIFO)
s: socket
9. Use find to display the names of all files in the system that are bigger
than 1MB.
10. Use find and file to display all files in the /home subdirectory tree, as
well as a guess at what sort of a file they are. Do this in two different
ways.
ANS 9, 10 :
Find files by size
To find files based on the size, pass the -size parameter along with the size
criteria. You can use the following surffixes to specify the file size.
b: 512-bytes block (default)
c: bytes
w: two- bytes words
k: kilobytes
M: megabytes
G: Gigabytes
following command will find all files of exactly 1024 bytes inside the /tmp
directory
$find /tmp -type f -size 1024c
Use find to display the names of all files in the system that are bigger
than 1MB.
You can even search for files within a size range. The following command
will find all files betweenn1 and 2MB
The command below will list all files in the home directory that were
modified 30 or more days ago:
You can easily filter all files under the/etc/dovecot/conf.d directory that
ends with .conf and has been modified in the last five days:
Find by permission
command will match all the files with read permissions set for either user, group,
or others.
Find . -perm /444
11. Use grep to isolate the line in /etc/passwd that contains your login
details.
Ans 11:
12. Use find and grep and sort to display a sorted list of all files in the /home
subdirectory tree that contain the word hello somewhere inside them.
Ans 12:
13. Use locate to find all filenames that contain the word emacs. Can you
combine this with grep to avoid displaying all filenames containing the
word lib?
Ans 13:
Check size of existing tar, tar.gz, tar.tbz file in Linux : ?The above
command will display the size of archive file in Kilobytes(KB).
$ tar czf file.tar | wc -c
or
$ tar czf file1.tar.gz | wc -c
or
$ tar czf file2.tar.tbz | wc -c
list the contents and specify the tarfile using option -tf :
This command will list the entire list of archived file. We can also list for specific
content in a tarfile
$ tar tf file.tar
Output :
example.cpp
Applying pipe to through ??grep command?? to find what we are looking
for :
This command will list only for the mentioned text or image in grep from archived
file.
$ tar tvf file.tar | grep "text to find"
or
$ tar tvf file.tar | grep "filename.file extension"
USING CPIO:
Untar using CPIO:
17. Type mount (with no parameters) and try to interpret the output.
Ans 17 :
The “mount” command is used to connect an external device file system to the
system's file system.
18. list the different editors available in linux and what are the difference
between those and vi editor.
Ans 18:
In this section, we are going to discuss the top 20 text editors for Linux. Further,
we will talk about the latest text editors and will compare them with the
traditional text editors such as Viand nano This will help you with selecting the
editor of your choice.
1. Vi/VIM editor
2. Nano editor
3. Gedit editor
4. Sublime text editor
5. VSCode
6. GNU emacs
7. Atom editor
8. Brackets editor
9. Pico editor
10. Bluefish
11. Kate/Kwrite
12. Notepad ++
13. Eclipse
14. gVIM editor
15. Jed editor
16. Geany editor
17. Leaf Pad
18. Light Table
19. Medit text editor
20. CodeLite
Vi EDITOR:
Vim editor is one of the most used and powerful command-line based editor of the
Linux system. By default, it is supported by most Linux distros. It has enhanced
functionalities of the old Unix Vi editor. It is a user-friendly editor and provides the
same environment for all the Linux distros. It is also termed as programmer's
editor because most programmers prefer Vi editor.
Vi editor has some special features such as Vi modes and syntax highlighting that
makes it powerful than other text editors. Generally, it has two modes:
Command Mode: The command mode allows us to perform actions on files. By
default, it starts in command mode. In this mode, all types of words are
considered as commands. We can execute commands in this mode.
Insert Mode: The insert mode allows to insert text on files. To switch from
command mode to insert mode, press the Esc key to exit from active mode
and 'i' key.