Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
71 views

Interview Linux

This document provides over 100 Linux commands organized into categories including system information commands, networking commands, file creation commands, searching commands, sed commands, awk commands, common commands, RPM commands, and compressed file commands. The commands can be used to display system details, manage files and directories, view and edit files, install packages, work with networks, compress and uncompress files, and more.

Uploaded by

tahazzad hossain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
71 views

Interview Linux

This document provides over 100 Linux commands organized into categories including system information commands, networking commands, file creation commands, searching commands, sed commands, awk commands, common commands, RPM commands, and compressed file commands. The commands can be used to display system details, manage files and directories, view and edit files, install packages, work with networks, compress and uncompress files, and more.

Uploaded by

tahazzad hossain
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

Linux Commands

=========================================================

System information Commands


===========================
1. date :- to display the current system date and time
2. host name:- to display the system name
3. uname :-to display the os name
4. uname –a :- to display os name,kernel version,hostname,os bit
5. Uname –r :to display the kernel version
6. uptime:- to display system uptime ,load avg ,how many users working
7. Su – username :- it switches one user to another user
8. Vim /etc/passwd:- user information location path
9. su – username :- switch one user to another user
10. Arch :- to display the os bit version
11. Cat /proc/version :- to display the kernel version
12. cat /etc/redhat-release :-to know the linux version
13. Service iptables status
Service iptables start
Service iptables stop
14. Service servicename status
Service servicename start
Service servicename stop
Networking commands
====================
15. ifconfig:- to display the system Ip and mac address
16. Ifconfig eth0 :- to display only ip address
17. netstat –anlp |grep “:80” :- to see the which service is running 80
port number
18. ping hostname :- to display to see the connection remote system
available or not
19. netstat –anlp |grep httpd :- to see the apache running or not
20. dig hostname :- to display the response time on remote server
21. nslookup hostname :- to display the hostname is dns registered or
not
22. telnet hostname portno:- to see the remote server and port is
available or not

nc -vz hostname portno:- to see the remote server and port is available or
not

here :-nc means net cat

23. Nmap hostname:- it is used for port number scanner


24. Traceroute hostname/websitename:- to reach the website path in 30
hops to display
File creation commands
=========================
25. Vim filename :- to display the file content and add the file content
Esc mode:
:wq ---save and quit
:q!—forcebully quit
Yy – copy the line,P --- paste the line
Shift +gg ----- go to firstline
Shift+g -------go to last line
U –undo last delete or modified line
:set nu---to be set number on file
Dd --- to delete the line
/searchkeyword :-- to be search keyword in particular file existed or
not
n – to search next word by top to down
N – to search next word by down to top
:%/oldkeyword/newkeyword/gc it is replace old name to newname
I ---insert the data
26. cat >filename.txt :- to be create file and to give the data and save
the data in a file
27. cat filename:- to be see the content of the file
28. cat >> filename.txt :- to be append the data already existing file
29. touch:- to be create the empty file
30. touch filename:- to be create the empty or change the timestamp
for file
31. View filename:- to display the content of the file
32. more filename:- it displays the content of file
33. Head filename :- to display the first 10 lines in a file
34. Head -100 filename :- to display the first 100 lines in a file
35. Head –n 5 filename :- to display the first 5 lines in a file
36. tail filename :- to display the last 10 lines in a file
37. tail -50 filename :- to display the last 50 lines in a file
38. tail –f filename :- to see the running content process file
39. Rm file:- it remove the file with conformation
40. Rm –rf filename :– it remove the file without confirmation
Searching Commands
=====================
41. locate filename:- to search entire file system for given file name
42. find / -name filename:- to search entire / file system for given file
name
43. find . –name filename:- it searches the file in current directory
44. find . –iname filename:- it searches the file in current directory with
ignore the case sensitive
45. find / -type f –name filename:- it searches the file in the file system of /
46. find / -type d –name dirname :- it searches the directory in the file
system of /
47. find / -type f –name filename –exec rm –rf {}\; :-to find the file and
remove that file
48. find / -type f –empty :- it display the empty file
49. find / -type d –empty :- it display the empty directories
50. find / -mtime 50 :- to be find the last 50 days modified files
51. find / -mtime +50 –mtime -100 :- to be find the last 50 days to 100days
modified files.
52. find / -mmin -60:- it displayes the last one hour modified file
53. find / -cmin -60:- it displayes the last one hour changed file
54. find / -atime 50:- it displayes the last 50 days accessed file
55. find / -size 50M :- it displayes the 50 mb files.
56. find / -size +50M –size -100M :- it displayes the 50 mb to 100mb files.
57. Find / -size +100M –exec rm –rf {} \; :- it finds the 100 mb files and
delete the files

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

find . -type f -exec ls -s {} \; | sort -n | head -1

How to find the files which are created between two files.

find . -cnewer f1 -and ! -cnewer f2

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 {} \;

How to remove files which contain the name "java".


find -name "*java*" -exec rm -r {} \;

find and copy


-------------
find . -type f -name "*.mp3" -exec cp {} /tmp/MusicFiles \;
# cp *.mp3 files to /tmp/MusicFiles
copy one file to many dirs
--------------------------
find dir1 dir2 dir3 dir4 -type d -exec cp header.shtml {} \;
# copy the file header.shtml to those dirs

How to Find and Delete Files in the Linux Command Line

find . -name "*.bak" -delete

Find files with different file extensions

find . -type f \( -name "*.c" -o -name "*.sh" \)

find . -iname foo

If you’re just interested in directories, search like this:

find . -iname foo -type d

And if you’re just looking for files, search like this:

find . -iname foo -type f


Sed Command
====================
58. Sed ‘s/oldname/newname/’ filename :- to change first occurrence of
the each line old name to new name
59. Sed ‘s/oldname/newname/2’ filename :- to change second
occurrence of the each line old name to new name
60. Sed ‘s/oldname/newname/g’ filename :- to change all occurrence of
the each line old name to new name.
61. Sed –n ‘/name/p’ filename :- to print pattern match the line
62. Sed ‘/^#\|^$| -*#/d’ httpd.conf : to empty line file and start the #
beginning remove that lines

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

Moving data one location to another


================================
115. Cp :- copy the files
116. Cp source destintion:- to copy the files one location to another.
117. Cp -r source destintion:- to copy the directories one location to
another.
118. mv source destintion:- to cut and paste the files one location to
another. Or rename the files /directories

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

Chmod o+x file :- to give the others execution permissions

127. chown username:username filename :- to change the ower


permissions
128. chgrp username:username filename :- to change the group
permissions
PS Command
=================
129. Ps :- to display the process for running
130. Ps –ef :to display the all process for running
131. Ps –ef|grep httpd :- to check the httpd process is running or not
132. ps –ef|grep httpd :-to see the apache running or not
133. ps –ef|grep httpd|grep –v grep :-to see the apache running or not ad
not display grep output
134. kill -9 <pid> (Or) kill –TERM <PID> :- it kill the running process
forcebully
135. kill -3 <pid>:- it create the thread dump
136. jstack -l <pid> :- Creating tread dump
137. jmap -dump:[live],format=b,file=<file-path> <pid>
User Creation commands
===========================
138. Useradd username
139. Id username
140. Passwd username:-to create the password
141. Userdel username:-delete the user
142. Useradd –g primarygrp username:-
143. Useradd –G secondarygrp username:-
144. Usermod –a –G groupname username:-

Disk Fragmentation commands


=============================
145. Df :- to display disk fragmentation
146. Df -h :-to display disk fragmentation in gb
147. Df –m :- to display disk fragmentation in mb
148. Df –h . :- to display the disk fragmentation in current directory
149. Du:- to display the disk usage information
150. Du –sm *|sort -rn :- usage of the path reverse order
151. Du –sm *|sort –rn |head :- to display top 10in reverse order in
top approach
152. Du –sm *|sort –rn |tail :- to display top 10in reverse order in
down approach
153. Scp source username@ipaddress/hostname :remoteserverPath :- to
copy data one server to another server
154. Scp -r usernameA@ipaddress/hostname:remoteserverPath
usernameB@ipaddress/hostname:remoteserverPath :- to copy data
second server to third server but your in first server

155. Ssh steps password less login


Step1:-ssh-keygen
Goto .ssh
Id_rsa.pub

Step2:-go to second server


Go to home directory
Create .ssh directory
Copy the first server id_rsa.pub from to second server .ssh directory
Step 3:- after copy the file rename id_rsa.pub to authorized_keys
Change the permissions in server 2
chmod 644 authorized_keys
step 4:- to verify the ssh user@ipaddress
156. Yum install packagename:- for install the package(with dependencies.
157. Yum remove package :- for uninstall the package
158. ln –s file1 file2 :- to create the symbolic link file
159. echo message :- it displays the message
160. echo message >file.txt :- to create a file and store the file echo
message information.
161. Set or env :- to check the system or user environment variable
162. Echo $HOME:- it display the current home directory
163. >filename.txt:-
164. Wc filename:-
165. Grep “searchkeyword” filename:-
166. Grep –i “searchkeyword” filename:-
167. Echo $? :- if previous command is success print zero
Else :- print non zero
168. History :- to display the previous run command information

You might also like