All Linux Commands
All Linux Commands
All Linux Commands
Document History
Version Release Author Description Document Reviewer
Date
1.0 19.06.2017 Mithun Reddy L Created Mithun Reddy L
Server Details:
Server Name
IP
Username root
Password *********
Operating System
Introduction
Linux is an operating system that evolved from a kernel created by Linus Torvalds when
he was a student at the University of Helsinki.
When Linus Torvalds was studying at the University of Helsinki, he was using a version of
the UNIX operating system called 'Minix'. Linus and other users sent requests for
modifications and improvements to Minix's creator, Andrew Tanenbaum, but he felt that
they weren't necessary. That's when Linus decided to create his own operating system
that would take into account users' comments and suggestions for improvements.
Linux Distributions
§ Redhat Linux
§ Ubuntu.
§ CentOS
§ SuSe Linux
§ Debian.
§ Fedora
§ Gentoo
§ Mandriva.
§ Slackware
Download Linux from their respective home page. As it is an open source operating
system, it’s free to download! Not all versions are free, have a look:
http://distrocenter.linux.com/
http://www.redhat.com
http://fedora.redhat.com/
http://www.debian.org
http://www.mandriva.com
http://www.suse.com
http://www.opensuse.org/
http://www.slackware.com
http://www.ubuntulinux.org/
http://www.ubuntu.com/
http://www.distrowatch.com
http://www.openbsd.org
http://www.freebsd.org
http://www.netbsd.org
Kernel Architecture
1)bin: It contains the commands and binary files. User can access the commands. Ex:
mkdir, ls, cd, ps….
2)boot:
3)dev: It contains the device files. Ex: USB or any device attached to the server.
4)etc: It contains the configuration files.
5)home : It contains home directories for all users to store their personal files.
Ex: /home/bhaskar or /home/mithun
6)lib : It contains the system libraries.
7)lost+found :
8)media :
9)misc :
10)mnt :
11)net :
12)opt :
13)proc : It contains the RAM, Process and Kernel information.
14)root :
15)sbin : Just like /bin It contains the commands and files, but only root user can access.
Ex: ifconfig, reboot, shutdown and swapon …
16)selinux :
17)srv :
18)sys :
19)tmp :
20)usr : It contains the binaries and libraries. WAS,IHS or DB2 etc related softwares will
install in this directory.
21)var : It contains variable files. This includes system log files(/var/log), emails
(/var/mail) and temp files needed across reboots (/var/tmp)
22) tmp : It contains the temporary files.
e.g.
1)# mkdir Mithun
# ls -lt
# mkdir -m 777 MithunReddy
# ls -lt
4)#mkdir Bhaskar{1,2,3,4,5}
5)#mkdir -m 777 Mithun : It will create the Mithun folder with 777 permissions.
-----------------------------------------------------------------------------------------------------------------------
ls : Lists the contents of your current working directory.
-S Sorts files by file size. This option is useful only when used together with the
option –l
#ls –l
1 2 3 4 5 6 7
1) Permissions
2) Number of links
3) Owner
4) Group Owner
5) Size of the File in Bytes
6) Date and Time of created
7) File name/Dir Name
#ls –F
Here / indicates the directories, * indicates the executable files, @ indicates soft link.
• File type
• Date and time this information has been changed in the inode.
• File size
-----------------------------------------------------------------------------------------------------------------------
In linux which of the following information inode does not contain?
1.permission
2.File name
3.Owner ID
4.Size of the file.
Ans) 2
-----------------------------------------------------------------------------------------------------------------------
#ls b* : List files starting with b.
#ls *b : List files ending with b.
#ls *b* : Files just having letter b.
#ls ? : List single lettered file
#ls ?? : List double lettered file
#ls -l | grep ^d: It will display only the subdirectories from the current directory.
# ls -ld */ : It will display only the subdirectories from the current directory along with soft
link directories also.
#ls -p | grep "/" | xargs du –ks: It will display kilobytes used by each subdirectory of the
current directory.
Symbol Meaning
- Regular file
d Directory
l Soft Link
C Special file
S Socket
B Block device
#ls -l
Access Permissions
rw-r--r--
6 4 4 -----> Octal
r w x
r(Read) w(Write) x (Execute) -----> Owner 4 2 1
1 1 0 -----> Binary Notation
4 + 2 + 0 = 6 -----> Decimal Notation
r(Read) w(Write) x (Execute) -----> Group
1 0 0 -----> Binary Notation
r(Read) w(Write) x (Execute) -----> Others
1 0 0 -----> Binary Notation
-----------------------------------------------------------------------------------------------------------------------
cd : To Change working directory.
Options can be
• -i interactively asks for confirming the deletion of files. It is
useful in
avoiding accidental erasure of the file
• -r option provides a convenient way to erase a directory even if
it is not
empty
• -f option will forcefully remove a file to which we don’t have a
write
permission.
Syntax: rm <<File/Directory>>
#touch bhaskar.txt
#cat > newcatfile.txt (type your text when done press Ctrl + D).
Note: If data is already exists in that file, touch command will not overwrite, just it will
update the timestamp.
-----------------------------------------------------------------------------------------------------------------------
locate : Using locate command you can quickly search for the location of a specific file (or
group of files .
#locate mithun.txt
The example below shows all files in the system that contains the word crontab in it.
#locate crontab
-----------------------------------------------------------------------------------------------------------------------
find : find command used to search and locate list of files and directories based on
conditions you specify for files that match the arguments. Find can be used in variety of
conditions like you can find files by permissions, users, groups, file type, date, size and
other possible criteria.
#find ~ -name mithun.sh: It will search the mithun.sh file under logged in user home
directory.
#find . -name mithun.sh: It will search the mithun.sh file under current directory.
#find . -iname mithun.sh: It will search the mithun.sh file under current directory
ignoring the case.
find . -type f -perm 0777: It will search all the files which have 777 permissions.
find . -perm /a=x: It will search all the files which have execute permissions.
find . -type f –name ".*": It will search all the hidden files in current directory.
# find / -name <<FIleName>> : It will display the all files which we provide the name.
ex.# find / -name apachectl : It will display the all the locations, where the file apachectl
is available.
#find / -iname apachectl : It will display the all the locations, where the file apachectl is
available.
Here case insensitive.
#find . -mtime 1 : It will find all the files modified exact 1 day in current directory.
#find / -mtime 1 : It will find all the files modified exact 1 day in all directories.
#find . -mtime -1 : It will find all the files modified less than 1 day
#find . -mtime +1 : It will find all the files modified more than 1 day
#find / -mmin -10 : It will locate/display the files which modified less than 10 minutes
ago.
#find / -perm 600 : It will displays the files and directories which have the 600
permissions.–perm option is used to find files based upon permissions.
#find . –name "*.java" | xargs grep “FTPReadXML” : It will displays java files which
have the FTPReadXML word in those files.
# find . -name "*.java" -exec chmod 700 '{}' \; : It will set the access permissions (700)
for all java files.
The argument '{}' inserts each found file into the chmod command line. The \; argument
indicates the exec command line has ended.
#find . -size +1000c -exec ls -l {} \; : It will display the files which size greater than
1000bytes.
#find . -name "*.*" -ls | awk '{print $7 " " $11}' | sort -rn | head -n 10 :
Find ten largest files in the current directory and recursion through all subdirectories
-----------------------------------------------------------------------------------------------------------------------
What is the difference between locate and find?
Ans) The find command has several options and is very configurable. There are many ways
to reduce the depth and breadth of your search and make it more efficient.
locate uses a previously built database, If database is not updated then locate command will
not show the output. to sync the database it is must to execute updatedb command.
By default, the system will run updatedb which takes a snapshot of the system files once a
day, locate uses this snapshot to quickly report what files are where. However, recent file
additions or removals (within 24 hours) are not recorded in the snapshot and are unknown to
locate.
umask : User Mask or User file creation MASK : It is used to set the permissions for
files/directories newly created ona Linux Machine.
• The default umask 002 used for normal user. With this mask default directory
permission are drwxrwxr-x (775) and default file permissions are -rw-rw--r-- (664).
• The default umask for the root user is 022 result into default directory
permissions are drwxr-xr-x (755) and default file permissions are -rw-r--r—(644).
• For directories, the base permissions are (rwxrwxrwx) 0777 and for files they are
0666 (rw-rw-rw).
• Umask setup is in /etc/bashrc or /etc/profile file as follows.
Calculating the permissions for Files and directories are when umask value is 006.
For File:
Subtract the umask value from base permissions.
666 – 006 = 660 (rw-rw----)
For Directory:
Subtract the umask value from base permissions.
777 – 006 = 771 (rwxrwx--x)
If you want to know the umask value simply type unmask as follows.
#umask
Syntax : chmod << options >> <<access permissions >> << filename/directory >>
777 ----> Change permission of the file, make it to executable by all (Owner, Group and
Others).
400 ----> Change the permission of the file – only Owner can read.
# clear
# pwd
# ls -l
# chmod u-rwx Bachi.txt
# ls -l
# chmod og-rwx Bachi.txt
# ls -l
Permission
# Octal Permission Representation Reference
0 No permission ---
1 Execute permission -x-
2 Write permission -w-
3 Execute and write permission: 1 (execute) + 2 (write) = 3 -wx
4 Read permission r--
5 Read and execute permission: 4 (read) + 1 (execute) = 5 r-x
6 Read and write permission: 4 (read) + 2 (write) = 6 rw-
7 All permissions: 4 (read) + 2 (write) + 1 (execute) = 7 rwx
-----------------------------------------------------------------------------------------------------------------------
chown : Change file owner and group.
# ls –l
# chown bachi Bachi.txt
# ls -l
# ls –l
# chown --from=root bhaskar devops.txt
# ls -l
# ls -l
-----------------------------------------------------------------------------------------------------------------------
chgrp : Change file group.
# ls –l
# chgrp devops Bachi.txt
# ls -l
-----------------------------------------------------------------------------------------------------------------------
cp: Copy files and directories.
Syntax : mv <<File/ Directory Actual Name>> << File/ Directory New Name>>
-----------------------------------------------------------------------------------------------------------------------
file : Determine file type.
#file /etc/hosts
-----------------------------------------------------------------------------------------------------------------------
wc : Print the number of newlines, words, and bytes in files
Options can be
• -c Display number of bytes
• -m Display number of character.
• -l Display number of lines.
• -w Display number of words.
• -L Displays the length of the longest line.
-----------------------------------------------------------------------------------------------------------------------
ln : Make links between files.
The inode contains a list of all the blocks in which a file is stored, the owner information
for that file, permissions, and all other attributes that are set for the file. In a sense, you
could say that a file really is the inode, and names are attached to these inodes to make it
easier for humans to work with them.
Use the debugfs command start to display the contents of the inode that you want
to examine. For example, in this case you would type stat <InodeNumber>.
Hard Links:
In Linux all directories and files have inodes. Creating hard link is nothing but add a new
name to the inode. To do this we can use the ln command.
There is no difference between hard link and the original file.
Both files have the same inode number
Both files have the same size/contents.
Both files have the same access permissions.
If you change one file contents it will update another file also
Symbolic links:
The symbolic link and the original file have different inodes.
The size of the symbolic link is significantly different from the size of the real file.
The size of the symbolic link is the number of bytes in the name of the file it refers to,
because no other information is available in the symbolic link.
The file type of the symbolic link is set to 1, which indicates that it is a symbolic link.
A symbolic link is like a shortcut. It points to the original file and helps you find it easily. It
breaks if you remove the original file.
A hard ink is like a copy of the original file that is synchronized continuously. There is no
difference between the original file and the hard link; they both refer to the same blocks.
We can create symbolic link for both files and directories, but we cannot create hard links
for directories, can create only for files.
Note: If you create hard links, inode number will be same for both files and if you create
soft links, inode number will be different.
-----------------------------------------------------------------------------------------------------------------------
vim or vi : Vi IMproved, a programmers text editor.
#vi Bachi.txt
Then you can enter ‘Insert’ key or ‘i’. Now you are able to type text into that file(Bachi.txt).
Once it finishes press ‘Esc’ button and type ’:’ and type ‘wq’. Option q! is for simply quit
without save.
nano mithun.txt
#echo $PATH
/usr/kerberos/sbin:/usr/kerberos/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin
:/root/bin:/root/bin:/root/Deployment_Ant/apache-ant-1.8.4/bin
# cat bhaskarreddy.txt
# cat -n hello.sh
tac : Does the same as cat, but displays the contents in reverse order
#tac bhaskarreddy.txt
-----------------------------------------------------------------------------------------------------------------------
head : Print the first lines of each FILE to standard output.
Options are
1) –n: output the last N lines, instead of the last 10.
e.g. 1) #head bhaskar.txt : It will display the first 10 rows for specified file.
Note: By default, it will display 10 rows if don’t provide any options for head command.
2) #head -20 bhaskar.txt : It will display the first 20 rows for specified file.
(OR)
#head -n 20 bhaskar.txt
Note: If you specify the more lines than the available in file, it will display the max lines in
the file. See in the above example we specified the 20 lines in the command but only 15
lines there in the bhaskar.txt file.
-----------------------------------------------------------------------------------------------------------------------
tail : Print the last lines of each FILE to standard output.
Options are
1) –f : output appended data as the file grows.
2) –n : output the last N lines, instead of the last 10.
e.g.
#tail bhaskar.txt ---> It will display the last 10 rows.
The # prompt does not return even after the work is over. With this option we have to
abort the
process to exit to the shell. Use the interrupt key applicable on your machine. (Ctrl+c or q)
Note: By default, it will display 10 rows if don’t provide any options for tail command.
#tail -n 3 bhaskar.txt : It will display the last 3 rows for specified file.
(OR)
#tail -3 bhaskar.txt
-----------------------------------------------------------------------------------------------------------------------
more : It is a filter for paging through text one screenful at a time (stop the display on
each screen)
#more bhaskarreddy.txt
-----------------------------------------------------------------------------------------------------------------------
less : less is the same as more except you can scroll back and forward.
#less bhaskarreddy.txt
-----------------------------------------------------------------------------------------------------------------------
sort : It is used to sort the output in numeric or alphabetic order .
-----------------------------------------------------------------------------------------------------------------------
tr: To translate the text from lower case to upper case.
-----------------------------------------------------------------------------------------------------------------------
sed : 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).
FileName: sedfile.txt
Hi All,
My Name is Mithun Reddy, working as a DevOps Engineer in MT, Bangalore. Currently
DevOps is very good in market.
Learning DevOps tools are very easy. DevOps is not a technology. DevOps is a culture.
DevOps is the combination of software development and operations team. DevOps helps
an organization deploy software more frequently.
Note: By default, the sed command replaces the first occurrence of the pattern in each
line and it won't replace the second, third...occurrence in the line.
Use the /1, /2 etc flags to replace the first, second occurrence of a pattern in a line. The below
command replaces the second occurrence of the word "unix" with "linux" in a line.
http://www.folkstalk.com/2012/01/sed-command-in-unix-examples.html
-----------------------------------------------------------------------------------------------------------------------
grep : This command is used to search specific string in specified file. By default, grep
prints the matching lines.
#ps –ef | grep java : It will display all the java process.
-----------------------------------------------------------------------------------------------------------------------
who : It shows who is logged in the same machine.
#who -T :
#who -H :
#who am i : The use of the arguments with who am i causes the command to only lists
the one user who typed the command.
The command is who and the arguments are am i.
-----------------------------------------------------------------------------------------------------------------------
w : Show who is logged on and what they are doing.
The header shows, in this order, the current time, how long the system has been running,
how many users are currently logged on, and the system load averages for the past 1, 5,
and 15 minutes.
The following entries are displayed for each user: login name, the tty name, the
remote host, login time, idle time, JCPU, PCPU, and the command line of their current
process.
The JCPU time is the time used by all processes attached to the tty. It does not
include past background jobs, but does include currently running back- ground jobs.
The PCPU time is the time used by the current process, named in the "what" field.
e.g. #w
-----------------------------------------------------------------------------------------------------------------------
#whoami : Print the user name associated with the current effective user ID. Same as id
-un.
#id -un :
-----------------------------------------------------------------------------------------------------------------------
whereis: Path/locate the binary, source, and manual page files for a command.
Options are:
Examples:
# whereis chmod
# whereis -b chmod ---> Gives the path for binaries.
# whereis -m chmod ---> Gives the path for manual sections.
# whereis -s chmod ---> Gives the path for sources.
-----------------------------------------------------------------------------------------------------------------------
date : Displays or sets the date or time.
-----------------------------------------------------------------------------------------------------------------------
df : Report file system disk space usage.
OPTIONS
Show information about the file system on which each FILE resides, or all file
systems by default.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
include dummy file systems
-h, --human-readable
print sizes in human readable format (e.g., 1K 234M 2G)
-H, --si
likewise, but use powers of 1000 not 1024
-i, --inodes
list inode information instead of block usage
-k like --block-size=1K
-l, --local
limit listing to local file systems
--no-sync
do not invoke sync before getting usage info (default)
-P, --portability
use the POSIX output format
-t, --type=TYPE
limit listing to file systems of type TYPE
-T, --print-type
print file system type
-x, --exclude-type=TYPE
limit listing to file systems not of type TYPE
-v (ignored)
--version
output version information and exit
SIZE may be (or may be an integer optionally followed by) one of following: KB 1000, K
1024, MB 1000*1000, M 1024*1024, and so on for G, T, P, E, Z, Y.
#df –h
#df –a
-----------------------------------------------------------------------------------------------------------------------
du: Estimate file space usage.
DESCRIPTION
Summarize disk usage of each FILE, recursively for directories.
Mandatory arguments to long options are mandatory for short options too.
-a, --all
write counts for all files, not just directories
--apparent-size
print apparent sizes, rather than disk usage; although the apparent size is
usually smaller, it may be larger due to holes in (âsparseâ) files,
internal fragmentation, indirect blocks, and the like
-b, --bytes
equivalent to â--apparent-size --block-size=1â
-c, --total
produce a grand total
-D, --dereference-args
dereference FILEs that are symbolic links
--files0-from=F
summarize disk usage of the NUL-terminated file names specified in file F
-H like --si, but also evokes a warning; will soon change to be equivalent to –
dereference-args (-D)
-h, --human-readable
print sizes in human readable format (e.g., 1K 234M 2G)
-k like --block-size=1K
-l, --count-links
count sizes many times if hard linked
-m like --block-size=1M
-L, --dereference
dereference all symbolic links
-P, --no-dereference
donât follow any symbolic links (this is the default)
-0, --null
end each output line with 0 byte rather than newline
-S, --separate-dirs
do not include size of subdirectories
-s, --summarize
display only a total for each argument
-x, --one-file-system
skip directories on different file systems
-X FILE, --exclude-from=FILE
Exclude files that match any pattern in FILE.
--max-depth=N
print the total for a directory (or file, with --all) only if it is N or fewer levels
below the command line argument; --max-depth=0 is the same as --summarize
--time show time of the last modification of any file in the directory, or any of its
subdirectories
--time=WORD
show time as WORD instead of modification time: atime, access, use, ctime or
status
--version
output version information and exit.
#du –h
Note: If no path is mentioned, default is current directory, where the action will be
performed.
-----------------------------------------------------------------------------------------------------------------------
hostname: Show or set the systems host name.
#hostname
ralbz2072.cloud.dst.mt.com
#hostname ralbz2072
#hostname
ralbz2072
Once the hostname is changed, verify that it has changed the hostname successfully. As
you see below, it has changed the hostname to ralbz2072.
#vi /etc/hosts
#vi /etc/sysconfig/network
#ifconfig
# hostname -i
9.42.158.72
# nslookup ralbz2072
Server: 9.0.6.1
Address: 9.0.6.1#53
Non-authoritative answer:
ralbz2072.cloud.dst.mt.com canonical name = ralbz2072.raleigh.mt.com.
Name: ralbz2072.raleigh.mt.com
Address: 9.42.158.72 IP for ralbz2072.raleigh.mt.com
How to change the IP address temporarily?
Ans) We can use ifconfig command to change IP Address as follows.
#ifconfig eth0 9.42.159.72
-----------------------------------------------------------------------------------------------------------------------
# domainname (show or set the systems NIS/YP domain name)
(none)
# dnsdomainname ( show the systems DNS domain name)
lexington.mt.com
nisdomainname (show or set systems NIS/YP domain name)
(none)
# ypdomainname (show or set the systems NIS/YP domain name)
(none)
-----------------------------------------------------------------------------------------------------------------------
nslookup : It will query the server name, ip address for specified host.
#nslookup ppdb2dev03
nslookup: parse of /etc/resolv.conf failed
#cat /etc/resolv.conf
# DNS info generate from updateconfig
# 2011-10-30 12:23:26 PM
# DO NOT MANUALLY MODIFY THIS FILE!
#
domain boulder.mt.com
search
nameserver 9.0.8.1
nameserver 9.0.9.1
#nslookup ppdb2dev03
Server: 9.0.8.1
Address: 9.0.8.1#53
This is zLinux server
Non-authoritative answer:
Name: ppdb2dev03.boulder.mt.com
Address: 9.17.174.17
-----------------------------------------------------------------------------------------------------------------------
What is the difference between /etc/hosts and /etc/resolve.conf? What are the types
of DNS records?
Ans) resolv.conf specifies the nameservers for resolver lookups, where it will actual use
the DNS protocol for resolving the hostnames. Typically the hosts file is used for
administrative purposes such as backend and internal functions, which is substantially
more isolated in scope, as only the local server will reference it it.
An “A” record, which stands for “address” is the most basic type of syntax used in DNS
records, indicating the actual IP address of the domain. The “AAAA” record is an IPV6
address record that maps a hostname to a 128-bit Ipv6 address. Regular DNS addresses
are mapped for 32-bit IPv4 addresses.
The “CNAME” record stands for “canonical name” and serves to make one domain an
alias of another domain. CNAME is often used to associate new subdomains with an
existing domain's DNS records.
The “MX” record stands for “mail exchange” and is basically a list of mail exchange
servers that are to be used for the domain.
The “PTR” record stands for “pointer record” and maps an Ipv4 address to the CNAME on
the host.
The “NS” record stands for “name server” and indicates which Name Server is
authoritative for the domain.
An “SOA” record stands for “State of Authority” and is easily one of the most essential
DSN records because it stores important information like when the domain was last
updated and much more.
An “SRV” record stands for “service” and is used to define a TCP service on which the
domain operates.
A “TXT” record lets the administrator insert any text they'd like into the DNS record, and it
is often used for denoting facts about the domain.
-----------------------------------------------------------------------------------------------------------------------
Help Commands
To search any word in “man” page use “/” and string name.
“n” for checking next search and “N” for previous search.
To quit press “:q”.
-----------------------------------------------------------------------------------------------------------------------
What is the differance between Ctrl +c and Ctrl + Z?
Ans)
By using fg command we can run the suspended job in foreground and using bg
command we can run the suspended job in backroundas follows.
bg
(OR)
bg %n
kill %n --> where n will be numbers displayed in jobs command , so if you want to kill 1st
process use below command.
e.g.
#info man
#info who
-----------------------------------------------------------------------------------------------------------------------
help : It gives a short explanation about how to use the command and a list of available
options.
e.g.
#ls --help
#passwd --help
-----------------------------------------------------------------------------------------------------------------------
The Gnome Help Browser is very user friendly as well. You can start it selecting
Applications->Help from the Gnome menu, by clicking the lifeguard icon on your desktop
or by entering the command gnome-help in a terminal window. The system
documentation and man pages are easily browsable with a plain interface.
You may want to try "info:info" in the Location address bar, and you will get a browsable
Info page about the info command. Similarly, "man:ls" will present you with the man page
for the ls command.
-----------------------------------------------------------------------------------------------------------------------
apropos : Search information about a command or keyword.
Suppose if you don't know how to start a browser, then you could enter the following
command:
#apropos browser
#apropos editor
-----------------------------------------------------------------------------------------------------------------------
service : This command is used to find the service is running in the server or not.
Options are:
status:
stop
start
restart
status-all
Examples:
# service sshd status: It will displays the status of the specified service.
#service crond status : It will check the status of cron is running or not?
# /etc/init.d/nfs start
-----------------------------------------------------------------------------------------------------------------------
ps : This command can used to display the currently running processes on Linux
systems.
ps is the shortage for Process Status.
# ps ux :
(OR) It display all processas owned by a specific user.
# ps U mithun :
# pstree -G :
-G ---> Use VT100 line drawing characters.
Note : -A ---> This opion uses ASCII characters to draw the tree.
-G --->This opion uses VT100 line drawing characters.
In AIX:
Here -e means select all processes and -f means full format listing.
ps -eo pid,cmd,%mem,%cpu,stat | less: It will display the process which are currently
running in following format.
If you type Spacebar it will display screen by screen. If you go back you need to enter ‘B’.
-----------------------------------------------------------------------------------------------------------------------
kill : The command will sends the specified signal to the specified process
#kill –l : It will display all signal names. These are found in /usr/include/linux/signal.h
#kill -3 <<JavaProcess ID>> : It will generate the core dump for Java processes.
#kill all -u <<username>> : It will kill all the processes under specified user.
-----------------------------------------------------------------------------------------------------------------------
top : The top program provides a dynamic real-time view of a running system. It can
display system summary information as well as a list of tasks currently being managed by
the Linux kernel. The types of system summary information shown and the types, order
and size of information dis-played for tasks are all user configurable and that
configuration can be made persistent across restarts.
# top
Press (Shift+O) to Sort field via field letter, for example press ‘a‘ letter to sort process with
PID (Process ID).
Press ‘z‘ option in running top command will display running process in color which may
help you to identified running process easily.
Press ‘c‘ option in running top command, it will display absolute path of running process.
By default screen refresh interval is 3.0 seconds, same can be change pressing ‘d‘ option
in running top command and change it as desired as shown below.
You can kill a process after finding PID of process by pressing ‘k‘ option in running top
command without exiting from top window as shown below.
Press (Shift+P) to sort processes as per CPU utilization. See screenshot below.
Press (Shift+W) to save the running top command results under /root/.toprc.
Top output keep refreshing until you press ‘q‘. With below command top command will
automatically exit after 10 number of repetition.
# top -n 10
-----------------------------------------------------------------------------------------------------------------------
File Archieve/Extraction Commands
zip : zip, zipcloak, zipnote, zipsplit - package and compress (archive) files.
unzip : unzip - list, test and extract compressed files in a ZIP archive.
#tar xvfz test.tar.gz : Extract a gzipped tar archive ( *.tar.gz ) using option xvzf
#tar tvf test.tar : View the tar archive file content without extracting using option tvf
#tar tvf test.tar.gz : View the *.tar.gz file content without extracting using option tvzf
#tar rvf test.tar Source/ : Adding a file or directory to an existing archive using option –r
Note: 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 as shown below.
-----------------------------------------------------------------------------------------------------------------------
User Administration Commands
To login
#passwd -u isgproject
Now not able to login with isgproject user because !! in the password field of /etc/shadow
file for user isgproject as shown above screen shot.
# passwd -u isgproject
#passwd -d < User Name > : It will deletes the already existing password in /etc/shadow
file for specified user, resulting it restricts the login into server.
#passwd -d bhaskar
Syntax:
# newusers <filename>
Following is the syntax of the parameters to be provided for each user in file.
<Username>:<Password>:<UID>:<GID>:<User Info/Comments>:<Home Dir>:<Default
Shell>
Example:
File Name: UsersList
bhaskar:bhaspwd@2013:500:500:Bhaskar User ID:/home/bhaskar:/bin/bash
mithun:mithpwd@2013:501:501: Mithun User ID:/home/mithun:/bin/bash
Note:
Password should contain at least 8 characters length.
It should contain at least one special character like @, & …
It should contain at least one number.
It should contain at least one Capital letter.
It should contain at least one small letter.
#newusers UsersList
If you are using MD5 passwords(default), ensure that newusers will generate MD5
paswords, else the users will not be able to login.
MD5_CRYPT_ENAB yes
/etc/group
/etc/passwd
/etc/shadow
#chage naresh
#chage -E never bhaskar : It will make user ‘s(bhaskar) account will not expire.
-----------------------------------------------------------------------------------------------------------------------
groupadd: Create a new group.
-----------------------------------------------------------------------------------------------------------------------
usermod : Changes user attributes.
For locking:
#usermod -e : The date on which the user account will be disabled. The date is specified
in the format YYYY-MM-DD.
Syntax: groupmod -n << group name >> << new group name >>
In the above example the groupmod command would change the group "linuxadmin" to
"bhaskaradmin".
-----------------------------------------------------------------------------------------------------------------------
newgrp : It is used to change the current group ID during a login session.
For example if you are a member of the groups "linuxgrp" and "javagrpyou can switch to
the other group with the following command:
newgrp mithubgroup
Every Linux user can be assigned to multiple groups so they can obtain access to
whatever files and directories they need to perform their work. Users can determine the
groups to which they have access by using the id command.
#id
#newgrp mithungroup
#id
Now if you create any file or directory, it will assign the group as mithungroup, as shown
below.
-----------------------------------------------------------------------------------------------------------------------
id : It is one more command which will show the user details such as his primary group
and his secondary group.(Displays the system identifications of a specified user.)
Examples:
#id mithun
#id madhava
#id ahcrn
#id root
#id
-----------------------------------------------------------------------------------------------------------------------
lid: Display user’s groups or group’s users. à Only root user can execute.
-----------------------------------------------------------------------------------------------------------------------
su : Switches the user between users and root. (Changes the user ID associated with a
session.)
#su Mithun
#whoami
#exit
#whoami
-----------------------------------------------------------------------------------------------------------------------
users: Displays a compact list of the users currently logged on the system.
e.g.
#users
Note: See first it displays only one user name called root, after that I logged with bhaskar
user in other terminal, then it shows two users.
-----------------------------------------------------------------------------------------------------------------------
groups : Displays group membership.
#groups <<User Name>>
-----------------------------------------------------------------------------------------------------------------------
userdel : Removes a user account.
Examples:
#userdel Bhaskar
#userdel -r bhaskar ---> It will delete/remove the bhaskar account and also the bhaskar
home directory, in this case (/home/ bhaskar).
-----------------------------------------------------------------------------------------------------------------------
groupdel: Deletes a new group.
#groupdel linuxadmin
-----------------------------------------------------------------------------------------------------------------------
finger : Finger displays the users login name, real name, terminal name,shell and write
status, idle time, login time, office location and office phone number.
#finger
#finger govinda
#finger root
-----------------------------------------------------------------------------------------------------------------------
crontab : Crontab is the program used to install, deinstall or list the tables used to drive
the cron daemon in Linux Operating system.
Crontab format:
Example:
To restrict any user from using cron job facility, enter their names in /etc/cron.deny and
save it
#vim /etc/cron.deny
If again want to allow bhaskar1user to use cron job facilities just remove bhaskar1 user
from /etc/cron.deny file.
Assuming that we have 100 users in our system, putting all 98 names in /etc/cron.deny
file is a time consuming process. Instead of that, we can create one more file
/etc/cron.allow, in which we can assign names of those users who are allowed to use cron
jobs. Remove the /etc/cron.deny file and create /etc/cron.allow, still if both files are
existing cron.allow file will be having precedence over cron.deny file. Just to avoid
confusion it is good to remove cron.deny file
Note: /etc/cron.deny file exists by default, but we need to create /cron.allow file. If your
name is not there in cron.allow file then you will not be allowed to use cron jobs, and as
mentioned above, if both files are existing cron.allow file will be having precedence over
cron.deny file. If neither cron.deny nor cron.allow files exists then only root can use cron
jobs.
-----------------------------------------------------------------------------------------------------------------------
To find RAM details in Linux
free : To find the amount of free and used RAM memory in the system
Syntax : free [-b|-k|-m|-g] [-l] [-o] [-t] [-s delay] [-c count] [-V]
-b,-k,-m,-g show output in bytes, KB, MB, or GB
-l show detailed low and high memory statistics
-o use old format (no -/+buffers/cache line)
-t display total for RAM + swap
-s update every [delay] seconds
-c update [count] times
-V display version information and exit
#free
#free -b
#free -k
#free -m
#free -g
-----------------------------------------------------------------------------------------------------------------------
#free -l
-----------------------------------------------------------------------------------------------------------------------
#free -o
-----------------------------------------------------------------------------------------------------------------------
#free -t
-----------------------------------------------------------------------------------------------------------------------
#free -V
-----------------------------------------------------------------------------------------------------------------------
# dmidecode -t 16 : It gives the RAM information like location, Maximum capacity of RAM
supported, number of RAM devices present and slot info.
-----------------------------------------------------------------------------------------------------------------------
How to enable a password login instaed of pem file when logging into EC2 Instance
using SSH?
====================================================================
vi /etc/ssh/sshd_config
PasswordAuthentication yes
passwd ec2-user
-----------------------------------------------------------------------------------------------------------------------
ssh: ssh (SSH client) is a program for logging into a remote machine and for executing
commands on a remote machine. It is intended to provide secure encrypted
communications between two untrusted hosts over an insecure network.
Note : Below screen shot shows the message got from the write command.
-----------------------------------------------------------------------------------------------------------------------
mesg: Permits or refuses write messages from other users.
mesg n ---> Allows only the root user the permission to send messages to your
workstation.
mesg y ---> Allows all workstations on the local network the permission to send
messages to your
workstation.
e.g.: $ mesg n
Now I tried with user prakash to send the message to user bhaskar. See the output.
Here the user is root. Root can able to send the message to any user even they disabled.
-----------------------------------------------------------------------------------------------------------------------
#mail devopstrainingblr@gmail.com
Once you enter the to address It will ask Subject then Press Enter Body of mail then type
Ctrl+D it will ask CC address, then enter CC address and press Enter button.
Here Hello is the Subject and contents in bhaskar.txt is the subject for mail.
#echo "This is for body of mail" | mail -c satya@in.mt.com -s "Sending mail using
mail command" prakash@in.mt.com -b mithun@in.mt.com
mutt always reads a text from standard input that will become the main body of the e-mail,
the text before the attachment. If the mail should consist of attachments only, we can
either specify /dev/null as the file to read, e.g.
Following example will download and store the file with name: apache-ant-1.8.4-
src.tar.gz
Download in progress:
Download in completed:
If you run the same command twice the file name will be saved suffix with .1 as follows.
-----------------------------------------------------------------------------------------------------------------------
Record your session
script : This command records your login session in a typescript (file) in the current
directory. All the commands, their output and the error messages are stored in the file
(typescript --> ASCII text file) for later viewing.
e.g.
# script
script
Script started, file is typescript
# ls
ls
anaconda-ks.cfg isus
Desktop plglogs pluginGSKitUpgradeLog.txt
ihsGSKitUpgradeLog.txt Read_Me_IC2_Default.properties
ihslogs typescript
install.log updilogs
install.log.syslog waslogs
# pwd
pwd
/root
# whoami
whoami
root
# exit
exit
exit
Script done, file is typescript
spell and ispell are used to spell-check a document. spell produces a list of misspelled
words, while ispell lets you perform the corrections on-line.
(OR)
# lsb_release -a
#cat /etc/*release
-----------------------------------------------------------------------------------------------------------------------
uname : Print system information.
DESCRIPTION
Print certain system information. With no OPTION, same as -s.
-a, --all
print all information, in the following order, except omit -p and -i if unknown:
-s, --kernel-name
print the kernel name
-n, --nodename
print the network node hostname
-r, --kernel-release
print the kernel release
-v, --kernel-version
print the kernel version
-m, --machine
print the machine hardware name
-p, --processor
print the processor type or "unknown"
-i, --hardware-platform
print the hardware platform or "unknown"
-o, --operating-system
print the operating system
--version
output version information and exit
-----------------------------------------------------------------------------------------------------------------------
To find Physiacl RAM(Linux)
#dmesg | grep mem
(OR)
#cat /proc/meminfo
-----------------------------------------------------------------------------------------------------------------------
To find Physiacl RAM(AIX)
#lsattr –E –l sys0 –a realmem
-----------------------------------------------------------------------------------------------------------------------
[root@ralbz2072 /]# cat /proc/cpuinfo |grep processor ---> It will display the CPUs
names
(OR)
[root@ralbz2072 /]# cat /proc/cpuinfo | grep processor | wc –l ---> It will display the
CPUs count
-----------------------------------------------------------------------------------------------------------------------
last: Show listing of last logged in users.
Syntax:
last [-R] [-num] [ -n num ] [-adiowx] [ -f file ] [ -t YYYYMMDDHHMMSS ] [name...] [tty...]
OPTIONS
-num This is a count telling last how many lines to show.
-t YYYYMMDDHHMMSS
Display the state of logins as of the specified time. This is useful, e.g., to
determine easily who was logged in at a particular time -- specify that time with
-t and look for "still logged in".
-f file
Specifies a file to search other than /var/log/wtmp.
-a Display the hostname in the last column. Useful in combination with the next
flag.
-d For non-local logins, Linux stores not only the host name of the remote host but
its IP number as well. This option translates the IP number back
into a hostname.
-i This option is like -d in that it displays the IP number of the remote host, but it
displays the IP number in numbers-and-dots notation.
#last
-----------------------------------------------------------------------------------------------------------------------
#cat /etc/shells : It will give all available shells in your system
-----------------------------------------------------------------------------------------------------------------------
#echo $SHELL : It will give you the current shell type.
-----------------------------------------------------------------------------------------------------------------------
How to change the Shell type?
-----------------------------------------------------------------------------------------------------------------------
netstat : Netstat prints information about the Linux networking subsystem.
# netstat -tupl
# netstat –tup
# netstat -a -n –o : Windows it will display all ports and which port is used by which pid
Linux : netstat -tulpn | grep :9080 it will display who is using porticular port
Windows: netstat -a -n -o Windows it will display all ports and which port is used by which
pid
AIX : netstat -Aan | grep LISTEN | grep 50000 it will display socket ID
(EX: f1000e0008b1cbb8 )
rmsock socket id we got withp revious command tcpcb
EX: rmsock f1000e0008b1cbb8 tcpcb
it will display the pid
-----------------------------------------------------------------------------------------------------------------------
lsof:
# lsof -i | grep 9060
-----------------------------------------------------------------------------------------------------------------------
cal : Displays a calendar.
#cal -3
#cal 10 1984
#cal 8 1984
-----------------------------------------------------------------------------------------------------------------------
clock : Determine processor time.
-----------------------------------------------------------------------------------------------------------------------
history : Displays the recently executed commands.
Typically when you type history from command line, it displays the command # and the
command. For auditing purpose, it may be beneficial to display the time stamp along with
the command as shown below.
When you’ve already executed a very long command, you can simply search history using
a keyword and re-execute the same command without having to type it fully. Press
Control+R and type the keyword. In the following example, I searched for red, which
displayed the previous command “cat /etc/redhat-release” in the history that contained the
word red.
# [Press Ctrl+R from the command prompt,which will display the reverse-i-search
prompt]
(reverse-i-search)`red': cat /etc/redhat-release
Note: Press enter when you see your command,which will execute the command from the
history
# cat /etc/redhat-release
Fedora release 9 (Sulphur)
Sometimes you want to edit a command from history before executing it. For e.g. you can
search for httpd, which will display service httpd stop from the command history, select
this command and change the stop to start and re-execute it again as shown below.
# [Press Ctrl+R from the command prompt,Which will display the reverse-i-search
prompt]
(reverse-i-search)`httpd': service httpd stop
[Note: Press either left arrow or right arrow key when you see your
command, which will display the command for you to edit, before executing it]
# service httpd start
# vi ~/.bash_profile
HISTFILE=/root/.commandline_warrior
In the following example date was typed three times, when you do history, you can see all
the 3 continuous occurrences of it. To eliminate duplicates, set HISTCONTROL to
ignoredups as shown below.
# date
Thu Apr 25 06:09:12 EDT 2013
# date
Thu Apr 25 06:09:14 EDT 2013
# date
Thu Apr 25 06:09:16 EDT 2013
# history | tail -10
1 date
2 date
3 date
4 history | tail -10
Note that there are three date commands in history, after executing date 3 times as
shown above
# export HISTCONTROL=ignoredups
# date
Note that there is only one date command in the history, even after executing date 3
times as shown above
The ignoredups shown above removes duplicates only if they are consecutive commands.
To eliminate duplicates across the whole history, set the HISTCONTROL to erasedups as
shown below.
# export HISTCONTROL=erasedups
# date
Thu Apr 25 06:18:44 EDT 2013
# date
Thu Apr 25 06:18:45 EDT 2013
# date
Thu Apr 25 06:18:47 EDT 2013
# service sendmail stop
Shutting down sm-client: [ OK ]
Shutting down sendmail: [ OK ]
# history | tail -5
3 history | tail -10
4 export HISTCONTROL=erasedups
5 date
6 service sendmail stop
7 history | tail -5
# pwd
/root
# service sendmail stop
Shutting down sendmail: [FAILED]
# history | tail -5
4 export HISTCONTROL=erasedups
5 date
6 pwd
7 service sendmail stop
8 history | tail -5
Note that the previous service sendmail stop after date got erased
When you execute a command, you can instruct history to ignore the command by setting
HISTCONTROL to ignorespace AND typing a space in front of the command as shown
below. I can see lot of junior sysadmins getting excited about this, as they can hide a
command from the history. It is good to understand how ignorespace works. But, as a
best practice, don’t hide purposefully anything from history.
# pwd
/root
# date
Thu Apr 25 07:43:27 EDT 2013
# whoami [Note that there is a space at the beginning of service,to ignore this command
from history]
root
# history | tail -10
1 export HISTCONTROL=ignorespace
2 pwd
3 date
4 history | tail -10
# export HISTSIZE=0
# history
# ----> Note that history did not display anything.
history. Please note that adding ls to the HISTIGNORE ignores only ls and not ls -l. So,
you have to provide the exact command that you would like to ignore from the history.
# export HISTIGNORE="pwd:date:whoami:ls:"
# pwd
/root
# date
Thu Apr 25 08:04:16 EDT 2013
# whoami
root
# ls
anaconda-ks.cfg Desktop ihslogs isus
Read_Me_IC2_Default.properties updilogs waslogs
install.log plglogs SERVERINFO vpd.properties
client_config_update.py ihsGSKitUpgradeLog.txt install.log.syslog
pluginGSKitUpgradeLog.txt typescript WAS
# who
root pts/0 2013-04-25 08:02
# history
1 export HISTIGNORE="pwd:date:whoami:ls:"
2 who
3 history
Note that history did not record pwd, date, whoami and ls.
-----------------------------------------------------------------------------------------------------------------------
reboot : To reboot the system.
#reboot
Once we execute the init 0 command we will get the below error. Means server got
shutdown.
-----------------------------------------------------------------------------------------------------------------------
type : Writes a description of the command type.
#type ps
#type man
#type cd
#type java
-----------------------------------------------------------------------------------------------------------------------
uptime : Shows how long the system has been up.
Syntax: uptime
e.g : uptime
-----------------------------------------------------------------------------------------------------------------------
How to check the java version?
java -version
-----------------------------------------------------------------------------------------------------------------------
Keystroke Function
Ctrl+s Stops scrolling of screen output
Ctrl+q Resumes scrolling of screen output
Delete Interrupts a command (Use Ctrl+c if this fails)
Ctrl+d Terminates login session (Use exit also)
Ctrl+h Erases text (if backspace key does’nt work)
Ctrl+u Kills command line without executing it
Ctrl+\ Kills command line without executing it
Ctrl+j Alternative to Enter
Ctrl+m Alternative to Enter
Sty sane Restore terminal to normal status
-----------------------------------------------------------------------------------------------------------------------
> is used to remove/nullify the contents from file, without deleting the file.
-----------------------------------------------------------------------------------------------------------------------
#cat /dev/null > bhaskar.txt : It will clear/null the contents of bhaskar.txt file.
-----------------------------------------------------------------------------------------------------------------------
#ls | tee teeoutput.txt: It will display the output in console as well into file also.
jobs -l: list only jobs that have change status since last notified by their status
-----------------------------------------------------------------------------------------------------------------------
env : Display environment, set environment for process
If you call env with no arguments, it displays the environment.
In Dev Server.
#env
-----------------------------------------------------------------------------------------------------------------------
How to set the class path?
Here we are setting the Java class path.
PATH=$PATH:/usr/java14/jre/bin
export PATH
echo $PATH
-----------------------------------------------------------------------------------------------------------------------
How do you see Linux server system reboot history?
#last reboot
#who --boot
#who –b Provided the most succinct reply
-----------------------------------------------------------------------------------------------------------------------
Disply top 5 files/directories taking your disk space in current directory?
-----------------------------------------------------------------------------------------------------------------------
#tree: List contents of directories in a tree-like format.
-----------------------------------------------------------------------------------------------------------------------
Errors:
#useradd manan
This issue occurs if there is passwd.lock or passwd- or passwd~ file in the /etc/directory.
These types of files will create when someone must have run the useradd command and
it did not finish correctly.
-----------------------------------------------------------------------------------------------------------------------
# vmstat -s
-----------------------------------------------------------------------------------------------------------------------
fdisk: fdisk stands (for “fixed disk or format disk“) is an most commonly used
command-line based disk manipulation utility for a Linux/Unix systems. With the
help of fdisk command you can view, create, resize, delete, change, copy and
move partitions on a hard drive using its own user friendly text based menu
driven interface.
In RedHat OS
In Cent OS
#fdisk -l /dev/xvdb
https://www.tecmint.com/fdisk-commands-to-manage-linux-disk-partitions/
-----------------------------------------------------------------------------------------------------------------------
root@ralbz2072 ~]# dmidecode -t 17: It Give the RAM information like Type of RAM(SD
RAM, DRAM or DDR2/3), Speed, Manufacture etc
-----------------------------------------------------------------------------------------------------------------------
cut : Cut command in unix (or linux) is used to remove sections from each line of files.
#cat cut_example.txt
Hi All,
I am Mithun Reddy L, working as a Java application developer in MT Manyatha Tech
Park.
I am very good in Linux administration as well as WebSphere Application server also.
#cut –c4 cut_example.txt: With the -c option, cut will cut out specific characters (i.e.,
columns) in the input lines. This will displays 4th character from each line of a file
cut_example.txt.
#cut -c1-3 cut_example.txt : It willextracts first 3 characters of each line from a file called
cut_example.txt.
#cut -c3- cut_example.txt : This will extracts from 3rd character to end of each line from
cut_example.txt.
#cut -c1-3 cut_example.txt : When you don’t specify a number before or after the ‘-’ , it
will print entire line as follows.
#cut -c1-3 cut_example.txt : It will displays only first field of each lines from /etc/passwd
file using the field delimiter : (colon). In this case, the 1st field is the username. The file
#grep "/bin/bash" /etc/passwd | cut -d':' -f1,6: It will displays username and home
directory of users who has the login shell as “/bin/bash”.
#grep "/bin/bash" /etc/passwd | cut -d':' -f1-4,6,7: It will displays range of fields specify
start field(we are selecting field 1 through 4) and end field ( 6 and 7) who has the login
shell as “/bin/bash”.
-----------------------------------------------------------------------------------------------------------------------
rsync: rsync stands for remote sync.
rsync utility is used to synchronize the files and directories from one location to another in
an effective way. Backup location could be on local server or on remote server.
Source and destination could be either local or remote. In case of remote, specify the
login name, remote server name and location.
Examples:
========
#rsync -azvr /home/isgproject/scripts/Java/Source/
/home/isgproject/scripts/Java/Target/
This command will sync the file from local server to remote server for specified directory.
This command will sync the file from remote server to local server for specified file.
-----------------------------------------------------------------------------------------------------------------------
I have a directory which contains files with different kinds of extensions .Everyday
a file with .log gets added to it, I want to extract the file with .log extension which is
created with today’s date.
If the date (in format YYYYMMDD) is not part of the log file then,
#!/bin/sh
file="/home/isgproject/scripts/ControlStatements/test.sh"
if test -r $file
then
echo "File has read access"
else
echo "File does not have read access"
fi
if test -w $file
then
echo "File has write permission"
else
echo "File does not have write permission"
fi
if test -x $file
then
echo "File has execute permission"
else
echo "File does not have execute permission"
fi
if test -f $file
then
echo "File is an ordinary file"
else
echo "This is sepcial file"
fi
if test -d $file
then
echo "File is a directory"
else
echo "This is not a directory"
fi
if test -s $file
then
echo "File size is not zero"
else
echo "File size is zero"
fi
if test -e $file
then
echo "File exists"
else
echo "File does not exist"
#sh test.sh
-----------------------------------------------------------------------------------------------------------------------
if test -f /usr/bin/java
then
echo "Java exists in /usr/bin/"
fi
Square brackets can be used to replace the test command in most command shells. Here
is an example of this. Note that the spaces between the brackets and the test operation
are vital here.
if [ -f /usr/bin/java ]
then
echo "Java exists in /usr/bin/"
fi
-----------------------------------------------------------------------------------------------------------------------
expr : The expr command reads the Expression parameter, evaluates it, and writes the
result to standard output.
Syntax : expr << Argument 1 >> << Operator >> << Argument 2 >>
Examples :
#expr 2 + 2
#expr 2 - 2
#expr 2 \* 2
#expr 2 / 2
#expr 2 = 2
#expr 2 = 3
#expr 2 \< 2
#expr 2 \< 3
#expr 2 \> 2
#expr 2 \> 1
#expr 2 \! 1
#expr 2 \! 2
#expr 2 != 2
#expr Bhaskar : Bhaskar ---> Partial match and returns the number of characters
matched.
#expr Bhaskar : Bhaskar
#expr Bhaskar : Bhas
#expr Bhaskar : '.*' ---> Regular expression to match any number of characters
#expr Bhaskar : '....\(...\)' ---> To print the matched characters instead of number of
matching positions.
expr `echo "123671" | sed -e 's/[0-9]/ + &/g' -e 's/^ +//g'` : It will give sum of digits of a
number.
-----------------------------------------------------------------------------------------------------------------------
How to find Apache version?
Ans)
# find / -name apachectl
#cd /opt/MT/HTTPServer/bin/apachectl
# ./apachectl –v
-----------------------------------------------------------------------------------------------------------------------
Managing Bash with Key Sequences
Ctrl+C : This key sequence is used to terminate the command that’s running in your
shell.
Ctrl+D : This key sequence is used to send the “eod of the file” (EOF) signal to the
command. We can also use this key sequence to close the shell session.
Ctrl+R : This is the reversed search feature. It will open the “reverse I-search” prompt,
which helps you locate commands that you used previously. This key sequence searches
the bash history. This feature is useful when working with longer commands.
longer commands.
We can start these jobs again with the fg and bg commands. To start the command
again, we need to see the job number that command/job using. We can see the list of job
numbers with jobs command.
Shift+PageUp and
Shift+PageDown Browse terminal buffer (to see text that has "scrolled off" the
screen).
-----------------------------------------------------------------------------------------------------------------------
ping: It is a network tool that tests of whether a particular host is up and reachable on the
network.
The default behavior of ping is to send a 64 byte ICMP (Internet Control Messaging
Protocol) packet to the specified host every second until you cancel the operation with a
Ctrl+c. When the ping operation is cancelled or done, ping will report summary statistics
such as average pocket loss, number of pockets sent/received, etc.
#ping ralbz2072.cloud.dst.mt.com
#ping –c 4 ralbz2072.cloud.dst.mt.com
With -i option we set the interval seconds between sending each packet. The default is to
wait for one second between each packet normally.
#ping -i 3 -c 5 devpcpdgdst02.w3-969.mt.com
-----------------------------------------------------------------------------------------------------------------------
traceroute:
# traceroute b03ziwas11c.boulder.mt.com
-----------------------------------------------------------------------------------------------------------------------
How to find weather system type is 32 bit or 64 bit?
Ans) Below command will give the weather system type is 32 bit or 64 bit
#getconf LONG_BIT
-----------------------------------------------------------------------------------------------------------------------
How to change the prompt disply?
Ans) Add the below lines in .bashrc (BASH) or .kshrc (KSH) in respective home directory.
PS1='$PWD $'
export PS1
-----------------------------------------------------------------------------------------------------------------------
sort: Sort allows us to sort data in numeric, alphabetic and reverse order whether it’s of
column or multiple columns with delimiters. Sort order can be restricted to individual
columns and then merged to one single file. Sorting becomes handy in many situations.
#cat names.txt
#sort names.txt
#cat numbers.txt
#sort numbers.txt
#sort -n numbers.txt
#sort -nr numbers.txt
-----------------------------------------------------------------------------------------------------------------------
https://www.geeksforgeeks.org/sort-command-linuxunix-examples/