Interview Linux
Interview Linux
=========================================================
nc -vz hostname portno:- to see the remote server and port is available or
not
How to find the largest file in the current directory and sub
directories
find . -type f -exec ls -s {} \; | sort -n -r | head -1
How to find the smallest file in the current directory and sub
directories
find . -type f -exec ls -s {} \; | sort -n -r | tail -1
or
How to find the files which are created between two files.
How to find the permissions of the files which contain the name
"java"?
find -name "*java*"|xargs ls -l
Alternate method is
find -name "*java*" -exec ls -l {} \;
Find the files which have the name "java" in it and then display
only the files which have "class" word in them?
find -name "*java*" -exec grep -H class {} \;
Awk Command
===================
63. Awk {print;} filename:-
64. Awk ‘/searchword/’ filename
65. Awk ‘{print $2,$3;}’ filename
66. Awk ‘{print $2,$5;}’ filename
67. Awk ‘{print $2,$NF;}’ filename
68. Awk ‘BEGIN {print col1 \t col2 \t…}
Awk “BEGIN {print $2 ,”\t” $3,;}
69. Awk ‘$1>200 ‘ filename :-
70. Awk ‘BEGIN {count=0:}
$4 ~ /searchkeyword/{count ++;}
END {print “no .ofmatching records:=,count;}’ filename
Linux Common Commands
============================
71. pwd :-present working directory
72. w:- to display system uptime ,load avg ,how many users
working full information of users
73. who:-to display the current active users
74. whoami:- current user name
75. who am i:-it gives first login user in the system command
prompt
76. which command :- to know the execution command location
path
77. cd:- to go the home directory
78. cd ~ :- to go the home directory
79. cd ..:- to go the previous directory
80. cd /somepath:- to go the given path
81. man :- to given the commands information
82. ls :- to display the list of files and directories
83. ls –a :- to display the list of files and directories and hidden
directories and files
84. ls –l :-
85. ls –lt:-it display the files with time based
86. ls –ltr:- it display the files with time reverse order
87. ls –ltrh:- it display the files with human readable format (like
gb,mb)
Rpm Commands
=================
88. Rpm –ivh rpmpkgname :- to install rpm package independently(with
in dependence)
89. Rpm –qa :- to display the all rpm packages installed details
90. Rpm –q kernel :- it display the kernel version
91. Rpm –e packagename :- to uninstall the rpm package
92. Rpm –l package :- to search the rpm location path
Compressed Commands
============================
93. Tar –cvf filename.tar directory/filepath:- to create tar file
94. Tar –xvf filename.tar:- to extract the tar file
95. Tar –cvf filename.tar directory1 directory2 directory3:- to create tar
file multiple directory
96. Tar –xvf filename.tar –d directorypath:- to extract the tar file in
specific location
97. Tar –tvf filename.tar:- to see the contents tar file without extract
98. Tar –czvf filename.tar.gz directory1 directory2 directory3:- to create
tar file multiple directory
99. Tar –xzvf filename.tar.gz:- to extract the tar file
100. Tar –tzvf filename.tar.gz:- to see the contents tar file without extract
101. Zip –r filename.zip directory1 :- to creates zip files
102. Unzip filename.zip :- to unzip the files
103. Unzip –l filename.zip (or) less filename.zip:- to see the content
without extract to see the content
104. Gzip filename:- to create only the files not directories
Example: gzip filename
Output:filename.gz
105. Gzip –r directory:- to create only zip In files in directories
106. Gunzip filename.gz :- to extract the gz file
107. Tar –cjvf filename.tar.bz filename:- to create bz file
108. Jar –cvf filename.jar file1 file2 :- to create a jar file
109. Jar –xvf filename.jar :- extract the jar file
110. Jar –tvf filename.jar :- to see the content of jar file without extract
111. Jar –cvf filename.war directorypath:- create a war file
112. Jar –xvf filename.war:- extract the war file
113. Jar –xvf filename.war –d directorypath:- extract the war file in
specific location
114. Jar –tvf filename.war:- to see the war file content without extract
Directory commands
========================
119. mkdir directoryname :- to create the directory.
120. Mkdir -p directoryname :- to create the directorys with in
directories.
121. Mkdir – p directory/directory{1..10} :- to create the directory in
directories
122. Rm –rf directoryname:- it removes the directory without
confirmation
123. Rmdir directoryname :- it remove the directory
Permission commands
==========================
124. Chmod 755 file :- to be give the change file permissions.
125. Chmod u+x file :- to be give the users execution permissions
126. chmod g+x file :- to give the groups execution permissions