1⟩ Indicate the right option to search for anything not a letter or number a) grep '^[a-zA-Z0-9]' b) grep '[^a-zA-Z0-9]' c) grep '[a-zA-Z0-9]' d) None of the above in Search Pattern
b) grep '[^a-zA-Z0-9]'
“Linux Search Pattern frequently Asked Questions by expert members with experience in Search Pattern. These questions and answers will help you strengthen your technical skills, prepare for the new job test and quickly revise the concepts”
b) grep '[^a-zA-Z0-9]'
a) awk `{print $1 ":" $6}` /etc/passwd
d) comm
a) sort foo | uniq -u
a) user1
d)
a) uniq -u
b) grep 'B[oO][bB]' files
d) $ grep [^$] file
c) -n
b) The count of lines which begin with the pattern echo in file abc
c) -1
Explanation:
The "close" system call closes a file descriptor but in the program "fd2″ in not a file descriptor. Hence close system call returns -1.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
-1
[root@localhost google]#
b) this program will print "#include"
Explanation:
The "dup" system creates the a copy of the file descriptor.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
#include
[root@localhost google]#
a) linux
Explanation:
The lseek function allows the file offset to be set beyond the end of the file and if the data is latter written this point, subsequent reads of the data in the gap returns NULL.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
linux
[root@localhost google]#
d) none of the mentioned
Explanation:
Because of "lseek" system call the character "s" is overwritten by character "d" in the file "google.txt".
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
d
[root@localhost google]#
a) it will print nothing
Explanation:
We have to use "lseek" system call if we want to read the file from the beginning just after writing into it.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ls
san san.c
[root@localhost google]# ./san
[root@localhost google]# ls
san san.c google.txt
[root@localhost google]# vim google.txt
[root@localhost google]#
a) 5
Explanation:
The "read" system call returns the number of bytes successfully read.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
5
[root@localhost google]#
d) none of the mentioned
Explanation:
This program will write nothing in the source file "san.c" because we are opening the file in read only mode.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
write: Bad file descriptor
[root@localhost google]#
a) it will create a file "google.txt" in the present working directory
Explanation:
This program will write only "Linux" in the file "google.txt" because we are writing only 5 bytes with "write" system call.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ls
san san.c
[root@localhost google]# ./san
[root@localhost google]# ls
san san.c google.txt
[root@localhost google]# vim google.txt
[root@localhost google]#
a) it will print nothing
Explanation:
none.
Output:
[root@localhost google]# gcc -o san san.c
[root@localhost google]# ./san
#include
#include
int main()
{
int fd, count;
char ch;
fd = open("san.c",O_RDONLY);
do{
count = read(fd,&ch,1);
printf("%c",ch);
}while(count);
}
[root@localhost google]#