Basic unix commands Flashcards

to crack the interviews

1
Q

create a tar archive file tecmint-14-09-12.tar for a directory /home/tecmint in current working directory

A

tar -cvf tecmint-14-09-12.tar /home/tecmint

-cvf options specified? no? then rate 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

create a compressed MyImages-14-09-12.tar.gz file for the directory /home/MyImages

A

tar -cvzf MyImages-14-09-12.tar.gz /home/MyImages

right extension of tar file, no-rate 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

create a Phpfiles-org.tar.bz2 file for a directory /home/php

A

tar -cvfj Phpfiles-org.tar.bz2 /home/php

options specified? no? then rate 2
right extension of tar file, no-rate 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

untar the file public_html-14-09-12.tar in present working directory

A

tar -xvf public_html-14-09-12.tar

options specified? no? then rate 2
if said untar instead of tar -x, rate 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Uncompress tar.gz archive file in different working directory /etc/psswd -the absolute path

A

tar -xvf public_html-14-09-12.tar.gz -C /etc/psswd

options specified? no? then rate 2
if said untar instead of tar -x, rate 1
right extension of tar file, no-rate 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Uncompress highly compressed tar.bz2 file

A

tar -xvf public_html-14-09-12.tar.bz2

options specified? no? then rate 2
if said untar instead of tar -x, rate 1
right extension of tar file, no-rate 3
no j in the options during uncompress-note this

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

list the content of uploadprogress.tar file.

A

tar -tvf uploadprogress.tar

options specified? no? then rate 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

list the content of tar.gz file

A

tar -tvf uploadprogress.tar.gz

options specified? no? then rate 2
right extension of tar file, no-rate 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

list the content of tar.bz2 file

A

tar -tvf uploadprogress.tar.bz2

options specified? no? then rate 2
right extension of tar file, no-rate 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

extract a single file called cleanfiles.sh from cleanfiles.sh.tar

A

tar -xvf cleanfiles.sh.tar cleanfiles.sh

command arguments in same order or not? no -rate 3
options specified? no? then rate 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

extract a single file tecmintbackup.xml from tecmintbackup.tar.gz archive file

A

tar -zxvf tecmintbackup.tar.gz tecmintbackup.xml

command arguments(not options) in same order or not? no -rate 3
options specified? no? then rate 2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

extract a single file called index.php from the file Phpfiles-org.tar.bz2

A

tar -jxvf Phpfiles-org.tar.bz2 index.php

command arguments(not options) in same order or not? no -rate 3
options specified? no? then rate 2
j and respective z options are required here

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

extract or untar multiple files from the tar, tar.gz and tar.bz2 archive file

A

tar -jxvf Phpfiles-org.tar.bz2 “file1.xml”,” file2.xml”
tar -zxvf tecmintbackup.tar.gz “file1.xml”,” file2.xml”
tar -xvf cleanfiles.sh.tar “index.php” , “k2.php”

options specified? no? then rate 2
command arguments(not options) in same order or not? no -rate 2
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

extract a group of all files whose pattern begins with .php from a tar, tar.gz and tar.bz2 archive file

A

tar -jxvf Phpfiles-org.tar.bz2 –wildcards ‘.php’
tar -zxvf tecmintbackup.tar.gz –wildcards ‘
.php’
tar -xvf cleanfiles.sh.tar –wildcards ‘*.php’

options specified? no? then rate 2
command arguments(not options) in same order or not? no -rate 2
quotations and regex not correct, rate 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

add file xyz.txt and directory php to existing tecmint-14-09-12.tar archive file

A

tar -rvf tecmint-14-09-12.tar xyz.txt
tar -rvf tecmint-14-09-12.tar php

options specified? no? then rate 2
command arguments(not options) in same order or not? no -rate 2
quotations and regex not correct, rate 3
didnt identify which option for append, rate 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

add files or directories to an existing compressed tar.gz and tar.bz2 archive file

A

tar -rvf tecmint-14-09-12.tar.gz xyz.txt
tar -rvf tecmint-14-09-12.tar.bz2 php

options specified? no? then rate 2
command arguments(not options) in same order or not? no -rate 2
quotations and regex not correct, rate 3
didnt identify which option for append, rate 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
17
Q

check the size of any tar, tar.gz and tar.bz2 archive file

A

tar -czvf tecmint-14-09-12.tar.gz xyz.txt | wc -c
tar -cjvf tecmint-14-09-12.tar.bz2 php | wc -c

options specified? no? then rate 2
command arguments(not options) in same order or not? no -rate 2
quotations and regex not correct, rate 3
didnt identify which option for size check , rate 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
18
Q

see the actual content of that tar file

A

tar -tvf actualcontent.tar

options specified? no? then rate 2
right extension of tar file, no-rate 3
didn’t understand the question , rate 1
didn’t remember the right option, rate 1

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

create tar file in Unix with just specified contents

A

tar -cvf equitytrading.tar equity currency

command arguments(not options) in same order or not? no -rate 2
didn't understand the question , rate 1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
20
Q

view contents of gzip tar file

A

tar -ztvf trading.tgz

options specified? no? then rate 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
21
Q

know the size of tar file before creating it

A

tar -cf - * | wc -c

didn’t understand the question , rate 1
options specified? no? then rate 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
22
Q

How To Uncompress A Tar.Gz In Another Directory

A

tar xzf archive.tar.gz -C /destination

didn’t understand the question , rate 1
options specified? no? then rate 2

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
23
Q

Using tar -xzvf filename.tar.gz doesn’t extract the file. it is gives this error:

gzip: stdin: not in gzip format
tar: Child returned status 1
tar: Error exit delayed from previous errors

A

If file filename.tar.gz gives this message: POSIX tar archive, the archive is a tar, not a GZip archive.

Unpack a tar without the z, it is for gzipped (compressed), only:

mv filename.tar.gz filename.tar # optional
tar xvf filename.tar

didn’t understand the question , rate 1
options specified? no? then rate 2
don’t remember the solution, rate 3

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
24
Q

How to check if a Unix .tar.gz file is a valid file without uncompressing?

A

What about just getting a listing of the tarball and throw away the output, rather than decompressing the file?

tar -tzf my_tar.tar.gz >/dev/null

This test in no way implies integrity of the data. Because it was designed as a tape archival utility most implementations of tar will allow multiple copies of the same file!

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
How do I tar a directory of files and folders without including the directory itself?
``` $ mkdir my_directory $ touch my_directory/file1 $ touch my_directory/file2 $ touch my_directory/.hiddenfile1 $ touch my_directory/.hiddenfile2 $ cd my_directory/ && tar -zcvf ../my_dir.tgz * && cd .. ./ ./file1 ./file2 ./.hiddenfile1 ./.hiddenfile2 $ tar ztf my_dir.tgz ./ ./file1 ./file2 ./.hiddenfile1 ./.hiddenfile2 ```
26
What is the difference between tar and zip? What are the use cases for each?
tar in itself just bundles files together, while zip applies compression as well. Usually you use gzip along with tar to compress the resulting tarball, thus achieving similar results as with zip
27
How can you untar more than one file at a time?
find -iname \*.tar -exec tar -xvf {} \ if can't think of exec or xargs, rate 1
28
Untar a file in current directory or in a specified directory
tar xvfj file.tar tar xvfj file.tar -C path of file in directoy didn't understand the question , rate 1 options specified? no? then rate 2 don't remember the solution, rate 3
29
list only for the mentioned text or image from archived file.
tar tvf file.tar | grep "text to find" tar tvf file.tar | grep "filename.file extension" don't remember the command to use, rate 1 didn't understand the question , rate 1 --wilcards can't be used?
30
views the archived files along with their details like the file name that's archived in the given tar file
tar tvf file.tar filename don't remember the argument to use at the end, rate 1 didn't understand the question , rate 1
31
Viewing the Archive file.tar
tar tvf file.tar don't remember the argument to use at the end, rate 1 didn't understand the question , rate 1
32
Creating an uncompressed archive using tar command
tar cvf archive_name.tar dirname/ don't remember the options to use , rate 1 didn't understand the question , rate 1
33
make a tar file out of two specific files file1, file2 in a specified directory
``` $ ls abc def $ tar cvf compressed.tar abc def abc def $ ls abc compressed.tar def ``` if dont know that passing specified filenames is an option to tar only them, rate 1
34
Listing an uncompressed archive using tar command
tar tvf archive_name.tar didn't understand the question , rate 1 don't know listing imples option t, rate 1
35
Listing a compressed archive using tar command
tar tvfz archive_name.tar.gz tar tvfj archive_name.tar.bz2 didn't understand the question , rate 1 don't know listing imples option t, rate 1 don't know what compressed archive imples option t, rate 1
36
You cannot add file or directory to a compressed archive. If you try to do so, you will get “tar: Cannot update compressed archives” error
do u know this very well?
37
estimates the tar file size ( in KB ) before you create the tar file
tar -cf - /directory/to/archive/ | wc -c
38
Find all the files whose name is tecmint.txt in a current working directory
find -name techmint.txt /path/to/current/working/dir shouldn't be your answer The right answer is find . -name techmint.txt ``` -name option if not specified, rate 1 if doesnt strike that . = current working dir, rate 1 command arguments(not options) in same order or not? no -rate 2 ```
39
Find all the files under /home directory with name tecmint.txt
find /home -name techmint.txt if not specified the full file name with extensions, rate 3
40
Find all the files whose name is tecmint.txt and contains both capital and small letters in /home directory.
find /home -iname techmint.txt if not specified the full file name with extensions, rate 3 if not specified the i letter before name , rate 1
41
Find all directories whose name is Tecmint in / directory.
find / -name Techmint The question implies that techmint is the name for multiple directories, if dont understand this -rate 2 if any quotations are added, rate 4 coz its plain-no quotations
42
Find all php files whose name is tecmint.php in a current working directory
find . -type f -name techmint.php if missed the type -f option-it could bring in directories with such name too(possible)- rate 2 If don't watch out that the question only asked for files and not the directories- rate 1
43
Find all php files in a directory
find /path/to/dir -type f -name "*.php" If don't understand that its a wildcard or regex -rate 2 if don't put it in "", rate 2 if don't put along with the -name option, rate 1
44
Find all the files whose permissions are 777
find . -type f -perm 0777 -print if don't know that / means check all dirs in current dir, rate 1 if are specific that you want to print to std out like screen, rate 5
45
Find all the files without permission 777
find . -type f ! -perm 0777 -print if don't know that ! means a negation before an option, rate 1
46
Find all the SGID bit files whose permissions set to 644
find . -type f -perm 2644 if the first bit is set to 2 , sgid bit is set-dont know this rate 1
47
Find all the Sticky Bit set files whose permission are 551
find . -type f -perm 1551 if the first bit is set to 1 , sticky bit is set-dont know this rate 1
48
Find all SUID set files
find . -type f -perm /u=s if don't remember that -perm option is used, rate 1 if don't remember the argument to -perm userid set bit which is /u=s(set suid), rate 1
49
Find all SGID set files.
find . -type f -perm /g=s if don't remember that -perm option is used, rate 1 if don't remember the argument to -perm userid set bit which is /g=s(set sgid), rate 1
50
Find all Read Only files
find . -perm /u=r if don't remember that -perm option is used, rate 1 if don't remember the argument to -perm userid set bit which is /u(user)=r(read), rate 1
51
Find all Executable files
find . -perm /u=x if don't remember that -perm option is used, rate 1 if don't remember the argument to -perm userid set bit which is /a(any user or all )=x(execute), rate 1, use /u(user)=x rate 3
52
Find all 777 permission files and set permissions to 644
find . -perm 0777 -exec chmod 0644 {} /; If don't remember that -perm option is used, rate 1 if don't remember that -exec option is used, rate 1 if don't remember that {} '; syntax is at the end of -exec option, rate 1 If don't remember that -chmod option is used to set permissions, rate 1
53
Find all 777 permission directories and set permissions to 755
find . -type d-perm 0777 -exec chmod 0644 {} /; if don't note that the permissions are to be set for directories, rate 1 If don't remember that -chmod option is used to set permissions, rate 1 If don't remember that -perm option is used, rate 1 if don't remember that -exec option is used, rate 1 if don't remember that {} '; syntax is at the end of -exec option, rate 1
54
find a single file called tecmint.txt and remove it
find . -name techmint.txt -exec rm -rf {} /; If don't remember that -rm option for deleting or removing, rate 1 If don't remember that -perm option is used, rate 1 if don't remember that -exec option is used, rate 1 if don't remember that {} '; syntax is at the end of -exec option, rate 1
55
find and remove multiple files such as .mp3
find . -name "*.txt" -exec rm-rf {} /; if don't remember multiple files with a pattern has to be in " ", rate 1
56
find all empty files under certain path
find . -type f -empty if don't remember , -empty is an option , rate 1
57
find all empty directories under certain path
find . -type d -empty if don't remember , -empty is an option , rate 1 if don't notice the question is on directories , and use -type d , rate 1
58
To find all hidden files
find . -type f -name " .*" if don't remember that . is the pattern of the hidden file start-rate 1
59
find all or single file called tecmint.txt under / root directory of owner root
find / -type f -user root -name techmint,txt if don't remember that the option is -user ,rate 1 if the options are in wrong order, rate 3 if dont rememeber / corresponds to root dir, rate 1
60
find all files that belongs to user Tecmint under /home directory
find /home -user Techmint -type f if added any extra options like -name , rate 1 if the options are in wrong order, rate 3
61
find all files that belongs to group Developer under /home directory
find /home -group developer -type f If don't remember that the option is -group ,rate 1 if added any extra options like -name , rate 1 if the options are in wrong order, rate 3
62
find all .txt files of user Tecmint under /home directory
find /home -type f -iname "*.txt" -user Techmint if don't remember that the option is -user ,rate 1 if the options are in wrong order, rate 3 if dont rememeber / corresponds to root dir, rate 1
63
find all the files which are modified 50 days back
find . -type f -mtime 50 if don't remember that the option is -mtime ,rate 1 if have any + or - sign , rate 3,since asked just precise 50 days
64
find all the files which are accessed 50 days back
find . -type f -atime 50 if don't remember that the option is -atime ,rate 1 if have any + or - sign , rate 3 ,since asked just precise 50 days
65
nd all the files which are modified more than 50 days back and less than 100 days
find . -type f -mtime +50 -mtime -100 If don't remember that the option is -mtime ,rate 1 If don't remember that the option is -mtime should be used two times to specify range ,rate 1 f don't remember that the option is -mtime arguments have +, - signs ,rate 1
66
find all the files which are changed in last 1 hour
find . -type f -cmin 60 if confused with cmin and mmin, rate 3 if don't remember the cmin option, rate 1 if don't remember the arguments are in minutes count, rate 1
67
find all the files which are modified in last 1 hour
find . -type f -mmin 60 if confused with cmin and mmin, rate 3 if don't remember the cmin option, rate 1 if don't remember the arguments are in minutes count, rate 1
68
find all the files which are accessed in last 1 hour
find . -type f -amin 60 if confused with cmin and mmin, rate 3 if don't remember the cmin option, rate 1 if don't remember the arguments are in minutes count, rate 1
69
find all 50MB files
find / -type f -size 50M if don't remember the -size option, rate 1 if don't remember the option's argument needs to specify the unit of size, rate 1
70
find all the files which are greater than 50MB and less than 100MB
find / -type f -size +50M -size +100M If don't remember that the option is -size ,rate 1 If don't remember that the option is -size should be used two times to specify range ,rate 1 f don't remember that the option is -size arguments have +, - signs ,rate 1 if don't remember the option's argument needs to specify the unit of size, rate 1
71
find all 100MB files and delete them using one single command
find / -type f -size 100M -exec rm -rf {} /; if don't remember the -size and -exec for deleting -rm, rate 1
72
Find all .mp3 files with more than 10MB and delete them using one single command
find / -type f -name "*.mp3" -size +10M -exec rm -rf {} /;
73
``` Symbol 1 f 2 d 3 b 4 c 5 p 6 l 7 s ```
``` Type Regular file Directory file Block file Character file Pipe file Symbolic link file Socket file. ```
74
Search for all the files whose StickyBit is set
find / -perm /o=t if dont know o means others and t is for sticky, rate 1
75
Search for all the files whose owener permissions is read only
find / -perm /u=r if don't know u means owner and r is for read pnly , rate 1
76
Search for all the files which have user, group and others with executable permissions
find / -perm /a=x if don't know a means owner, user and all others and x is for execution , rate 1
77
want to get all the files which are created later this file creation newer.txt .
find / -newer newertxt need to know that -newer is an option, rate 1 if no
78
Search for files whose size is more than 10bytes
find / -type -f -size +10c if don't now that c is used for bytes notation of size in units, rate 1
79
Search for files which are exactly 10kb in /opt folder
find /opt -type -f -size 10k if don't now that k is used for kilo bytes notation of size in units, rate 1
80
find all the empty files in my system
find /opt -type -f -size 0k if don't now that k is used for kilo bytes notation of size in units for empty files too , rate 1
81
Search for files which are more than 1GB size in /usr folde
find /opt -type -f -size +1G if don't now that G is used for giga bytes notation of size in units, rate 1
82
Find all the files with SGID for the group sales and with size exactly 100MB with file name as pass.txt under /opt.
find /opt -size 100M -group sales -perm g+s -name pass.txt
83
Find all the files which are more than 100MB and less than 1GB in size.
find / -size +100M -size -1G if don't know to put appropriate units near the -size's argument, rate 2
84
: find a file with passwd.txt in /var folder and long list this file for checking file properties
find /var -iname passwd.txt -exec ls -l {} ; if dont remeber long listing option is for ls , rate 1
85
Find all the files with name test.txt in /mnt and change the ownership of the files from Surendra to Narendra
find /mnt -type f -name test.txt -user Surendra -exec chown Narendra {} \; if don't remember that exec needs to be used, rate 1 if don't remember that chown needs to used with exec to do modifications on the found files, rate 2 if added extra options with chown, rate 3
86
finding a file with inode number
find /mnt -type f -inode 23 if don't remember the inode number , then rate 2
87
Find all the files with name test.sh in /abc folder and then grep if for word is there in that file or not
find /abc -type f -name test.sh -exec grep "for" {} \;
88
Find all the files with name xyz.txt owned by Surendra in /var/ftp/pub and change the permissions to 775 to them.
find /var/ftp/pub -type f -name xyz.txt -user Surendra -exec chmod 775 { } \; make sure you have included all the filter options, rate 4 if missed
89
Find all the files with name temp.txt in /xyz folder and backup then compress them to send it for saving
find /xyz -type f -name temp.txt -exec tar -cvfz backup.tar.gz {} /; any small obvious mistake , rate 1
90
Find files with name abc.txt in /home directory and take backup of each file before modifying it
find /xyz -type f -name temp.txt -exec cp {} {}.bkf /; If doesn't strike to use cp command, rate 1 if don't remember that cp follows w=by the current path of the file represented by {} in -exec command , rate 1 If don't remember the cp syntax, rate 1
91
Find all the files with executable permissions and display their checksum value
find /con -type f -perm /a=x -exec -md5sum {} \; if don''t remember that md5sum is the command for the checksum, rate 1
92
Find all the files with name abc.txt and owner as surendra then move them to /opt folder
find /com -type f -name abc.txt -user surendra -exec mv {] /opt/ \; If doesn't strike to use mv command, rate 1 if don't remember that mv follows by {}. rate 1 the current path of the file represented by {} in -exec command , rate 1 If don't remember the mv syntax, rate 1
93
Find files with abc.txt name in /opt directory change the owner permissions from Surendra to Narendra and change the permissions to 775
find /com -type f -name abc.txt -user surendra -exec chown Narendra \; -exec chmod 775 \; If you don't remember that We can use this multiple -exec option more than two times, rate 2
94
Find abc.txt file in /opt and /var folder at a time
find /opt /var -name abc.txt If you don't remember that two locations can be specified side by side, rate 2
95
Search multiple locations but not in particular location. Find abc.txt file in /opt and /var folder at a time, Search in entire system expect /proc folder
find /opt /var -path /proc -prune -name abc.txt if don't remember this - The -path variable to define the path of a location. And -prune combined with -path will say not to descend in to the mention path /proc- rate 1
96
search for abc.txt and hash.c file at a time
find /opt /var -name abc.txt -o -name hash.c if don't know that the -o should be followed by the specific previous option , rate 3 if don't know h=that -o option should be used to find for something together, rate 1
97
find two directories say opt and var how can i find them
find . -type d -name opt -o -type d-name var if don't understand the question, rate 1 if doesn't strike that its type d option, rate 1
98
Finding files only in the current directory not searching on subdirectories
find . -maxdepth 1 -type f -newer first_file if don't remember the maxdepth option, rate 1
99
find all of the symbolic links in your home directory, and print the files your symbolic links points to
find . -type l -print0 | xargs -o ls -ld | awk '{print $10}' 10th field has the actual link pointing, remember if forgot, rate 3 if forgot about the awk syntax, rate 2 if forgot about symbolic links , rate 1
100
always use find -print0 along with xargs -0 if you see slightest possibilities of file names containing space in UNIX or Linux
know this or not
101
/bin for what
executable files
102
/ for what
root dir
103
/etc
config files
104
/tmp for
only temporary files, they clear during boot time
105
/opt for
installing software not bundled with os
106
/var for
log files created by programs and applications
107
/cdrom for
mount point for files on cdrom
108
/media for
mount point for cdrom and dvd
109
/srv for
web files, ftp server files /srv/ftp
110
/opt/avg/bin
executable files
111
/etc/opt/myapp
configuration files
112
/var/opt/myapp
log files
113
long listing of files and dir
ls -l
114
long listing of hidden files
ls -la
115
listing of only files not directories
ls -F @ link / dir * binary executables
116
how to execute a binary execuatable file
./binaryfilename
117
listing of files with time
ls -t
118
listing of files recursively
ls -R
119
listing of directories only
ls -d
120
ls -R alternative is
tree
121
listing of files in revers order, can this command be confused with anything elsr
ls -r yes with ls -R which is a recursive listing not reverse listing
122
directory structure
tree -d | tree - c to colorize output
123
listing with colorized output
ls --color
124
edit a file using editor
vi filename
125
modes of vi
3 | command, insert, line
126
get into vi command mode by
ESC key
127
get into vi insert mode by
i - to insert right at after the cursor
128
in vi insert mode, to append right after cursor is
A
129
in vi insert mode, to append at the beginning of the line is
a
130
in vi insert mode, to insert at the beginning of the line is
I
131
what are the navigation commands in command mode
h left j down k up l right
132
how to get into line mode in vi
type : followed by the command
133
to save writes in line mode
:w
134
to force save writes in line mode
:w!
135
to quit in line mode
:q
136
to force quit in line mode
:q!
137
to save writes and force quit, its alternative also in line mode
:wq! :x
138
navigating through lines in line mode, to position cursor at line n
:n
139
navigating through lines in line mode, to position cursor at the line end
:$
140
navigating through lines in line mode, to turn on line numbers
:set nu
141
navigating through lines in line mode, to turn off line numbers
:set nonu
142
navigating the command mode, to delete a character
x
143
navigating the command mode, to delete a word
dw
144
navigating the command mode, to delete a line
dd
145
navigating the command mode, to delete from current position
D
146
navigating the command mode, to change current character
r
147
navigating the command mode, to change current word
cw
148
navigating the command mode, to change current line
cc
149
navigating the command mode, to change from current position
C
150
navigating the command mode, to change case of a charecter
~
151
copy a word in command mode vi
yy
152
in command mode vi , copy 3 words
y3w; y
153
in command mode vi, paste the copied or deleted word
p
154
in command mode vi, undo
u
155
in command mode vi, redo
Cntrl+ R
156
to search in vi, line mode- forward searching
/pattern ( n for next, N for previous match)
157
to search in vi, line mode- backward searching
? n for next, N for previous match
158
Display current running processes
ps
159
Display current running processes not owned and running as you
ps -e
160
Display the full format of the process
ps -f
161
Display process running on root
ps -u root
162
Display process details of process 123
ps -p 123
163
Display process tree
ps -e --forest | pstree
164
Interactive process view
top
165
What are environment variables for
they specify storage location and has a name and a value, they affect the way programs behave
166
the command to know all the environment variables
printenv
167
List few names of environment variables
TZ,HOME,PATH
168
another way than printenv to print the contents of environment variables are
echo $ENVIRONMENT VARIABLE NAME($HOME)
169
Create an environment variable name VAR with a value -value
export VAR='value'
170
Update an environment variable EDITOR to vi | and TZ environemnt variable to 'US/Pacific'
export EDITOR="vi" | export TZ="US/Pacific"
171
Remove environment variable TZ to revert it's value to default
unset TZ
172
Does an unset and export command persist changes between logins?
No,
173
How to persist changes in environment variables between logins
vi .bash_profile ``` insert mode, go to the end export TZ="US?Pacific" :wq! exit login to shell printenv TZ or echo $TZ ```
174
what is the pager utility to print output upto the screen fit
pipe the output to less command
175
How to tell if a particular program or an application is using a particular environment variables
man commandname will display the man pages with a section on environment variables
176
command for background process
&
177
what to do to kill a foreground process like: | sleep 300
Cntrl + C
178
what to do to suspend a foreground process like: | sleep 300
Cntrl + Z
179
How to foreground a background process
fg %jobid ;fg %3
180
How to background a running foreground process
bg %jobid; bg (will background the latest process evoked)
181
How to kill a job
``` kill %jobid; kill %3 kill pid; kill 103458 kill -TERM pid; kill -TERM 123 kill 15 123 kill -9 123 (9 kill signal) ```
182
what is kill's kill signal
9
183
what is kill's termination signal
15
184
what is signal 15's in kill, it's also used interchangebaly
-TERM
185
command to list all the jobs
jobs
186
command to list job details of a job with id 1
jobs %1
187
command to list the current job(recent /latest job id)
job %+
188
command to list the previous job id
job %-
189
what in unix helps to do time based job scheduling
cron services
190
Tell more about cron services
cron job starts when the system boots, it performs routine maintenance and it automates a process
191
syntax of thecrontab command
``` min hr dom month dow /path/to/the/executable/file min(0-59) hr(0-23) (dom= day of the month) (1-31) (dow=day of the week)(0-6) ```
192
schedule a cron job located at /opt/sales/bin/weekly-report every monday at 7 pm
min hr dom month dow | 0 19 * * 1 /opt/sales/bin/weekly-report
193
perform a half hourly check
``` 0,30 * * * * /opt/sales/bin/weekly-report */2 * * * * /opt/sales/bin/weekly-report ```
194
perform a check every first 5 min of the hr
0-5 * * * * /opt/sales/bin/weekly-report
195
Perform a cron job annually
0 0 1 1 * /opt/sales/bin/weekly-report
196
Perform a cron job weekly
0 0 * * 0 path/to/the/executable/file
197
Perform a cron job monthly
0 0 1 * * path/to/the/executable/file
198
Perform a cron job daily
0 0 * * * path/to/the/executable/file
199
Perform a cron job hourly
0 * * * * path/to/the/executable/file
200
What command manipulates cron jobs
chrontab command
201
command to install a cron job from file
crontab file
202
command to list cron jobs
crontab -l
203
command to edit cron job files
crontab -e (should open ur favrt editor: set an environment variable)
204
command to remove all your cron jobs
crontab -r
205
how to create a cron job
1) open a vi editor with the file name => vi my-cron 2) in insert mode type 07 **1 /opt/sales/bin/weekly-report 3) :wq! 4) install the file with crontab command => crontab my-cron 5) echo $ EDITOR 6) export EDITOR =vi 7) crontab -e to do any edits
206
command as a way to start a session as another user is
su
207
how to start a session as root user
su with no arguments
208
execute a command by starting a session as a root user
su -C command; su -C ls -l
209
command to know the what is the current user in our session
whoami
210
how to stay with the same environment while switched as a user
su oracle ( with out - before the user name )
211
how to change to the user's environment while switched as a user
su - oracle (with the - and space followed by a username)
212
command to switch user to obtain privileges and security of super user
sudo
213
Does sudo prompts for a password?
yes
214
list of available commands as superuser switching
sudo -l
215
to execute a command as privileged user sqoop
sudo -u sqoop command
216
to execute a command as privileged user sqoop and also switch to the users environment
sudo su - sqoop command
217
command to start a shell as root
sudo -s
218
command to start a shell as sqoop
sudo -u sqoop -s
219
command to modify sudo configurations
sudo visudo
220
command to copy files from one local machine to linux server
scp source destination scp z.txt linuxserver(hostname):~ (~ shortcu for hoe dir)
221
command to copy files from one local machine to linux server interactively
sftp linuxserver pwd ls lpwd # local path to directory lls # local list files put z.txt ls rm z.txt quit
222
Transfer this z.txt file as different user: adminuser
scp z.txt adminuser@linuxserver:/home/adminstration or sftp adminuser@linuxserver pwd ls lpwd # local path to directory lls # local list files put z.txt ls rm z.txt quit
223
command to find difference between contents of file 1 AND file 2
diff file1 file2
224
explain the output of diff file1 file2 command : 3c3
file1lineno change - c file2lineno
225
if the difference between two files is addition of txt at the 8th line then o.p of diff file1 file2 would be
4a4
226
if the difference between two files is addition of txt at the 8th line then o.p of diff file1 file2 would be 4a4, Now to see what line was added and the diff the command woud be
sdiff file1 file2 or vimdiff file1 file2 (to view ffiles in two diffent windows) | symbol for differing lines > lines exist only in 2nd file < lines exist only in 1rst file
227
To quit seeig both the file windows using vimdiff command then
:qa!
228
To quit seeing both the file windows using vimdiff command then
:q
229
Command to remove file
rm file
230
command to reove directory
rm -r -dir
231
command to copy a lift of files to /home
cp file1 file2 /home
232
command to copy files into a dir that doesnot exist
cp -r file /newdir
233
command to move or rename files
mv source destin
234
command to sort file based on the field no
sort -k 10 # 10 is field no
235
command to sort file in reverse order
sort -r
236
command to sort file uniquely
sort -u
237
command to know the disk space used by a file in kilobytes
du -k
238
command to know the disk space used by a file in human readable format
du -h
239
if u have to gzip a dir by checking it's file usage on disk
du ``` then gzip then check du then tar gzip and view contents of the tar gzip file ```
240
When you login you get “$” prompt, what is the prompt for root?
#
241
Explain the difference between grep and egrep?
egrep is to search for multiple patterns with pattern having a pipe character eg: egrep "PATTERN1|PATTERN2" FILE grep is for searching patterns as a string, any special characters are needed to be escaped eg: grep "PATTERN1\|PATTERN2" FILE
242
What are the mostcommon Linux command line tools for parsing files.
grep, egrep, sed, awk
243
get a list of all email address with grep
$ grep -E -o "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b" file.txt
244
Parse a file and print all expressions that match a range between 0.0.0.0 and 999.999.999.999.
grep -E -o "([0-9]{1,3}[\.]){3}[0-9]{1,3}" file.txt
245
What is the port # for DNS, NTP and NFS?
53, 123 and 111/2049
246
What is the configuration file name of DNS and where is it located? /etc/named.conf
All configuration files are located in /etc directory and the name of the DNS configuration file is named.conf. /etc/named.conf
247
How many new directories will be created after running the following command mkdir {a..c}{1..3}
9
248
Your PC is configured with a DNS server address but not the default gateway. Can the PC access internet?
No
249
Can you assign one static IP to 2 computers, if not then why?
No because it will create IP conflict
250
You are trying to ping a server by hostname and you get an error message, “ping: unknown host …”. What could be the reason and how to solve the problem so you can ping it by hostname?
Check for /etc/hosts or DNS to see if it has hostname to IP entry
251
Explain the difference between relative and absolute path?
Absolute path starts from / where relative path is your current directory
252
List 3 different methods of adding user?
1) The adduser command automatically creates a home directory and sets the default group, shell, etc. To create a new standard user with the adduser command the syntax is as follows: sudo adduser bob 2) Anytime you add a user, that user is added to the passwd file,You can edit the file directly or use the commands we will go over shortly - useradd roman 3) useradd bob passwd
253
What is the command to change file/directory ownership and group?
chown and chgrp
254
List any 3 type of filesystem?
ext4, NTFS FAT
255
What is /bin directory used for?
A user of an operating system can expect to find executable files in binary.
256
How to change a user password?
passwd username
257
How to logoff from the system?
exit
258
Give any 3 examples of operating systems?
Windows, Linux and MAC
259
List any 4 linux distributions?
Redhat, CentOS, Ubuntu and SUSE
260
How to create a directory?
mkdir
261
Where are the zone files located for DNS service?
/var/named/zonefiles
262
How to check kernel version?
uname –a
263
Which directory has all the configuration files?
/etc
264
How to become root user from a regular user?
su –
265
What is the purpose of having different network ports?
So the communication of each application goes through a dedicated port
266
How to display first column of a file?
cat filename | awk ‘{print $1}’
267
What is the name of DNS rpm package?
bind
268
How to check a file’s permission?
ls –l
269
What is the difference between “kill” and “kill -9” command?
kill will create a sigterm signal. kill -9 willforcefull kill the process
270
You are troubleshooting an issue with Redhat support and they have asked you to send the contents of /etc directory. How and which method you will use to transfer the contents?
tar (compress) the entire /etc directory and sftp or scp
271
What is root home directory?
/root
272
How to check the computer name or host name in Linux?
hostname
273
Which permission allows a user to run an executable with the permissions of the owner of that file?
First 3 bits should have x
274
What is the command to untar a tarred file?
untar
275
What is /proc directory used for?
1) provides a method of communication between kernel space and user space. 2) the process reporting utility ps uses the proc file system to obtain its data, 3) special filesystem in Unix-like operating systems that presents information about processes and other system information in a hierarchical file-like structure
276
List 3 basic commands to navigate the filesystem?
cd, pwd and ls
277
Which service/daemon should be running on the server that allows you to connect remotely?
sshd
278
What is the purpose of firewall?
1) it provides a barrier to control network traffic both into and out of an organization’s Internet-connected network, or perhaps between different segments of an internal network. 2) companies can configure multiple firewalls inside their corporate network to essentially divide the network into multiple segments. That helps contain the damage should some form of worm or other malware be unleashed in any given segment.
279
List any 3 IT components?
Hardware, OS and Applications
280
What is the difference between memory, virtual memory and cache?
virtual memory: memory in db server or any virtual machine memory cache: active memeory sits between cpu and memory physical memory: memory
281
Which directory has all the commands we use, e.g. ls, cd etc.?
/usr/bin or /bin
282
Which of the following is a communication command?
o grep o mail this one o touch o cd
283
How to rename a file or directory?
mv
284
How to change a hostname in Linux?
sudo nano /etc/hosts | sudo nano /etc/hostname
285
How to check network interfaces in Linux?
ifconfig
286
What command used most often to output all incoming logs in real time
“tail –f logfilename”
287
How to sort a file in reverse order?
cat filename | sort –r
288
What is the name of operating system that runs Unix?
Solaris, HP-UX etc
289
List all byte sizes from smallest to largest?
bytes, kilobytes, megabytes,gigabytes,terabytes
290
How to check the total number of partition in Linux?
fsdisk -l
291
How to access a linux system from a linux system?
ssh
292
What is the exact command syntax to list the 5th column of a file and cut the first 3 letters?
cat filename | awk ‘{print $5}’ | cut –c1-3
293
What is /etc/hosts file used for?
To resolve hostnames with IP address
294
List any 3 options of ‘df’ command and what they are used for?
df -h df -x tmpfs to exclude certain filesytem types df -t ext4 list only specific file system types df -T To show the file system type pass the -T option
295
What is the command to change file/directory permissions?
chmod
296
What is the purpose of pipe (|)?
To combine multiple commands
297
What is /etc directory used for?
For configuration files
298
Which command is used to list files in a directory?
ls -l
299
There is a command which gives you information about other commands, please explain that command and what is it used for?
man
300
How to delete a file and a directory?
rm filename and rmdir dirname
301
What is the difference between “tail” and “tail -10”?
None
302
List 4 commands to display or read a file contents?
cat, more, less, vi
303
Which command is used to read the top 5 lines of a file?
head -5 filename
304
What are the different commands or methods to write to a file?
echo > filename and vi filename
305
What is swap space and how to check swap space?
top command shows swap space, swap space is the amount of memory reserved for a process which is equivalent to amount of memory assigned to the process by the kernel., when the physical memory passes its threshold then the swap space is activated,the inactive
306
What is inode and how to find an inode of a file?
1) An inode is simply an internal data structure that Linux uses to store information about a filesystem object 2) ls -id /path/to/dir ``` i = inode d= directory ```
307
Which file to edit for kernel tuning?
1) /etc/sysctl.conf you can configure various Linux networking and system settings
308
Name the command to find specific word from a file?
grep word filename
309
You have scheduled a job using crontab but it does not run at the time you specified, what could be the reason and how would you troubleshoot?
Check your system time Check your crontab entry Check /var/log/messages
310
How to check network interface MAC address?
ifconfig
311
If I don’t want others to read my file1, how to do that?
Remove r from the last 3 bits of file permission
312
What is the purpose of “uniq” and “sed” command?
1) uniq authors.txt, uniq command is of showing a count of occurrences, showing only repeated lines and ignoring characters and specific fields. uniq -c authors.txt To output the number of occurrences of a line use the -c uniq -d authors.txt This will output only lines that occur more than once and write the result to standard output In summary the purpose of uniq is to parse data a 2) sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline). ``` for eg: the input file is Tom Westley Essex Ravi Bopara Essex Marcus Trescothick Somerset Joe Root Yorkshire Jonny Bairstow Yorkshire ``` uniq -f 2 -c cricketers.txt | sed 's/^\s*//' | cut -d ' ' -f 1,4 2 Essex 1 Somerset 2 Yorkshire To ignore fields in a comparison pass the -f option to uniq. This will run the comparison on the specified field and output the result to standard output. ^/s* zero or more occurences of space is replaced by1 single space " " to make a solid delimiter for cut command The cut command in UNIX is a command line utility for cutting sections from each line of files and writing the result to standard output. In summary, the sed and uniq command are for data transformation.
313
Which command is used to list the contents of a directory in the most recent time and in reverse order, meaning the most updated file should be listed on the bottom?
ls –ltr explanation: ls -ltr : - t option will sort the entries by modification date (with newest first) - r will reverse the sorting order. As -t will sort by modification time with newest first, -r will cause the reverse i.e. oldest entries will be shown first now.
314
What is the difference between tar, gzip and gunzip?
Tar is a file archiving technique and it combines mulitple files to a single archive file gzip is to compression technique to compress a file which has large file gunzip is to decompress the compressed file that was compressed using the gzip technique
315
How to view difference between two files?
diff file1 and file2
316
Run a command that shows all lines except any lines starting with the character # in a file
grep -v "^#" filename
317
What is the difference between .bash_profile and basharc
.bash_profile is executed when newly logged in to the shell session. .basharc is executed when already logged in but opened a new trminal
318
The difference between $ and # prompts on CLI
$ prompt is for users and # prompt is for root
319
How to create a file
touch ,vi
320
Default port number of DNS
53
321
name of DNS package name
bind
322
configuration file for DNS location
/etc/named.conf
323
List 3 type of filesyste
ext3,ext4, xfs,fat,ntfs
324
list any 4 unix flavors
fedora ubuntu redhat suse
325
hw to find filetype of a file
file filename
326
how to check files permission
ls -l
327
command to find your current directory
pwd
328
how to log off from linux system
exit
329
how to check if a package is installed
for eg to check if DNS package is installed rpm -qa | grep bind
330
to check all previously typed commands
history
331
how to check where passwd command is located
which passwd
332
how to list all the commands
ls /usr/bin
333
how to check ip and ac address
ifconfig -a
334
How to count no. of lines in a file
wc -l filename
335
where is the network time config file located
/etc/ntpd.conf
336
how to reboot a linux system with init command
init 6
337
when is the last comand used
to show last logged in users
338
Can't write to hard disk on the linux systems?
1) Run the df command to find out info about the total space and available space on a file system including partitions 2) Locate the filesystem that has unusually high usage 3) When the disk is full, du on the /var/logs and tar the files where the directory is large on du 4) compress the tar files either usng gzip or bzip technique. 5) Delete unwanted files using rm , and unwanted directories using rmdir 6) Move files to other systems or external hard disk rsync --remove-source-files -azv /ftp/tmp/*.log /mnt/usbdisk/ rsync --remove-source-files -azv /ftp/tmp/*.log server2:/path/to/the destination/directory 7) find largest dir or files eating disk space on unix system du -a /ftp/tmp | sort -n -r| head -n 10 8) locate those largest files and truncate the largest files on unix/linux truncate -s 0 /ftpuser/ftp.log 9)find and remove large files that are open but have been deleted on unix lsof -np | grep 'deleted' 10) Check if you are running out of inodes, coz most likely when 1000's of small files are created on a dir, the ifilesystem runs out of inodes. To check this out we can use du -i /dirname/filename.ext if 100 % of inodes are used, we need to find the unwanted files and delete them after transfering them to different server or mount point using rsync command 11) du -hs points to the biggest directory and points to what needs cleaning up
339
Why getting disk full messages on the screen?
1) Run the df command to find out info about the total space and available space on a file system including partitions 2) Locate the filesystem that has unusually high usage 3) When the disk is full, du on the /var/logs and tar the files where the directory is large on du 4) compress the tar files either usng gzip or bzip technique. 5) Delete unwanted files using rm , and unwanted directories using rmdir 6) Move files to other systems or external hard disk rsync --remove-source-files -azv /ftp/tmp/*.log /mnt/usbdisk/ rsync --remove-source-files -azv /ftp/tmp/*.log server2:/path/to/the destination/directory 7) find largest dir or files eating disk space on unix system du -a /ftp/tmp | sort -n -r| head -n 10 8) locate those largest files and truncate the largest files on unix/linux truncate -s 0 /ftpuser/ftp.log 9)find and remove large files that are open but have been deleted on unix lsof -np | grep 'deleted' 10) Check if you are running out of inodes, coz most likely when 1000's of small files are created on a dir, the ifilesystem runs out of inodes. To check this out we can use du -i /dirname/filename.ext if 100 % of inodes are used, we need to find the unwanted files and delete them after transfering them to different server or mount point using rsync command 11) du -hs points to the biggest directory and points to what needs cleaning up
340
how to solve full/corrupt or failed disk issues?
1) Run the df command to find out info about the total space and available space on a file system including partitions 2) Locate the filesystem that has unusually high usage 3) When the disk is full, du on the /var/logs and tar the files where the directory is large on du 4) compress the tar files either usng gzip or bzip technique. 5) Delete unwanted files using rm , and unwanted directories using rmdir 6) Move files to other systems or external hard disk rsync --remove-source-files -azv /ftp/tmp/*.log /mnt/usbdisk/ rsync --remove-source-files -azv /ftp/tmp/*.log server2:/path/to/the destination/directory 7) find largest dir or files eating disk space on unix system du -a /ftp/tmp | sort -n -r| head -n 10 8) locate those largest files and truncate the largest files on unix/linux truncate -s 0 /ftpuser/ftp.log 9)find and remove large files that are open but have been deleted on unix lsof -np | grep 'deleted' 10) Check if you are running out of inodes, coz most likely when 1000's of small files are created on a dir, the ifilesystem runs out of inodes. To check this out we can use du -i /dirname/filename.ext if 100 % of inodes are used, we need to find the unwanted files and delete them after transfering them to different server or mount point using rsync command 11) du -hs points to the biggest directory and points to what needs cleaning up
341
One application is connected to 30 Databases using DB connect, there is also a pool limit user , and when that exceeds, the error is pooped us saying pool limit user exceeded or error establishing DB connection .How to trouble shoot it and what causes it ?
1) It happens when the query execution time exceeds the normal time 2) There will already by some shell scripts created by primary admin or system admin. 3) So, whenever the application is down, run the scripts 4) if the scripts don't work, accelerate the issue either to the system admin or the server admin 5) Sometimes the script requires to pass arguments to the scripts, we can either go and edit certain part of the script using the vi editor
342
How to pass arguments to the script just before execution?
./shellscript.sh argument1 argument2 argument3 2 "Newyork"
343
How to know the total number of arguments specified to the script
$# wil output the number of arguments specified to the script
344
What is shebang?
Shebang is a pound symbol followed by an exclamation #! This syntx is used in scripts to indicate an interpreter for the execution under linux/unix os for eg #!/bn/bash would mean the shell script should be executed with the bash interpreter #! /usr/bin/prl meaning it should execute using the interpreter specified on a first line
345
what is the difference between sh script and ./script
1) Both are used to execute the script 2) Howewer sh scriptname will make it execute under sh 3) ./ could execute under bash/perl/sh/etc whatever interpreter specified in its shebang line
346
How to tackle out of meory alert and why it occurs?
Each process is allocated some java heap size for eg 3gig has been alloted to one process However a user has started downloading a 600 MB excel file and now the process is taking 4GB RAM , then that particular process throws out of memory exception, since it's demanding more than what's allocated to it. The ways to troubleshoot this issue is: 1) If we have a shell script to auto-restart the process, we will go ahead and run it 2) If the process hangs, we will kill it or teminate it
347
Some unexpected behavior on the server side may at times causes real resource outage issues. process crucial to your web application was killed as a result of out of memory situation. How do you troubleshoot it.
We have couple of options 1) Reduce amount ofmeory asked by the process 2) Disallow process to overcomit memory 3) Simply add more memory to the server configuration > A useful memorymonitoring tool is the top command > If your system memory gets used up to the extent that it can threathen the system stability, the out of memory killer will choose which process to terminate or eliminate and linux keeps a score for each running process for this purpose and it's called oom score and this score is stored in the file /proc//oom_score ps aux |grep processname will give the processid cat /proc/pid/oom_score can give the score, higher the number more likely its can be eliminated. >Now to change the overcommit mode if the system is at risk of running out of memory, sudo sysctl -w um.overcomit_memory=2 2 meaning if system doesnt have meomry it will not overcommit other options include 1 to always allow 0 estimate if we have enough RAM
348
How to know what process runs on which port
sudo netstat -tunlp | grep 8080 t = tcp u =udp n= numerical display of addresses ,ip and ports l=list only listening ports p=show processid and name of the program to which the socket belongs
349
List what files are being used by port 80
sudo lsof -i :80
350
Find process nae associated with the pid
ps -p 2212 -o -comm= or ls -l /proc//exc
351
display the working directory of a process with the pid 123
pwdx 123
352
To understand what the command is about
whatis pwdx
353
What is the difference between ssh and telnet
both are used to connect remotely to the other servers remotely However, ssh is encrypted version of telnet - telnet sends data in plain text, if the usecase is for fast protocol,telnet is the choice if the usecase if for security, ssh is the choice-its a slow protocol due to encryption.
354
Can you troubleshoot what may be causing a connection issue when trying to connect remotely ?
1) During establishing connections to other computers firewall issues may be encountered 2) So we need to make sure that port is open in the firewall to listen 3) So wen use telent command to test ports opened or closed on a remote server as follows: telnet domainnameorIP port eg. telnet adminuser@google.com 80 Due to security issues of transferring data in plain text most use ssh 4) We can use ping to know if the ip or port are active, but most likely this will be disabled 5) After port issue is established, another issue that can be causing this is ip restriction ifconfig is to query network interface parameters, using this we can figure out if the ip address is resolved with the particular hostname
355
The system is in trouble , how will you troubleshoot?
Will continuously monitor log files for errors, this way I can keep tabs on the live feed of data coming into the log file : var/log/messages tail -f /var/log/messages AND use Cntrl C to exit
356
Which is the file where we an go and look for errors
/var/log/messages
357
When it's a really large file particularly because the system is on over the years, which command will u use to view the recently written data
I will not use cat command as it can potentially hang the system I will use the tail -f /varlog/messages
358
How to remove files older than 7 days by creating cronjob to run everynight
vi filename | 0 0 * * * /bin/find -mtime +7 -exec rm -rf {} ;/
359
How to list all the created users in the system and send the in a file
tar -cvf users.tar /etc/passwd | awk '{print $1}' >file.ext tar -cvf users.tar /etc/passwd | cut d ':' -f 1 >file.ext sftp file.ext server2:/destination/dir
360
How would you create a file or how to print out the first column of the first field
touch or vi used to create a file, | awk and cut can be used to pront out the first column
361
Someone needs data from a file which is really large but only need second column from a file ? how will u do thi
cut -d ' ' -f 2
362
system is about to go down due to some emergency that happened, probably a hack, so it needs to be booted, how to broadcast a message to all the logged in users
wall -n "server is going down in 15 mins"
363
How to create a user with no login access because there is an aplication that need a usr account but does not require access to login to a s/m
useradd -s /sbin/nologin username then su username to check
364
Schedule server reboot in 15 minutes
shutdown -r 15
365
Schedule server reboot immediately
shutdown -r now
366
Schedule server reboot at 11 pm
shutdown -r 23:00
367
How to find disk usage by the largest directory
this can be troubleshooted by checking disk space pertaining to a particulr user or by particular directory and sub directories pwd /var du -Sh | sort -n | less S is for searching disk space for directories
368
How to prevent users deleting other users files in a directory
This question is pointing towards special permissions that are called sticky bit chmod 1777 hist/
369
how to display the 10th line of a file only
cat filename | head -n 10 | tail -n 1
370
the server got damaged as it got hacked , due to the amount of damage the whole server needs to be restored. How would you go about doing that?
There are two parts in this question: Vmware and physical server 1) If I am using VMware and ther is a complete copy of that disk, VM has a tool in it that captures the ystems state off a particular system or depending on which date it's capturing from , you can completely redo the system from that particular date. we can restore it from the system state if VMware has saved it to some kind of capture tool that captures the whole system and deploys that image for that system 2) If it's the physical server , then only the data gets backedup , also some config files can be restored not all. We can restore the entire OS just from the back up and use the data from the back up taped device Config files are restored in /etc files So to summarize , we create a new system, get all the data from the back up and throw them on your new system.
371
To update packages in the server
yum update
372
to remove the package
yum remove packagename
373
Command to disable service
service servicename stop
374
What is the difference between linux and unix
Unix was primarily developed with multi tasking and multi users in ind, unix cannot be installed on any hardware. Where as linux can be installed in almost many hardwares and supports may flavors of file system, whereas unix supports only fewer filesystems.
375
What is linux
Linux is an operating system sits between hardware and users
376
Difference between linux and windows
free not free not user friendly userfreindly very secure not so secure very open to public can modify ur own changes Not an open surce os, cannot open the code or reveal to anyone Best for multi tasking multi tasking requires high cpu and mem
377
To list all the available ips or interfaces that u have on your system
ifconfig command is deprecated, | ip addr
378
What is a filesystem.
A filesystem is something similar to your closet at your hoe. Think of each shelf with specific kind of storage. One folder has only programs or applications, another folder have only attaced devices, so it will be much easier for the operating system to access the files, ``` There are different types of filesystems: 1)ext3 ext4 FAT NTFS XFS ```
379
what command to use to creata ultiple files in a directory
touch command eg: touch mart lisa tex
380
what command to use to create multiple files in a directory
touch command eg: touch mart lisa tex
381
what command to use to create multiple directories in a directory
mkdir dir1 dir2
382
Tell me what kind of file starts with c
if any eboard of mouse is attaches, then that file starts with c
383
Tell me what kind of file starts with p
named pipe file starts with p
384
Tell me what kind of file starts with b
block device starts with b
385
What are the commands to file diles and directories in a system
find and locate
386
How to create files with one command using wildcards
touch abcd{1...9}-xyz this will create 9 files wildcards are to substitute for charecters
387
touch abcd{1...9}-xyz will create how many files?
9 files
388
wildacard used for the begining of the line and the end of the line
^ and $ respectively
389
What is soft link and hard link?
it is related to inode. Inode is a pointer of a file on the hard disk Eevrytime we create a file, computer assisgns a number to the file and hard disk will associate that number to it and that number is called inode Soft link is a link if when created will be removed if the filname of that link is removed or renamed once created it looks for the inode through that file, so that creates a soft link, if removed the source file it removes the destination link whereas for hard link, deleting or renaming the source file will not change the hard link, as if you have copied it
390
What are the commands to create a hard link command
ln
391
to create a soft link command
ln -s
392
the reason why we creata soft link or hard link
to creata shortcut of the actual file, to have easy access instaed of doing a lot directory chnages or specifying the long path to the file
393
Create a soft link to a file in /tmp dir where the file is in /home/hulk and verify that the link got created
cd /tmp ln -s /home/hulk to check that the link got created ls -ltr command , at the botto of the output the file is seen
394
Why do we get the error that failed to create a hard link
This happens when the hard link is created on the different partition. . For the hard link to work, it needs to be on the same partition.
395
what are file permissions
Since unix is a multi user system. typically for protecting our environment where files could be viewed by other users, or unnecessarily modified or deleted by other users
396
how to display directory or file permission , explain them
ls -l command, the first 3 bits are for the user the second three bits are for the group the last three bits are for the other users of the system
397
How to remove write permissions of a file for a group
chmod g-w filename
398
How to remove read permissions to all users
chmod a-r filename
399
How to grant both read and write permissions to user
chmod u+rw filename
400
what is the meaning of x in the permissions bits of the direcotry
It certainly doesnot mean it is a script, what it means is we cannot cd into that directory
401
commands to change the ownership of the files
chown and chgroup that an be changed from the root account
402
let the root user own the filename
chown root filename
403
let the root group own the filename
chgroup root filename
404
what key completes the command on cli
hitting a tab key after the command completes the command
405
to show commands that start with ch
type ch and press tab twice
406
To bring the last command that you ran and the commands that were ran previous to it
up arrow key
407
Give me the commands that you use to monitor the system
``` top free df dmesg netstat iostat cat proc/cpuinfo cat proc/meminfo ```
408
What does df report
df reports filesystem usage of disk
409
If your system is dead or crashed, one of the things that you will look into it is
df command
410
If you see 100 % usage with the df command output,then the next step is
to free up the disk space an, and the comand to help in this pursuit is du which will output the disk usage of the files and the directories
411
The command to show you the output of the system related warnings , error messages , failures
It throws bunch of messages and bunch of information at you , and that command is dmesg If there are any issues with the memory it will report right here , if there is a memory leak, cpu that crashed or any mother board issue, anything related to system hardware will be related to that
412
what command that displays whats coming in and whats coming out and how we are communicating with our system's peripheral devices or system internal devices if it's a disk or network
iostat
413
Command to find out gateway information, command to find out my subnet mask and what interface it is going through
netstat -rnv
414
what is free command used for
It gives you information about the virtual memory and the swap space which is a virtual memory utilization
415
What is connected to the system, what is been disconnected , what is the process id and which process is it running and the name of the owner of the process
netstat
416
to get all the cpu info- which file to look at
cat /proc/cpuinfo
417
what is the log file that stores messages or errors during boot time
cat /proc/boot.log |more
418
All the system resouce informations are stored into files, where are these files located?
/var/directory
419
what is the log file that stores messages or errors during boot time
cat /var/boot.log |more
420
whenever you schedule a job or process through a cron tab entry, that activity is recorded as a log into this file
cat /var/cron
421
email out and email in is recorded in which log
/var/maillog
422
when troubleshooting issues as to why you are not able to send emails
/var/maillogs
423
real time recent logs on users loggin in and logging out
tail -f /var/secure
424
everytie there is an issue with the machine, the first thinga an adinistrator does is
look into the /var
425
This file has all the hardware information, all the software information, all the application information, all the process information, everything is logged into this log
/var/messages
426
command to see how many lines does /var/messages file has
cat /var/messages | wc -l
427
which command will give information about the OS and some kernel information
uname -a
428
which command will give you the information about the processor memory and the hardware underneath the OS
dmidecode
429
the first thing every time who ever logs into the system they should check they should run this command to know about which system they are in
uname -a
430
To tell which server you are logged in the command would be
hostname
431
how to disable ping
go to sysctl.conf net.ipv4.icmp.ignore_echo_ignore_all = 1 that parameter 1 will disable the ping, the parameter 0 will enable it
432
explain diff fields in /etc/passwd
username uid groupid shellname uid gid home drectory
433
how to know that a port is listening
netstat -tunlp | grep 22
434
Which commadn to tell how long the system has been running
uptime
435
wat command to show load average on the server
uptime
436
Define system load average
average number of processes that are in runnable state or uninterrupted state
437
Dispaly all lines in the files with line numbers
cat -n filename
438
What is the command to list all the network interfaces
ifconfig
439
How to make some congiguration on the network interface specified
go to /etc/sysconfig/network-scripts/ifcfg-empos3
440
which command to run to find if certain package is installed
rpm -qa | grep packagename rpm -qa | grep ntp
441
How to find if DNS package is installed or not
rpm -qa | grep bind
442
what is rpm command for
rpm command is a powerful package manager
443
how to find total lines in a file without opening the file
wc -l filename
444
shall we do cat on large files
no don't do cat on large files
445
How to find disk usage of the largest directory
du -Sh |sort -nr | head -n 10
446
how to find all directories with name cong under root
find / -type d -name conf
447
commadn to view all the currently logged in users
who
448
what is SOS report
sos repor is a package of all the sysyem congifuration informations, all the processes and all the resources information packaged and send t redhat for support
449
How to combine multiple files into one
cat file1 file2 file3 > file4
450
The file is very large, compression is not the option, you need t chop the files to send them to another server or a third party vendor and the log file is huge how to split single filesinto multiple files
split -l 300 filename childfile
451
How to append data to an existing file
echo uk >>filename
452
To send a foreground running process to background the command is
cntrl Z
453
To stop a background process
Cntrl C
454
A process when initiated always attaches itself to the terminal from where it is initiated
know this?
455
How to not interrupt a background process even after the terminal is closed?
nohup processname &
456
How to set priority of a process,
nice is the command to set priority of a process, the nice value ranges from -19 to 20, lower the number more priority the task gets. nice -n process command
457
what is the command to start an applicationand stop an application
systemctl restart ntpd d means daemon
458
what does ntp application do
its a daemon and is a network time protocol that runs all the time and syncs your time with other clocks
459
How to know the status of a service
systemctl status ntpd
460
To stop a service or an application or a process
systemctl stop ntpd
461
To startt an application whenever the system starts the command is
systemctl enable ntpd this will start the ntpd daemon whenevr the system strts
462
How do you know that a process is hung
top command that shows 99% of usage of mem and cp
463
command to know no. of users currently logged into the system
uptime
464
how to view all the commands available to you as a user
cd /usr/bin | ls -l
465
Did you know that you need to sort before u pipe it to uniq command?
only then the uniq command works | sort | uniq
466
To get the partition information on the disk
fdisk -l
467
Steps to mount new disk to the system
1) add new disk 2) initialize the disk 3) Patition the disk 4) mount it to the different mount points
468
what is the purpose of adding a new disk
when u run out of the disk space or if you have multiple applications may be one partition is required for one application and other partiton is required for another application, that's why we ask new disk
469
what is the purpose of adding a new disk
when u run out of the disk space or if you have multiple applications may be one partition is required for one application and other partition is required for another application, that's why we ask new disk
470
How to regular zip a directory
zip -r filename /path/to/dir/to/zip
471
How to unzip a regular zipped file
unzip filename -d dire/where/to/unzip/into
472
what is also another way to monitor cpu usage
sar -u
473
how to monitor cpu usage of all cores
sar -p ALl
474
How to monitor cpu usage of particular core
sar -p 4 (here 4 is the core number)
475
How to monitor the memory free and used
sar -r
476
which command shows memory usage ,cpu usage, cpu core usage, i/o statistics, block drivers,run query,load average,netwrok statisitcs
sar commadn with it's different options
477
How to monitor i/o statistics
sar -b
478
How to get the historic statistics of the cu usage of 15th of this month
sar -u -f /varlog/sa/sa15
479
which command to know the information on number of block drivers
sar -d
480
which command to know the information on the run queue and the load average
sar -q
481
which command to know the information on the network statistics
sar -n
482
which command to show the cpu and i/o of all partitions
iostat
483
to show only the cpu utilization bu tnot the partition i/o
iostat -c
484
to show only the partition i/o not the cpu
iostat -d
485
to show only the info a specified partition device name
iostat -p partition-device-name
486
command to display when the system was last rebooted
last reboot
487
command to displaywhen the system was last shutdown
last shutdown
488
command to display who all logged in to the system on 3rd january 2 am this year
last -t 201801030300
489
when did the username =cloudbreak last logged in?
last username
490
list all the users currently logged into the system
who
491
what is the number of users currently logged into the system
who -q
492
when was the system last rebooted
who -b
493
what are the processes spawned by the init
who -p
494
what are the processes that are dead and their details
who -d
495
command to compress a file
compress filename
496
command to uncompress a filename
compress -rv filename
497
command to know the amount of disk space util
df
498
command to know the dis space take up by a specified file say filename
du -a filename
499
You noticed that one of the Linux servers has no disk space left, how would you troubleshoot that issue
add more disk, create a new partition and link the new partition to an existing file-system
500
How to check Redhat version release?
uname -a
501
What is the difference between TCP and UDP?
TCP and UDP are protocols used for sending bits of data — known as packets — over the Internet. The main difference between TCP and UDP is connection; TCP is connection oriented and UDP is connectionless. TCP is all about reliability—packets sent with TCP are tracked so no data is lost or corrupted in transit UDP is used when speed is desirable and error correction isn’t necessary. For example, UDP is frequently used for live broadcasts and online games
502
To view the lined between 5 through 10 on file.txt
sed -n '5,10p' file.txt
503
to print the entire file except a certain range. To exclude lines 20 through 35 from myfile.txt, do:
sed '20,35d 'file.txt'
504
it’s possible that you’re interested in set of non-consecutive lines, or in more than one range. Let’s display lines 5-7 and 10-13 from myfile.txt:
sed -n -e '5-7p' -e '10-13p' myfile.txt
505
To replace every instance of the word version with story in myfile.txt, do:
sed 's/version/story/g' myfile.txt
506
To replace every instance of the word version with story in myfile.txt, is this command in order to ignore character case
sed 's/version/story/gi' myfile.txt
507
replace multiple blank spaces with a single space
sed 's/ */ /g' myfile.txt
508
If you’re interested in replacing words only within a line range (30 through 40, for example), you can do
sed '30,40 s/version/story/g' myfile.txt
509
Sometimes configuration files are loaded with comments. While this is certainly useful, it may be helpful to display only the configuration directives sometimes if you want to view them all at a glance. To remove empty lines or those beginning with # from the Apache configuration file, do
sed '/^##/|^$/|*#/d' myfile.txt
510
in regular expresion ^$ represnts what
blank lines
511
To replace a word beginning with uppercase or lowercase with another word, we can also use
sed 's/[zZ]ip/rar/g' file.txt
512
the pattern to search for is Jul 2 at the beginning of each line
sed -n '/^ Jul 2/p' file.txt
513
we can also insert spaces (blank lines) for each non-empty line in a file. To insert one blank line every other line in LICENSE, a plain text file
sed G file.txt
514
To insert two blank lines, for each non-empty line in a file. do
sed 'G;G' file.txt
515
replace all instances of this or This (ignoring case) with that in myfile.txt, and we will save the original file as myfile.txt.orig.
sed -i '.orig' 's/this/that/gi' myfile.txt
516
you have a file containing full names in the format First name, Last name. To adequately process the file, you may want to switch Last name and First name
sed 's/^\(.*\)\,\(.*\)/$/2\,/1' fil.txt
517
we may want to replace start with stop only if the word services is found in the same line. In that scenario, here’s what will happen:
sed '/services/ s/start/stop/gi' file.txt
518
Performing two or more substitutions at once
sed 's/this/that/gi;s/him/her/gi' file.txt
519
What is a zombie process?
To understand what a zombie process is and what causes zombie processes to appear, you’ll need to understand a bit about how processes work on Linux. When a process dies on Linux, it isn’t all removed from memory immediately — its process descriptor stays in memory (the process descriptor only takes a tiny amount of memory). The process’s status becomes EXIT_ZOMBIE and the process’s parent is notified that its child process has died with the SIGCHLD signal. The parent process is then supposed to execute the wait() system call to read the dead process’s exit status and other information. This allows the parent process to get information from the dead process. After wait() is called, the zombie process is completely removed from memory. This normally happens very quickly, so you won’t see zombie processes accumulating on your system. However, if a parent process isn’t programmed properly and never calls wait(), its zombie children will stick around in memory until they’re cleaned up. Utilities like GNOME System Monitor, the top command, and the ps command display zombie processes.
520
How do you search for a pattern/word in a file and then replace it in an entire file?
sed 's/patter/replcer/gi' filename
521
Explain the purpose of “touch” command?
To create an empty file
522
If a command hangs, how to stop it and get the prompt back?
Ctrl C
523
Which command is used to count words or lines?
wc
524
How to check the number of users logged in?
who
525
What is the command to view the calendar of 2011?
cal 2011
526
Which command is used to view disk space?
df –h
527
How to create a new group in Linux?
groupadd
528
What is the command to send a message to everyone who is logged into the system?
wall
529
Which command is used to check total number of disks?
fdisk –l
530
What does the following command line do? | ps -ef | awk '{print $1}' | sort | uniq
print all the processes and only print the first column of all running processes and sort them and remove duplicates
531
. You get a call that when a user goes to www.yourwebsite.com it fails and gets an error, how do you troubleshoot?
Check for user internet Check to see if user computer has DNS for hostname lookup Check to see if the server is up that is running that website Check to see if the server’s web service is running Check for DNS availability which is resolving that website
532
109. List 4 different directories in /?
/etc, /bin, /tmp, /home
533
What is the output of the following command: $tail -10 filename | head -1
It will show the first line from the last 10 lines of a file
534
What are the different fields in /etc/passwd file?
username passwword uid group name group id fullname of the user user home directory user terminall login
535
113. What is the difference between “hostname” and “uname” commands?
Hostname will give you system name and uname will give you OS information
536
How to check system load?
top and uptime command
537
How to schedule jobs?
crontab
538
What is the 3rd field when setting up crontab?
Day of the month
539
117. What is the command to create a new user?
useradd
540
118. What is the “init #” for system reboot?
6
541
119. How to restart a service?
systemctl restart servicename
542
120. How to shutdown a system? | shutdown or init 0
shutdown or init 0
543
How to shutdown a system? | shutdown or init 0
shutdown or init 0
544
What is “ftp” command used for?
To transfer files from one computer to another
545
123. How to delete a package in Linux?
rpm –e packagename
546
124. What is the file name where user password information is saved?
/etc/shadow
547
125. Which command you would use to find the location of chmod command?
which chmod
548
1. Which command is used to check if the other computer is online?
ping othercomputer
549
Please explain about LAN, MAN and WAN
A LAN (Local Area Network) is a group of computers and the network devices connected together usually within the same building. By definition, the connections must be high-speed and relatively inexpensive (e.g. token ring or Ethernet). A "LAN Connection" is a high-speed connection to a LAN. See "What is a LAN (local area network)?" below. A MAN (Metropolitan Area Network) is a larger network that usually spans several buildings in the same city or town. A WAN (Wide Area Network) is, in comparison, not restricted to a geographical location, although it might be confined within the bounds of a state or a country. A WAN connects several LANs, and may be limited to an enterprise (a corporation or an organization) or accessible to the public. The technology is high-speed, and is relatively expensive. The Internet is an example of a worldwide public WAN.
550
How to list hidden files in a directory?
ls –la
551
1. What is the difference between telnet and ssh?
ssh is secure where telnet is not
552
1. How to run a calculator on Linux and exit out of it?
bc and quit
553
131. List any 4 commands to monitor system?
top, df –h, iostat, dmesg
554
1. You are notified that your server is down, list the steps you will take to troubleshoot?
Check the system physically Login through system console Ping the system Reboot or boot if possible
555
1. What is difference between static and DHCP IP?
A Static IP address is a dedicated IP address that has been assigned to you. This is an IP address that is used by you every time you log in to network and need an IP address. DHCP or Dynamic is an IP address that will automatically be chosen for you from a pool of IP addresses that are assigned in the DHCP scope available on your network. Think Static as permanent and DHCP as temporary.
556
134. How to write in vi editor mode?
i = insert, a = insert in next space, o = insert in new line
557
135. What is the difference between “crontab” and “at” jobs?
crontab is for repetitive jobs where at is for one time job
558
1. What is “dmidecode” command used for?
To get system information
559
1. What is the location of system logs? E.g. messages
/var/log directory
560
140. How to setup an alias and what is it used for?
alias aliasname=”command” | It is used to created short-cuts for long commands
561
what is the purpose of netstat
Netstat is a common command line TCP/IP networking utility available in most versions of Windows, Linux, UNIX and other operating systems. Netstat provides information and statistics about protocols in use and current TCP/IP network connections. netstat (network statistics) is a command line tool for monitoring network connections both incoming and outgoing as well as viewing routing tables, interface statistics etc. netstat is available on all Unix-like Operating Systems and also available on Windows OS as well
562
What is nslookup used for
to resolve dns to obtain dns or ip addreses mapping for any other specific dns record
563
142. What are terminal control keys, list any 3?
Crtl C, D and Z, tab and up arrow
564
143. Which command(s) you would run if you need to find out how many processes are running on your system?
ps -ef |awk '{print $1}' |sort |uniq|wc -l or simply | ps -ef |wc -l
565
1. What are the different types of shells?
sh, bash, ksh, csh etc.
566
1. How to delete a line when in vi editor mode?
dd
567
146. Which is the core of the operating system?
a) Shell b) Kernel<< c) Commands d) Script
568
147. Which among the following interacts directly with system hardware?
a) Shell b) Commands c) Kernel<< d) Applications
569
148. How to save and quit from vi editor?
Shift ZZ or :wq!
570
149. What is the difference between a process and daemon?
A daemon is just a term for a process that runs continuously and usually is not attached to a terminal
571
1. What is the process or daemon name for NTP?
ntpd
572
151. What are a few commands you would run if your system is running slow?
top, iostat, df –h, netstat etc.
573
152. How to install a package in Redhat Linux?
yum install packagename
574
1. What is the difference between “ifconfig” and “ipconfig” commands? i
ifconfig for Linux and ipconfig for Windows
575
154. What is the first line written in a shell script?
Define shell | e.g. #!/bin/bash
576
155. Where is the network (Ethernet) file located, please provide exact directory location and file name?
/etc/sysconfig/network-scripts/ifcfg-nic
577
1. Why do we use “last” command? | To see who has logged in the system whether active or logged off
To see who has logged in the system whether active or logged off
578
158. To view your command history, which command is used and how to run a specific command?
history and history #
579
193. What is the difference between domain and nameserver?
The server or usually called as web server is an actual place where your website files are hosted. ... The domain name is a pointer to an IP address which hosts a server. Think of it as the difference between the street address "Example Street 42" (the domain name) and the house on that address (the server).
580
197. How to check scheduled jobs?
crontab –l
581
198. How to check system memory and CPU usage?
free and top
582
199. Which utility could you use to repair the corrupted file system?
fsck
583
1. What is the command to make a service start at boot?
systemctl enable servicename
584
1. How to combine 2 files into 1? E.g. you 3 lines in file “A” and 5 lines in file “B”, which command syntax to use that will combine into one file of 3+5 = 8 lines
cat fileA >> fileB
585
1. What is echo command used for?
To output to a screen
586
1. Which file to modify to allow users to run root commands
/etc/sudoers
587
1. Your system crashed and being restarted, but a message appears, indicating that the operating system cannot be found. What is the most likely cause of the problem?
The /boot file is most likely corrupted