Thursday, March 31, 2016

Friday, March 25, 2016

all Linux commands in detail.

File Manipulation & Directory Commands


To check the present working directory.


To see content of directory.
ls  -l    :To see more details  including the permissions regarding the contents of directory.
ls  -a    : to see contents including hidden files of directory.
ls ???* : to see a file whose length is more than 3 characters.
ls –la    : To see the file permissions, owners, and sizes of all files, enter:


cat is used to create a file and see the content of  file.
cat  > filename :to create a file and write content in that.
To append file1 onto the end of file2, enter:
  cat file1 >> file2
To view the contents of a file named myfile, enter:
  cat myfile


Create a directory.
Ex: mkdir directoryname


To change directory.
This command changes the current directory location. By default, the Unix login session begins in the home directory.
(i).To switch to a subdirectory (of the current directory) named myfiles,    enter:  cd myfiles
(ii).To switch to a directory named /home/wissen/sdm_docs, enter:
 cd /home/wissen/sdm_docs
(iii).To move to the parent directory of the current directory, enter:   cd ..
(iv).To move to the root directory, enter:   cd /
(v).To return to the home directory, enter:   cd


This command will remove (destroy) a file. We should enter this command with the  -i  option, so that we'll be asked to confirm each file deletion.
(i)rm –i filename
(ii).rm –rf   <file or Directory>


Copy files from one location to another location.
Ex: cp file1 file2 
(i).cp –I file1 file2


Move files from source to destination. and for rename also.
Ex: mv file1 file2  


Display the content ascending order.
Ex: sort filename.


Display first 10 lines in a file
Ex: head  filename



Display last 10 lines in a file
Ex: tail filename


The find command lists all of the files within a directory and its   subdirectories that match a set of conditions. This command is most commonly used to find all of the files that have a certain name.
Example :To find all of the files named myfile.txt in the current directory and all of its subdirectories, enter:
       find . -name myfile.txt -print
To look in the current directory and its subdirectories for all of the files that end in the extension .txt , enter:
       find . -name "*.txt" -print


This utility displays the contents of a text file one screen at a time, waiting for we to  press the Spacebar between screens. This lets we read text without it scrolling quickly off the screen.
Example :To read the contents of a file named textfile in the current directory, enter: 
$ less textfile
The less utility is often used for reading the output of other commands.
       For example, to read the output of the ls command one screen at a time, enter:
        $ ls -la | less
To exit less after viewing the file, press q .


 Copy files or directories from one host to another host



Remote  file copy host on network.


Compress or extract files.


            Create Tape ARchives (TAR) and add or extract files.
            Ex: tar -cvwf file.tar myfile.txt
             Ex: tar -xvwf myfile.tar



To execute last commands.


Nohup utility which allows to run command./process or shell script that can      continue running in the background after you log out from a shell
nohup command-name &


Displays the full path of the file


This commands is used to copy the files from windows to unix
            Syntax: pscp  <sourcefile>  username@hostname:<destinationpath>


This is used to search a particular pattern(string) in a file
Ex: grep java filename
           Ex: ps  -ef | grep java  àjava related processes are displaying


 This command is used to compare the two files byte by byte.
  Ex:cmp file1 file2
  We can compare directories also by using cmpdir.
   Ex:dircmp  -r  /home/test1  /home/test2


 This command is used to compare the two files line by line.
  Ex: diff  file1  file2


Side by side compare


 This is text editor used to create ,edit  a file 
    $ vi filename
                               To quit without savingà: q!
 To save and executeà: x   (or): wq
                          0àmove to the beginning of the line
                          $-->move to the end of the line
                          Ctrl-fàscroll forward
                          Ctrl-bàscroll backward


          To Change shell
            Ex: chsh –s ksh <username>

User & User Group Commands


Who logged on system what they are doing.


  Display current user and group id names.


 Displays current logged in user information


 Display current logged in user with full information(including logged time, name)


 Displays current user.


Terminate the session


Print the username of the users currently logged in to the current host



 Print the groups a user is in.


                Changes the owner or group associated with a file.
                Ex: Change the owner of /var/run/ to 'root'
                    chown root /var/run/





Disk & Memory Commands


 Mounting is done with the mount command
$ mount /dev/fd0 /mnt/floppy


 Unmounting is done with the umount command
umount /mnt/floppy


            To give file permission
            Ex: chmod 777 filename


 Display disk used spaces


Display disk free spaces


 It displays status of memories.

Sar(System Activity Report)

Displays the swap, disk space, I/O, system and cpu status.


Troubleshooting Commands


 Displays Running  process with PID
·         ps   - a:
·         ps   -u:
·         ps –ef:


Displays the contents of a file or standard input to all logged-in users.


 Displays host name.


Communicating with other host. Uses the telnet protocol to connect  to another remote computer.
  Syntax:  telnet [ host [ port ] ]
  Ex:telnet  ipaddress/hostname


Displays the list what are the commands you are executed. List of all the commands that you have entered. Each command is given a number according to the order it was entered.


 find files by name


 Terminates a process.
§  kill -9 <process id>
§  Kill -3 <process id>àthis is for thread dump


  Sends ICMP ECHO_REQUEST packets to network hosts.
        Ex:ping  <ipaddress>


 Used to record interactive session.
            Ex: script –a –f filename


 Displays network information


Displays the environment variable


Displays the variable in the standard out put
Ex: $echo $PATH     à Displays Path value


 Used to set environment variable
            Ex: export PATH=<path>


 Pidof  finds  the process id (pids) of the named programs.


      Fuser Displays the pids of processes using the specified files or file systems
      Ex: fuser <file name>
            Fuser  7001/tcp   àit will display process id associated with port 7001


Configures or displays network interface parameters for a network using TCP/IP


                Queries a name server for a host or domain lookup
            Ex: nslookup

tracert / traceroute

The traceroute command traces the network path of Internet routers that packets take as they are forwarded from your computer to a destination address
                Ex: tracert


                Displays the current date of the system



FAQs (?) :-

What tools or commands are recommended to troubleshoot performance related problems?

A:   Following are the basic or essential tools that every Linux or UNIX system admin should be                               aware of:

a) top
b) sar
c) vmstat
d) iostat
e) free

Command to display the Linux processes in a hierarchical format i.e. Parent and child format

·         Process list based on process id -- pstree <PID>
·         Process list based on username -- pstree <user name>

How to browse through directory structure

·         tree -d will display only the directories. i.e Files will not be displayed.
·         tree -a will display hidden files along with directories and files.
·         tree -s will display the file size. While using this option, it prints out the size of the files along with the file names.
·         tree -p will display the permissions along with the files.

How can we open files having different file formats?

By using “less” we can see the contents of a file
·         less filename.pdf
·         less filename.doc
·         less filename.tar
·         less
·         less filename.iso
·         less filename.rpm

How to Find Files Based on Access / Modification / Change Time

You can find files based on following three file time attribute.

Access time of the file. Access time gets updated when the file accessed.
Modification time of the file. Modification time gets updated when the file content modified.
Change time of the file. Change time gets updated when the inode data changes.
min argument treats its argument as minutes.
time argument treats its argument as 24 hours.
                  Example 1: Find files whose content got updated within last 1 hour
Following example will find files in the current directory and sub-directories, whose  content got updated within last 1 hour (60 minutes)
find . -mmin -60
In the same way, following example finds all the files (under root file system /) that got updated within the last 24 hours (1 day).
find / -mtime -1
 Example 2: Find files which got accessed before 1 hour
To find the files based up on the file access time, the option -amin, and -atime is used.
find -amin -60
find / -atime -1

Example 3: Find files which got changed exactly before 1 hour
To find the files based up on the file inode change time, the option -cmin, and -ctime is used.
find . -cmin -60
find / -ctime -1
Example 4: Restricting the find output only to files. (Display only files as find command results)
The following find command displays files that are accessed in the last 30 minutes.
find /etc/sysconfig -amin -30
[Note: The above output contains both files and directories]
find /etc/sysconfig -amin -30 -type f

How Do I Make Backups?

A: You can back up a directory hierarchy or complete file system to any media using GNU tar or cpio, the standard *nix tools for this purpose. tar seems to be the more commonly used program currently, and includes command line options to make compressed, incremental, and multi-volume backups.
How Do I Add Temporary Swap Space?

A: In addition to a swap partition, Linux can also use a swap file. Some programs, like g++, can use huge amounts of virtual memory, requiring the temporary creation of extra space. To install an extra 64 MB of swap space, for example, use the following shell commands:
# dd if=/dev/zero of=/swap bs=1024 count=65535
# mkswap /swap
# swapon /swap
The count= argument to dd determines how big the swap file will be. In this example the swap file's name is /swap, but the name and location are, generally, arbitrary, depending only on the file system's available space and your having write permissions in the directory.
When you don't need the swap space any more, remove it with the following statements:
# swapoff /swap
# rm /swap

What Is a core File?
A: A core file is created when a program terminates unexpectedly, due to a bug, or a violation of the operating system's or hardware's protection mechanisms. The operating system kills the program and creates a core file that programmers can use to figure out what went wrong. It contains a detailed description of the state that the program was in when it died.
If would like to determine what program a core file came from, use the file command, like this:
 $ file core
That will tell you the name of the program that produced the core dump. You may want to write the maintainer(s) of the program, telling them that their program dumped core.
[Eric Hanchrow]
 How To Enable or Disable Core Dumps?
A: By using the ulimit command in bash, the limit command in tcsh, or the rlimit command in ksh. See the appropriate manual page for details.
This setting affects all programs run from the shell (directly or indirectly), not the whole system.
If you wish to enable or disable core dumping for all processes by default, you can change the default setting in linux/sched.h. Refer to definition of INIT_TASK, and look also in linux/resource.h.
A: $ top

How do I find out Linux CPU Utilization individually?

A:$ mpstat

How can I find out Linux Resource utilization using vmstat command?

vmstat command reports information about processes, memory, paging, block IO, traps, and cpu activity
$ vmstat -S M

How to watch the log file in real time?

A: tail –f  <log_file_name>

How to Find Out Virtual Memory PAGESIZE?

A:    $ getconf PAGESIZE  or   getconf PAGE_SIZE

How much RAM does my Linux desktop PC have?

A:    $ free –m
       $ free –mt

How to find process id of running program?

A:   Pidof  finds  the process id (pids) of the named programs (Make sure you can see PID of your         service)
      $ pidof  <service-name>
How can we resolve hostname?
A:                # dig
                    # nslookup
 How to find out the total amount of free and used physical and swap memory in the system?
A:  $free
What is the command to see whether the host is alive or dead?
A: $ ping <ip-address>

How to get Information about Active / Inactive Memory Pages?

A: $ vmstat –a

What is the command to know how long the system is up and running?

A: $ uptime

 How to find out process memory usage?

A: $ pmap –d PID

How to check out how much hard drive space is left?

A: $ df –h


 How to list all the files that are currently open on system?

A: $ lsof


What is the command to find where the binary is stored and its library?

A: $ whereis <name of the binary>


How to get the Command line parameters of a process?

ps -fp <pid>
cat /proc/<pid>/cmdline

How to know which process is using a particular port?

Netstat –ap | grep 7001


Command to display the Process hierarchy?

$ ps -e -o pid, args --forest


How to take thread dump?

Find java process
·         Ps –ef | grep java
Take thread dump
·         Kill  -3 <pid>


Check connectivity between two systems?

Ping <ipaddress or Host name>

Print list of file/files are consuming more disk space?

                Find . –type f –exec  ls –sh  {} \; | sort –n –r

How do I find out the cpu architecture information under Linux OS?

A: $ proc/cpuinfo
    $ less proc/cpuinfo
   $ lscpu   à It lists cpu architecture information

How to display currently running process?

$ ps -ef
  • -e  to display all the processes.
  • -f  to display full format listing

How to List the Process based on the UID?

$  ps -f  -u  wwwrun,postfix

How to get the Linux version?

$ Uname -a

List down all the Environment variables?

$ env

How to get size of the folder ..?

$du –ch <foldername> | grep total
Example: [sdadmin@hostserver application]$ du -ch CDIAD | grep total
                   1.7G    total

Wednesday, March 23, 2016

Run WildFly8 as a service on Windows

Go to bin\service directory; use an x64 file explorer so that the x64 service wrapper will be launched.
At a command prompt enter service install and press Enter. The service is now installed but need to be manually configured for Automatic start-up.
Note for WildFly 10bin\service directory doesn't exist any more, it's content was moved indocs\contrib\scripts\service; the above described procedure is still valid but service must be copied tobin before applying it.