DISCLAIMER : Please note that blog owner takes no responsibility of any kind for any type of data loss or damage by trying any of the command/method mentioned in this blog. You may use the commands/method/scripts on your own responsibility.If you find something useful, a comment would be appreciated to let other viewers also know that the solution/method work(ed) for you.
Input/Output Redirection
Unix provides the capability to change where standard input comes from, or where output goes using a concept called Input/Output (I/O) redirection. I/O redirection is accomplished using a redirection operator which allows the user to specify the input or output data be redirected to (or from) a file. Note that redirection always results in the data stream going to or coming from a file.
The simplest case to demonstrate this is basic output redirection. The output redirection operator is the > (greater than) symbol, and the general syntax looks as follows:
command > output_file_spec
Spaces around the redirection operator are not mandatory, but do add readability to the command. Thus in our ls example from above, we can observe the following use of output redirection:
$ ls > my_files [Enter]
$
Notice there is no output appearing after the command, only the return of the prompt. Why is this, you ask? This is because all output from this command was redirected to the file my_files. Observe in the following diagram, no data goes to the terminal screen, but to the file instead.
Examining the file as follows results in the contents of the my_files being displayed:
$ cat my_files [Enter]
foo
bar
fred
barney
dino $
In this example, if the file my_files does not exist, the redirection operator causes its creation, and if it does exist, the contents are overwritten. Consider the example below:
$ echo "Hello World!" > my_files [Enter]
$ cat my_files [Enter]
Hello World!
Notice here that the previous contents of the my_files file are gone, and replaced with the string "Hello World!" This might not be the most desirable behavior, so the shell provides us with the capability to append output to files. The append operator is the >>. Thus we can do the following:
$ ls > my_files [Enter]
$ echo "Hello World!" >> my_files [Enter]
$ cat my_files [Enter]
foo
bar
fred
barney
dino
Hello World!
The first output redirection creates the file if it does not exist, or overwrites its contents if it does, and the second redirection appends the string "Hello World!" to the end of the file. When using the append redirection operator, if the file does not exist, >> will cause its creation and append the output (to the empty file). The ability also exists to redirect the standard input using the input redirection operator, the < (less than) symbol. Note the point of the operator implies the direction. The general syntax of input redirection looks as follows:
command < input_file_spec
Looking in more detail at this, we will use the wc (word count) command. The wc command counts the number of bytes, word and lines in a file. Thus if we do the following using the file created above, we see:
$ wc my_files [Enter]
6 7 39 my_files
where the output indicates 6 lines, 7 words and 39 bytes, followed by the name of the file wc opened.
We can also use wc in conjunction with input redirection as follows:
$ wc < my_files [Enter]
6 7 39
Note here that the numeric values are as in the example above, but with input redirection, the file name is not listed. This is because the wc command does not know the name of the file, only that it received a stream of bytes to count.
Someone will certainly ask if input redirection and output redirection can be combined, and the answer is most definitely yes. They can be combined as follows:
$ wc < my_files > wc_output [Enter]
$
There is no output sent to the terminal screen since all output was sent to the file wc_output. If we then looked at the contents of wc_output, it would contain the same data as above.
To this point, we have discussed the standard input stream (descriptor 0) and the standard output stream (descriptor 1). There is another output stream called standard error (stderr) which has file descriptor 2. Typically when programs return errors, they return these using the standard error channel. Both stdout and stderr direct output to the terminal by default, so distinguishing between the two may be difficult. However each of these output channels can be redirected independently. Refer to the diagram below:
The standard error redirection operator is similar to the stdout redirection operator and is the 2> (two followed by the greater than, with no spaces) symbol, and the general syntax looks as follows:
command 2> output_file_spec
Thus to show an example, we observe the following:
$ ls foo bar 2> error_file [Enter]
foo
$ cat error_file [Enter]
ls: bar: No such file or directory
Note here that only the standard output appears once the standard error stream is redirected into the file named error_file, and when we display the contents of error_file, it contains what was previously displayed on the termimal. To show another example:
$ ls foo bar > foo_file 2> error_file [Enter]
$
$ cat foo_file [Enter]
foo
$ cat error_file [Enter]
ls: bar: No such file or directory
In this case both stdout and stderr were redirected to file, thus no output was sent to the terminal. The contents of each output file was what was previously displayed on the screen.
Note there are numerous ways to combine input, output and error redirection. Another relevant topic that merits discussion here is the special file named /dev/null (sometimes referred to as the "bit bucket"). This virtual device discards all data written to it, and returns an End of File (EOF) to any process that reads from it. I informally describe this file as a "garbage can/recycle bin" like thing, except there's no bottom to it. This implies that it can never fill up, and nothing sent to it can ever be retrieved. This file is used in place of an output redirection file specification, when the redirected stream is not desired. For example, if you never care about viewing the standard output, only the standard error channel, you can do the following:
$ ls foo bar > /dev/null [Enter]
ls: bar: No such file or directory
In this case, successful command output will be discarded. The /dev/null file is typically used as an empty destination in such cases where there is a large volume of extraneous output, or cases where errors are handled internally so error messages are not warranted. One final miscellaneous item is the technique of combining the two output streams into a single file. This is typically done with the 2>&1 command, as follows:
$ command > /dev/null 2>&1 [Enter]
$
Here the leftmost redirection operator (>) sends stdout to /dev/null and the 2>&1 indicates that channel 2 should be redirected to the same location as channel 1, thus no output is returned to the terminal.
The simplest case to demonstrate this is basic output redirection. The output redirection operator is the > (greater than) symbol, and the general syntax looks as follows:
command > output_file_spec
Spaces around the redirection operator are not mandatory, but do add readability to the command. Thus in our ls example from above, we can observe the following use of output redirection:
$ ls > my_files [Enter]
$
Notice there is no output appearing after the command, only the return of the prompt. Why is this, you ask? This is because all output from this command was redirected to the file my_files. Observe in the following diagram, no data goes to the terminal screen, but to the file instead.
$ cat my_files [Enter]
foo
bar
fred
barney
dino $
In this example, if the file my_files does not exist, the redirection operator causes its creation, and if it does exist, the contents are overwritten. Consider the example below:
$ echo "Hello World!" > my_files [Enter]
$ cat my_files [Enter]
Hello World!
Notice here that the previous contents of the my_files file are gone, and replaced with the string "Hello World!" This might not be the most desirable behavior, so the shell provides us with the capability to append output to files. The append operator is the >>. Thus we can do the following:
$ ls > my_files [Enter]
$ echo "Hello World!" >> my_files [Enter]
$ cat my_files [Enter]
foo
bar
fred
barney
dino
Hello World!
The first output redirection creates the file if it does not exist, or overwrites its contents if it does, and the second redirection appends the string "Hello World!" to the end of the file. When using the append redirection operator, if the file does not exist, >> will cause its creation and append the output (to the empty file). The ability also exists to redirect the standard input using the input redirection operator, the < (less than) symbol. Note the point of the operator implies the direction. The general syntax of input redirection looks as follows:
command < input_file_spec
Looking in more detail at this, we will use the wc (word count) command. The wc command counts the number of bytes, word and lines in a file. Thus if we do the following using the file created above, we see:
$ wc my_files [Enter]
6 7 39 my_files
where the output indicates 6 lines, 7 words and 39 bytes, followed by the name of the file wc opened.
We can also use wc in conjunction with input redirection as follows:
$ wc < my_files [Enter]
6 7 39
Note here that the numeric values are as in the example above, but with input redirection, the file name is not listed. This is because the wc command does not know the name of the file, only that it received a stream of bytes to count.
Someone will certainly ask if input redirection and output redirection can be combined, and the answer is most definitely yes. They can be combined as follows:
$ wc < my_files > wc_output [Enter]
$
There is no output sent to the terminal screen since all output was sent to the file wc_output. If we then looked at the contents of wc_output, it would contain the same data as above.
To this point, we have discussed the standard input stream (descriptor 0) and the standard output stream (descriptor 1). There is another output stream called standard error (stderr) which has file descriptor 2. Typically when programs return errors, they return these using the standard error channel. Both stdout and stderr direct output to the terminal by default, so distinguishing between the two may be difficult. However each of these output channels can be redirected independently. Refer to the diagram below:
The standard error redirection operator is similar to the stdout redirection operator and is the 2> (two followed by the greater than, with no spaces) symbol, and the general syntax looks as follows:
command 2> output_file_spec
Thus to show an example, we observe the following:
$ ls foo bar 2> error_file [Enter]
foo
$ cat error_file [Enter]
ls: bar: No such file or directory
Note here that only the standard output appears once the standard error stream is redirected into the file named error_file, and when we display the contents of error_file, it contains what was previously displayed on the termimal. To show another example:
$ ls foo bar > foo_file 2> error_file [Enter]
$
$ cat foo_file [Enter]
foo
$ cat error_file [Enter]
ls: bar: No such file or directory
In this case both stdout and stderr were redirected to file, thus no output was sent to the terminal. The contents of each output file was what was previously displayed on the screen.
Note there are numerous ways to combine input, output and error redirection. Another relevant topic that merits discussion here is the special file named /dev/null (sometimes referred to as the "bit bucket"). This virtual device discards all data written to it, and returns an End of File (EOF) to any process that reads from it. I informally describe this file as a "garbage can/recycle bin" like thing, except there's no bottom to it. This implies that it can never fill up, and nothing sent to it can ever be retrieved. This file is used in place of an output redirection file specification, when the redirected stream is not desired. For example, if you never care about viewing the standard output, only the standard error channel, you can do the following:
$ ls foo bar > /dev/null [Enter]
ls: bar: No such file or directory
In this case, successful command output will be discarded. The /dev/null file is typically used as an empty destination in such cases where there is a large volume of extraneous output, or cases where errors are handled internally so error messages are not warranted. One final miscellaneous item is the technique of combining the two output streams into a single file. This is typically done with the 2>&1 command, as follows:
$ command > /dev/null 2>&1 [Enter]
$
Here the leftmost redirection operator (>) sends stdout to /dev/null and the 2>&1 indicates that channel 2 should be redirected to the same location as channel 1, thus no output is returned to the terminal.
Redirection Summary
Redirection Operator | Resulting Operation |
---|---|
command > file | stdout written to file, overwriting if file exists |
command >> file | stdout written to file, appending if file exists |
command < file | input read from file |
command 2> file | stderr written to file, overwriting if file exsits |
command 2>> file | stderr written to file, appending if file exists |
command > file 2>&1 | stdout written to file, stderr written to same file descriptor |
Difference Between Linux and UNIX
UNIX is copyrighted name only big companies are allowed to use the UNIX copyright and name, so IBM AIX and Sun Solaris and HP-UX all are UNIX operating systems. The Open Group holds the UNIX trademark in trust for the industry, and manages the UNIX trademark licensing program.
Most UNIX systems are commercial in nature.
Linux is a UNIX Clone
But if you consider Portable Operating System Interface (POSIX) standards then Linux can be considered as UNIX. To quote from Official Linux kernel README file:
Linux is a Unix clone written from scratch by Linus Torvalds with assistance from a loosely-knit team of hackers across the Net. It aims towards POSIX compliance.
However, "Open Group" do not approve of the construction "Unix-like", and consider it misuse of their UNIX trademark.
Linux Is Just a Kernel
Linux is just a kernel. All Linux distributions includes GUI system + GNU utilities (such as cp, mv, ls,date, bash etc) + installation & management tools + GNU c/c++ Compilers + Editors (vi) + and various applications (such as OpenOffice, Firefox). However, most UNIX operating systems are considered as a complete operating system as everything come from a single source or vendor.
As I said earlier Linux is just a kernel and Linux distribution makes it complete usable operating systems by adding various applications. Most UNIX operating systems comes with A-Z programs such as editor, compilers etc. For example HP-UX or Solaris comes with A-Z programs.
License and cost
Linux is Free (as in beer [freedom]). You can download it from the Internet or redistribute it under GNU licenses. You will see the best community support for Linux. Most UNIX like operating systems are not free (but this is changing fast, for example OpenSolaris UNIX). However, some Linux distributions such as Redhat / Novell provides additional Linux support, consultancy, bug fixing, and training for additional fees.
User-Friendly
Linux is considered as most user friendly UNIX like operating systems. It makes it easy to install sound card, flash players, and other desktop goodies. However, Apple OS X is most popular UNIX operating system for desktop usage.
Security Firewall Software
Linux comes with open source netfilter/iptables based firewall tool to protect your server and desktop from the crackers and hackers. UNIX operating systems comes with its own firewall product (for example Solaris UNIX comes with ipfilter based firewall) or you need to purchase a 3rd party software such as Checkpoint UNIX firewall.
Backup and Recovery Software
UNIX and Linux comes with different set of tools for backing up data to tape and other backup media. However, both of them share some common tools such as tar, dump/restore, and cpio etc.
File Systems
Linux by default supports and use ext3 or ext4 file systems.
UNIX comes with various file systems such as jfs, gpfs (AIX), jfs, gpfs (HP-UX), jfs, gpfs (Solaris).
System Administration Tools
UNIX comes with its own tools such as SAM on HP-UX.
Suse Linux comes with Yast
Redhat Linux comes with its own gui tools called redhat-config-*.
However, editing text config file and typing commands are most popular options for sys admin work under UNIX and Linux.
System Startup Scripts
Almost every version of UNIX and Linux comes with system initialization script but they are located in different directories:
HP-UX - /sbin/init.d
AIX - /etc/rc.d/init.d
Linux - /etc/init.d
End User Perspective
The differences are not that big for the average end user. They will use the same shell (e.g. bash or ksh) and other development tools such as Perl or Eclipse development tool.
System Administrator Perspective
Again, the differences are not that big for the system administrator. However, you may notice various differences while performing the following operations:
Software installation procedure
Hardware device names
Various admin commands or utilities
Software RAID devices and mirroring
Logical volume management
Package management
Patch management
UNIX Operating System Names
A few popular names:
HP-UX
IBM AIX
Sun Solairs
Mac OS X
IRIX
Linux Distribution (Operating System) Names
A few popular names:
Redhat Enterprise Linux
Fedora Linux
Debian Linux
Suse Enterprise Linux
Ubuntu Linux
Common Things Between Linux & UNIX
Both share many common applications such as:
GUI, file, and windows managers (KDE, Gnome)
Shells (ksh, csh, bash)
Various office applications such as OpenOffice.org
Development tools (perl, php, python, GNU c/c++ compilers)
Posix interface
Most UNIX systems are commercial in nature.
Linux is a UNIX Clone
But if you consider Portable Operating System Interface (POSIX) standards then Linux can be considered as UNIX. To quote from Official Linux kernel README file:
Linux is a Unix clone written from scratch by Linus Torvalds with assistance from a loosely-knit team of hackers across the Net. It aims towards POSIX compliance.
However, "Open Group" do not approve of the construction "Unix-like", and consider it misuse of their UNIX trademark.
Linux Is Just a Kernel
Linux is just a kernel. All Linux distributions includes GUI system + GNU utilities (such as cp, mv, ls,date, bash etc) + installation & management tools + GNU c/c++ Compilers + Editors (vi) + and various applications (such as OpenOffice, Firefox). However, most UNIX operating systems are considered as a complete operating system as everything come from a single source or vendor.
As I said earlier Linux is just a kernel and Linux distribution makes it complete usable operating systems by adding various applications. Most UNIX operating systems comes with A-Z programs such as editor, compilers etc. For example HP-UX or Solaris comes with A-Z programs.
License and cost
Linux is Free (as in beer [freedom]). You can download it from the Internet or redistribute it under GNU licenses. You will see the best community support for Linux. Most UNIX like operating systems are not free (but this is changing fast, for example OpenSolaris UNIX). However, some Linux distributions such as Redhat / Novell provides additional Linux support, consultancy, bug fixing, and training for additional fees.
User-Friendly
Linux is considered as most user friendly UNIX like operating systems. It makes it easy to install sound card, flash players, and other desktop goodies. However, Apple OS X is most popular UNIX operating system for desktop usage.
Security Firewall Software
Linux comes with open source netfilter/iptables based firewall tool to protect your server and desktop from the crackers and hackers. UNIX operating systems comes with its own firewall product (for example Solaris UNIX comes with ipfilter based firewall) or you need to purchase a 3rd party software such as Checkpoint UNIX firewall.
Backup and Recovery Software
UNIX and Linux comes with different set of tools for backing up data to tape and other backup media. However, both of them share some common tools such as tar, dump/restore, and cpio etc.
File Systems
Linux by default supports and use ext3 or ext4 file systems.
UNIX comes with various file systems such as jfs, gpfs (AIX), jfs, gpfs (HP-UX), jfs, gpfs (Solaris).
System Administration Tools
UNIX comes with its own tools such as SAM on HP-UX.
Suse Linux comes with Yast
Redhat Linux comes with its own gui tools called redhat-config-*.
However, editing text config file and typing commands are most popular options for sys admin work under UNIX and Linux.
System Startup Scripts
Almost every version of UNIX and Linux comes with system initialization script but they are located in different directories:
HP-UX - /sbin/init.d
AIX - /etc/rc.d/init.d
Linux - /etc/init.d
End User Perspective
The differences are not that big for the average end user. They will use the same shell (e.g. bash or ksh) and other development tools such as Perl or Eclipse development tool.
System Administrator Perspective
Again, the differences are not that big for the system administrator. However, you may notice various differences while performing the following operations:
Software installation procedure
Hardware device names
Various admin commands or utilities
Software RAID devices and mirroring
Logical volume management
Package management
Patch management
UNIX Operating System Names
A few popular names:
HP-UX
IBM AIX
Sun Solairs
Mac OS X
IRIX
Linux Distribution (Operating System) Names
A few popular names:
Redhat Enterprise Linux
Fedora Linux
Debian Linux
Suse Enterprise Linux
Ubuntu Linux
Common Things Between Linux & UNIX
Both share many common applications such as:
GUI, file, and windows managers (KDE, Gnome)
Shells (ksh, csh, bash)
Various office applications such as OpenOffice.org
Development tools (perl, php, python, GNU c/c++ compilers)
Posix interface
Using VRTSexplorer utility to gather information useful for Symantec Corporation Technical Support
VRTSexplorer , also known as
Veritas Explorer, VxExplorer, vxexplorer, and vxexplore,
is a tool provided by Symantec Corporation Technical Support that is executed
on a host to gather some of the information that may be needed by a Support
Engineer to troubleshoot an issue. The output of this utility is a compressed
tar file that must be sent to Support. The information collected may not be
sufficient to resolve the issue, but it is likely to give very relevant
information about it. This utility will run on Solaris, Solaris x64, SUSE
Linux, Red Hat Linux, AIX, and HP-UX.
Note: No user data is collected by the VRTSexplorer utility. Only the technical information about some server configuration and the installed Veritas products are collected. For the exact information that is collected by the VRTSexplorer utility, and other additional information refer to the README located in the VRTSexplorer directory after downloading and untarring.
The use of VRTSexplorer utility involves three different steps:
Note: No user data is collected by the VRTSexplorer utility. Only the technical information about some server configuration and the installed Veritas products are collected. For the exact information that is collected by the VRTSexplorer utility, and other additional information refer to the README located in the VRTSexplorer directory after downloading and untarring.
The use of VRTSexplorer utility involves three different steps:
1. Obtaining
VRTSexplorer
2. Executing the VRTSexplorer binary
3. Sending the output to Symantec Technical Support
2. Executing the VRTSexplorer binary
3. Sending the output to Symantec Technical Support
These
steps are detailed below:
1. Obtaining the package that contains the VRTSexplorer utility:
1. Obtaining the package that contains the VRTSexplorer utility:
Note: The VRTSexplorer utility is
packaged with the Symantec Support Tools, VRTSspt, package which is
included on the product CDs and available for download. If this package is
installed on the host, this step can be skipped unless the latest VRTSexplorer
utility is to be run, as the utility is located in the /opt/VRTSspt/VRTSexplorer
directory. For more information about the Symantec Support Tools package and
the tools that it contains (VRTSexplorer, FirstLook, metasave, vxbench, etc.),
please refer to the Related Documents section below. Otherwise, the VRTSexplorer
utility must be downloaded from the Symantec FTP site. The latest version
will always be on the FTP site. The package can be downloaded and the binary
executed from any directory. However, to remain consistent with installed
applications, extract the package in the /opt directory.
To download the VRTSexplorer utility, follow the below instructions:
Connect to the FTP site:
# ftp ftp.veritas.com
The below message appears with a prompt for a login name. Please see technote TECH66995 in related items below for logon credentials.
Connected to ftp.veritas.com
220-ftp
220-***********************************************************************
220- This system is for the use of authorized users only. Individuals
220- using this computer system without authority, or in excess of their
220- authority, are subject to having all of their activities on this
220- system monitored and recorded.
220- In the course of monitoring individuals improperly using this
220- system, or in the course of system maintenance, the activities of
220- authorized users also are monitored.
220- Anyone using this system expressly consents to such monitoring
220- and recording. Please be advised that unauthorized access to this
220- system is a violation of State and Federal law. If monitoring
220- reveals possible evidence of criminal activity, system personnel
220- may provide that evidence to law enforcement officials.
220-***********************************************************************
220
Name (ftp.veritas.com <ftp://ftp.veritas.com/>): Please see technote TECH66995
331 User symsupport okay, need password.
Password: Please see technote TECH66995
230 Restricted user logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
While logged into the FTP server as the customer user , it is not possible to list any files or directories. It is important that the below steps are followed exactly:
Change directories to /pub/support:
ftp> cd /pub/support
Set FTP mode to binary:
ftp> bin
Download the file that contains utility:
ftp> get vxexplore.tar.Z
Close the ftp connection:
ftp> bye
Untar the download:
Untar the downloaded file (only if the VRTSexplorer utility has been downloaded and not installed with the VRTSspt package) :
# zcat vxexplore.tar.Z | tar xvf -
The above command will create a VRTSexplorer directory containing everything that is needed. Change into this directory:
# cd VRTSexplorer
To download the VRTSexplorer utility, follow the below instructions:
Connect to the FTP site:
# ftp ftp.veritas.com
The below message appears with a prompt for a login name. Please see technote TECH66995 in related items below for logon credentials.
Connected to ftp.veritas.com
220-ftp
220-***********************************************************************
220- This system is for the use of authorized users only. Individuals
220- using this computer system without authority, or in excess of their
220- authority, are subject to having all of their activities on this
220- system monitored and recorded.
220- In the course of monitoring individuals improperly using this
220- system, or in the course of system maintenance, the activities of
220- authorized users also are monitored.
220- Anyone using this system expressly consents to such monitoring
220- and recording. Please be advised that unauthorized access to this
220- system is a violation of State and Federal law. If monitoring
220- reveals possible evidence of criminal activity, system personnel
220- may provide that evidence to law enforcement officials.
220-***********************************************************************
220
Name (ftp.veritas.com <ftp://ftp.veritas.com/>): Please see technote TECH66995
331 User symsupport okay, need password.
Password: Please see technote TECH66995
230 Restricted user logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
While logged into the FTP server as the customer user , it is not possible to list any files or directories. It is important that the below steps are followed exactly:
Change directories to /pub/support:
ftp> cd /pub/support
Set FTP mode to binary:
ftp> bin
Download the file that contains utility:
ftp> get vxexplore.tar.Z
Close the ftp connection:
ftp> bye
Untar the download:
Untar the downloaded file (only if the VRTSexplorer utility has been downloaded and not installed with the VRTSspt package) :
# zcat vxexplore.tar.Z | tar xvf -
The above command will create a VRTSexplorer directory containing everything that is needed. Change into this directory:
# cd VRTSexplorer
2. Execute the VRTSexplorer utility:
Some notes on the
execution of VRTSexplorer:
· To determine the version of VRTSexplorer that is on the host, along with other options, execute # ./VRTSexplorer -help:
# ./VRTSexplorer -help
VRTSexplorer: version 5.6c
· To run the VRTSexplorer utility for only one particular product, such as Veritas Volume Manager, execute:
# ./VRTSexplorer vxvm
· To run the VRTSexplorer utility to exclude a particular product, such as Veritas NetBackup, execute:
# ./VRTSexplorer -nbu
Refer to the README file for additional options that are available with the VRTSexplorer utility.
The below messages will appear requesting input for the case number, destination directory (BE CAREFUL TO NOT USE SPACES OR OTHER SPECIAL CHARACTERS IN THE DIRECTORY YOU SPECIFY!), restart of vxconfigd (do not choose to do this if PowerPath is installed or if this is a node in a cluster), etc. The program will output several messages and finish by tarring and compressing the collected information. Please note that this operation can take some time to complete.
Below is partial example of what might be seen (the messages below are from VRTSexplorer version 5.5o and will be different from earlier versions of the utility) when executing the VRTSexplorer utility to gather information about a host, output is dependant on which product packages are installed:
# ./VRTSexplorer
VRTSexplorer: Initializing.
VRTSexplorer: Please enter case number, or just hit enter: 150-175-206
VRTSexplorer: Please select a destination directory (default: /tmp): /tmp
VRTSexplorer: Using /tmp as destination directory.
VRTSexplorer: Collecting system configuration information for SunOS system.
VRTSexplorer: Collecting VERITAS package version information.
VRTSexplorer: Collecting loadable module information.
VRTSexplorer: Collecting SLIM information.
VRTSexplorer: Collecting SLIM Agent installer logs.
VRTSexplorer: Collecting SLIM Server installer logs.
VRTSexplorer: Collecting Cross Product/Platform Installation (CPI) information.
VRTSexplorer: Collecting ISIS configuration information.
VRTSexplorer: Collecting VERITAS SANPoint Control Console configuration information.
##### All information and files will be placed under /tmp/VRTSexplorer_150-175-206_server1/spc
Logfile is /tmp/VRTSexplorer_150-175-206_server1/spc/LOG
##### Capturing SAL/VAIL/VEA information from host server1'
##### Saving VERITAS Package Information..........
##### Logging VEA Information #####
+Copying vxisis.log files.
+Copying /var/vx/isis vxsvc corefiles
+Copying /opt/VRTSob/bin vxsvc corefiles
##### Logging VRTSvail Information #####
Checksum /opt/VRTSvail/providers/vx*:...............
##### Saving Detailed information for all VERITAS packages..........................
##### Saving Host syslogs #####
+Copying syslog files.....
VRTSexplorer: Collecting SIG licensing information.
VRTSexplorer: Collecting VRW configuration information.
VRTSexplorer: Collecting VxFS configuration information.
VRTSexplorer: Determining current VxVM operating mode.
VRTSexplorer: Collecting VxVM configuration information.
VRTSexplorer: Collecting DMP configuration information.
NOTICE: This section will stop and restart the VxVM Configuration Daemon,
vxconfigd. This may cause your VxVA, VMSA and/or VEA session to exit.
This may also cause a momentary stoppage of any VxVM configuration
actions. This should not harm any data; however, it may cause some
configuration operations (e.g. moving subdisks, plex
resynchronization) to abort unexpectedly. Any VxVM configuration
changes should be completed before running this section.
If you are using EMC PowerPath devices with Veritas Volume Manager,
you must run the EMC command(s) 'powervxvm setup' (or 'safevxvm
setup') and/or 'powervxvm online' (or 'safevxvm online') if this
script terminates abnormally.
Restart VxVM Configuration Daemon? [y,n] (default: n) n
VRTSexplorer: Collecting VRAS configuration information.
VRTSexplorer: Collecting Web GUI Engine information.
VRTSexplorer: Collecting Cross Product/Platform Installation (CPI) information.
VRTSexplorer: Script finished.
VRTSexplorer: The cksum for the tarfile is:
2113302371 2569248 /tmp/VRTSexplorer_150-175-206_server1.tar.gz
VRTSexplorer: Please ftp /tmp/VRTSexplorer_150-175-206_server1.tar.gz
VRTSexplorer: to ftp.veritas.com:/incoming or work with your
VRTSexplorer: support representative for other upload options.
#
· To determine the version of VRTSexplorer that is on the host, along with other options, execute # ./VRTSexplorer -help:
# ./VRTSexplorer -help
VRTSexplorer: version 5.6c
· To run the VRTSexplorer utility for only one particular product, such as Veritas Volume Manager, execute:
# ./VRTSexplorer vxvm
· To run the VRTSexplorer utility to exclude a particular product, such as Veritas NetBackup, execute:
# ./VRTSexplorer -nbu
Refer to the README file for additional options that are available with the VRTSexplorer utility.
The below messages will appear requesting input for the case number, destination directory (BE CAREFUL TO NOT USE SPACES OR OTHER SPECIAL CHARACTERS IN THE DIRECTORY YOU SPECIFY!), restart of vxconfigd (do not choose to do this if PowerPath is installed or if this is a node in a cluster), etc. The program will output several messages and finish by tarring and compressing the collected information. Please note that this operation can take some time to complete.
Below is partial example of what might be seen (the messages below are from VRTSexplorer version 5.5o and will be different from earlier versions of the utility) when executing the VRTSexplorer utility to gather information about a host, output is dependant on which product packages are installed:
# ./VRTSexplorer
VRTSexplorer: Initializing.
VRTSexplorer: Please enter case number, or just hit enter: 150-175-206
VRTSexplorer: Please select a destination directory (default: /tmp): /tmp
VRTSexplorer: Using /tmp as destination directory.
VRTSexplorer: Collecting system configuration information for SunOS system.
VRTSexplorer: Collecting VERITAS package version information.
VRTSexplorer: Collecting loadable module information.
VRTSexplorer: Collecting SLIM information.
VRTSexplorer: Collecting SLIM Agent installer logs.
VRTSexplorer: Collecting SLIM Server installer logs.
VRTSexplorer: Collecting Cross Product/Platform Installation (CPI) information.
VRTSexplorer: Collecting ISIS configuration information.
VRTSexplorer: Collecting VERITAS SANPoint Control Console configuration information.
##### All information and files will be placed under /tmp/VRTSexplorer_150-175-206_server1/spc
Logfile is /tmp/VRTSexplorer_150-175-206_server1/spc/LOG
##### Capturing SAL/VAIL/VEA information from host server1'
##### Saving VERITAS Package Information..........
##### Logging VEA Information #####
+Copying vxisis.log files.
+Copying /var/vx/isis vxsvc corefiles
+Copying /opt/VRTSob/bin vxsvc corefiles
##### Logging VRTSvail Information #####
Checksum /opt/VRTSvail/providers/vx*:...............
##### Saving Detailed information for all VERITAS packages..........................
##### Saving Host syslogs #####
+Copying syslog files.....
VRTSexplorer: Collecting SIG licensing information.
VRTSexplorer: Collecting VRW configuration information.
VRTSexplorer: Collecting VxFS configuration information.
VRTSexplorer: Determining current VxVM operating mode.
VRTSexplorer: Collecting VxVM configuration information.
VRTSexplorer: Collecting DMP configuration information.
NOTICE: This section will stop and restart the VxVM Configuration Daemon,
vxconfigd. This may cause your VxVA, VMSA and/or VEA session to exit.
This may also cause a momentary stoppage of any VxVM configuration
actions. This should not harm any data; however, it may cause some
configuration operations (e.g. moving subdisks, plex
resynchronization) to abort unexpectedly. Any VxVM configuration
changes should be completed before running this section.
If you are using EMC PowerPath devices with Veritas Volume Manager,
you must run the EMC command(s) 'powervxvm setup' (or 'safevxvm
setup') and/or 'powervxvm online' (or 'safevxvm online') if this
script terminates abnormally.
Restart VxVM Configuration Daemon? [y,n] (default: n) n
VRTSexplorer: Collecting VRAS configuration information.
VRTSexplorer: Collecting Web GUI Engine information.
VRTSexplorer: Collecting Cross Product/Platform Installation (CPI) information.
VRTSexplorer: Script finished.
VRTSexplorer: The cksum for the tarfile is:
2113302371 2569248 /tmp/VRTSexplorer_150-175-206_server1.tar.gz
VRTSexplorer: Please ftp /tmp/VRTSexplorer_150-175-206_server1.tar.gz
VRTSexplorer: to ftp.veritas.com:/incoming or work with your
VRTSexplorer: support representative for other upload options.
#
3. Send the file created above to Symantec Technical Support:
Example:
Change directory to the destination directory (default: /tmp):
# cd /tmp
Connect to the FTP site:
# ftp ftp.veritas.com
The below message appears with a prompt for a login name. Please see technote TECH66995 in related items below for logon credentials.
Connected to ftp.veritas.com
220-ftp
220-***********************************************************************
220- This system is for the use of authorized users only. Individuals
220- using this computer system without authority, or in excess of their
220- authority, are subject to having all of their activities on this
220- system monitored and recorded.
220- In the course of monitoring individuals improperly using this
220- system, or in the course of system maintenance, the activities of
220- authorized users also are monitored.
220- Anyone using this system expressly consents to such monitoring
220- and recording. Please be advised that unauthorized access to this
220- system is a violation of State and Federal law. If monitoring
220- reveals possible evidence of criminal activity, system personnel
220- may provide that evidence to law enforcement officials.
220-***********************************************************************
220
Name (ftp.veritas.com <ftp://ftp.veritas.com/>): See technote TECH66995
331 User symsupport okay, need password.
Password: See technote TECH66995
230 Restricted user logged in.
Remote system type is UNIX.
Using binary mode to transfer files.
ftp>
While logged into the FTP server as the customer user, it is not possible to list any files or directories. It is important that the below steps are followed exactly:
Change into the /incoming directory:
ftp> cd /incoming
Set FTP mode to binary:
ftp> bin
Upload the file that was created above:
ftp> put VRTSexplorer_150-175-206_server1.tar.gz
Close the ftp connection:
ftp> bye
If this is an existing case, call or email the Technical Support Engineer assigned to the case to let them know the VRTSexplorer data is available along with the name of the file that was uploaded. If a case has not been created for the issue, contact Technical Support via your local support hotline to create a new case, or create a new case on the Web via MySymantec at https://mysymantec.symantec.com/ and provide the name of the file that was uploaded along with a description of the issue.
HMC basic commands
Steps:
Show managed frames attached to a hmc
lssyscfg -r sys -F name:type_model:serial_num
Show managed lpars attached to a frame
lssyscfg -m <frame> -r lpar -F name
Show profiles from a specific lpar
lssyscfg -r prof -m <frame> --filter "lpar_names=<lpar>"
Shutdown lpar from HMC
chsysstate -m <frame> -r lpar -n <lpar> -o shutdown –immed
To perform a partition shutdown using the shutdown command on the client operating system
chsysstate -r lpar -o osshutdown –n <lpar> -m <frame>
To perform a delayed partition shut down (white button shut down):
chsysstate -r lpar -o shutdown –n <lpar> -m <frame>
To perform an immediate partition shutdown (operator panel function :
chsysstate -r lpar -o shutdown --immed –n <lpar> -m <frame>
To perform an immediate restart of a partition (operator panel function 3):
chsysstate -r lpar -o shutdown --immed --restart –n <lpar> -m <frame>
To perform a restart of a partition after initiating a dump (operator panel function 22):
chsysstate -r lpar -o dumprestart –n <lpar> -m <frame>
Boot lpar
chsysstate -r lpar -m <frame> -o on -n <lpar> -f <profile>
To perform a partition boot into system management services:
chsysstate -r lpar -m <frame> -o on -n <lpar> -b sms
To perform a partition boot into diagnostic with default bootlist
chsysstate -r lpar -m <frame> -o on -n <lpar> -b dd
To perform a partition boot into diagnostic with stored bootlist
chsysstate -r lpar -m <frame> -o on -n <lpar> -b ds
To perform a partition boot into diagnostic with stored bootlist
chsysstate -r lpar -m <frame> -o on -n <lpar> -b ds
To perform a partition boot into open firmware OK prompt
chsysstate -r lpar -m <frame> -o on -n <lpar> -b of
To perform a partition boot into normal mode
chsysstate -r lpar -m <frame> -o on -n <lpar> -b norm
Show free processor/memory/adapters on specific frame/lpar
Proc
lshwres -r proc -m <framename> --level sys
lshwres -r proc -m <framename> --level lpar
Mem
lshwres -r mem -m <framename> --level sys
lshwres -r mem -m <framename> --level lpar
Adapters
lshwres -r hca -m <framename> --level sys
lshwres -r hca -m <framename> --level lpar
Show io resources in a frame
lshwres -r io --rsubtype unit -m <frame>
lshwres -r io --rsubtype bus -m <frame>
lshwres -r io --rsubtype slot -m <frame>
lssyscfg -r sys -F name:type_model:serial_num
Show managed lpars attached to a frame
lssyscfg -m <frame> -r lpar -F name
Show profiles from a specific lpar
lssyscfg -r prof -m <frame> --filter "lpar_names=<lpar>"
Shutdown lpar from HMC
chsysstate -m <frame> -r lpar -n <lpar> -o shutdown –immed
To perform a partition shutdown using the shutdown command on the client operating system
chsysstate -r lpar -o osshutdown –n <lpar> -m <frame>
To perform a delayed partition shut down (white button shut down):
chsysstate -r lpar -o shutdown –n <lpar> -m <frame>
To perform an immediate partition shutdown (operator panel function :
chsysstate -r lpar -o shutdown --immed –n <lpar> -m <frame>
To perform an immediate restart of a partition (operator panel function 3):
chsysstate -r lpar -o shutdown --immed --restart –n <lpar> -m <frame>
To perform a restart of a partition after initiating a dump (operator panel function 22):
chsysstate -r lpar -o dumprestart –n <lpar> -m <frame>
Boot lpar
chsysstate -r lpar -m <frame> -o on -n <lpar> -f <profile>
To perform a partition boot into system management services:
chsysstate -r lpar -m <frame> -o on -n <lpar> -b sms
To perform a partition boot into diagnostic with default bootlist
chsysstate -r lpar -m <frame> -o on -n <lpar> -b dd
To perform a partition boot into diagnostic with stored bootlist
chsysstate -r lpar -m <frame> -o on -n <lpar> -b ds
To perform a partition boot into diagnostic with stored bootlist
chsysstate -r lpar -m <frame> -o on -n <lpar> -b ds
To perform a partition boot into open firmware OK prompt
chsysstate -r lpar -m <frame> -o on -n <lpar> -b of
To perform a partition boot into normal mode
chsysstate -r lpar -m <frame> -o on -n <lpar> -b norm
Show free processor/memory/adapters on specific frame/lpar
Proc
lshwres -r proc -m <framename> --level sys
lshwres -r proc -m <framename> --level lpar
Mem
lshwres -r mem -m <framename> --level sys
lshwres -r mem -m <framename> --level lpar
Adapters
lshwres -r hca -m <framename> --level sys
lshwres -r hca -m <framename> --level lpar
Show io resources in a frame
lshwres -r io --rsubtype unit -m <frame>
lshwres -r io --rsubtype bus -m <frame>
lshwres -r io --rsubtype slot -m <frame>
What to do if you cannot execute CHMOD?
If you just ran 'chmod -x /bin/chmod'. What to do? How to recover it?
If you have just removed execute permission on chmod (/bin/chmod).
So that now you cannot modify file permissions. Not even for chmod itself .
chmod remains useless on your system.
Here is the solution for the problem.
Run the below commands whichever works in your server.
sudo /lib/ld-linux.so.2 /bin/chmod 755 /bin/chmod
or
perl -e 'chmod(0755, "/bin/chmod")'
Migrating Users from One AIX System to Another AIX System
This document discusses migrating users from one AIX system to another. This
does not include transferring the user's personal data or home directories.
The information in this document applies to AIX 5.2 and above.
Since the files involved in the following procedure are flat ASCII files and their format has not changed from V4 to V5, the users can be migrated between systems running the same or different versions of AIX (for example, from V4 to V5).
Files that can be copied over:
When you copy the /etc/passwd and /etc/group files, make sure they contain at least a minimum set of essential user and group definitions.
Listed specifically as users are the following:
daemon
bin
sys
adm
uucp
guest
nobody
lpd
Listed specifically as groups are the following:
staff
bin
sys
adm
uucp
mail
security
cron
printq
audit
ecs
nobody
usr
If you copy over mkuser.default, changes must be made to the stanzas. Replace group with pgrp, and program with shell. A proper stanza should look like the following:
Once the files are moved over, execute the following:
NOTE: It is possible to find user ID conflicts when migrating users from older versions of AIX to newer versions. AIX has added new user IDs in different release cycles. These are reserved IDs and should not be deleted. If your old user IDs conflict with the newer AIX system user IDs, it is advised that you assign new user IDs to these older IDs.
The information in this document applies to AIX 5.2 and above.
Since the files involved in the following procedure are flat ASCII files and their format has not changed from V4 to V5, the users can be migrated between systems running the same or different versions of AIX (for example, from V4 to V5).
Files that can be copied over:
/etc/group /etc/passwd /etc/security/group /etc/security/limits /etc/security/passwd /etc/security/.ids /etc/security/environ /etc/security/.profile
NOTE: Edit the passwd file so the root entry is as follows
root:!:0:0::/:/usr/bin/ksh
When you copy the /etc/passwd and /etc/group files, make sure they contain at least a minimum set of essential user and group definitions.
Listed specifically as users are the following:
daemon
bin
sys
adm
uucp
guest
nobody
lpd
Listed specifically as groups are the following:
staff
bin
sys
adm
uucp
security
cron
printq
audit
ecs
nobody
usr
If you copy over mkuser.default, changes must be made to the stanzas. Replace group with pgrp, and program with shell. A proper stanza should look like the following:
user: pgrp = staff groups = staff shell = /usr/bin/ksh home = /home/$USER
The following files may also be copied over, as long as the AIX version in the new machine is the same:
/etc/security/login.cfg /etc/security/user
NOTE: If you decide to copy these two files, open the /etc/security/user file and make sure that variables such as tty, registry, auth1 and so forth are set properly with the new machine. Otherwise, do not copy these two files, and just add all the user stanzas to the new created files in the new machine.
Once the files are moved over, execute the following:
usrck -t ALL pwdck -t ALL grpck -t ALL
This will clear up any discrepancies (such as uucp not having an entry in /etc/security/passwd). Ideally this should be run on the source system before copying over the files as well as after porting these files to the new system.
NOTE: It is possible to find user ID conflicts when migrating users from older versions of AIX to newer versions. AIX has added new user IDs in different release cycles. These are reserved IDs and should not be deleted. If your old user IDs conflict with the newer AIX system user IDs, it is advised that you assign new user IDs to these older IDs.
Submitting system dump testcase to IBM
IBM support contact number - 1-800-426-7378 (1-800-IBM-SERV)
Check the information about the last recorded system dump (sysdumpdev –L). If this command reports no previous dump was recorded, then you will not be able to submit a system dump testcase. A dump will not be recorded if:
a) The system was halted or rebooted and did not crash.
b) The system hung but was not reset properly.
c) The dump device was changed after the crash and the previously recorded dump has been lost.
0453-039
Device name: /dev/lg_dumplv
Major device number: 10
Minor device number: 11
Size: 21010432 bytes
Date/Time: Tue Feb 12 13:05:33 CST 2002
Dump status: 0
dump completed successfully
Ensure the Date/Time is the actual time when the system crashed or hung. If the time stamp is old, the dump will not contain any information about the latest outage and there is no need to create a system dump testcase.
Check the dump status: If the status is 0 (Succesful dump) OR -2 (Dump device is too small) OR -3 (Dump crashed or didn't start): Proceed to step to create the system dump testcase.
If the status is -4 (Dump failed due to i/o error): There might not be a system dump if Size is 0 bytes. This usually indicates a bad disk or disk adapter. Check the error report for disk or disk adapter errors. If hardware errors exist, consider also opening a ticket with IBM Hardware Support. Even if the size of the dump is 0 bytes, proceed to step to create the system dump testcase so that AIX Software Support can assist with determining why the dump failed.
If the status is -1 (No dump device is defined): There is no system dump. A dump device should be configured so that a dump can be captured the next time the system crashes.
The snap command will be be used to create the testcase in the file system of your choice. The command creates a number of sub-directories including a directory named dump that will include a compressed copy of the system dump. The -c option on the snap command will create a compressed pax archive of the sub-directories named snap.pax.Z and this is the testcase file that should be ftp'ed to IBM. You will need to find a file system with sufficient space to hold all of the testcase data. In general, the file system you choose should have enough free space to hold about 2.5 times the size of the compressed system dump if the system is using dump compression. Dump compression is always used on AIX 6.1 or higher, but is optional on AIX 5. The sysdumpdev -L command can be used to obtain the size of the system dump to use in determining how much space will be required to hold the testcase.
AIX 6.1 or higher:
The output from sysdumpdev -L will contain the following line that shows the size of the
compressed system dump.
Size: N (this is the size of the compressed dump in bytes)
Find a file system with at least 2.5 times this value.
AIX 5
If the system is using dump compression, the output from sysdumpdev -L will include
the following two lines:
Size: N (this is the size of the compressed dump in bytes)
Uncompressed: N (this is the size of the uncompressed dump in bytes)
Find a file system with at least 2.5 times the size of the compressed system dump.
If the system is not using dump compression, the output from sysdumpdev -L will
include the following line:
Size: (this is the size of the uncompressed dump in bytes)
In this case, find a file system with at least 1/2 the size of the uncompressed dump.
# mkdir /thefs/ibmsupt
Run the snap commmand to generate the testcase data. This will create a file named snap.pax.Z which will be located inside the ibmsupt directory. If your chosen file system is /tmp, run:
# snap -r ; snap -ac
If your chosen file system is not /tmp, run:
# snap -acd /thefs/ibmsupt
Ftp the testcase file to IBM.
Rename the snap.pax.Z file to the PMR number using this format:
For example, if the PMR number is 12345,678 then name the file 12345.678.000.snap.pax.Z
Ftp the file to testcase.software.ibm.com or use the web interface at
https://testcase.boulder.ibm.com/ to upload the file into the directory /toibm/aix.
# cd /thefs/ibmsupt
# ftp testcase.software.ibm.com
user : anonymous
password : your full email address
> cd /toibm/aix
> bin
> hash
> put 12345.678.000.snap.pax.Z
> bye
Note: If a permission denied error is returned from ftp, first make certain that the ftp current directory is /toibm/aix. If it is, then usually a permissions denied error means an attempt is being made to overwrite an existing file and the permissions on the file will not allow this. In this case, try renaming the file to something like this:
12345.678.000.2.snap.pax.Z
Verify the upload with your ITS personnel and a quick follow-up with the technician will solve your problem quickly.
Using "tar" in Unix
On Unix platform, tar command is the primary archiving utility. Understanding various tar command options will help you master the archive file manipulation.
In this article, let us review various tar examples including how to create tar archives (with gzip and bzip compression), extract a single file or directory, view tar archive contents, validate the integrity of tar archives, finding out the difference between tar archive and file system, estimate the size of the tar archives before creating it etc.,
Note: I like to keep the ‘cvf’ (or tvf, or xvf) option unchanged for all archive creation (or view, or extract) and add additional option at the end, which is easier to remember. i.e cvf for archive creation, cvfz for compressed gzip archive creation, cvfj for compressed bzip2 archive creation etc., For this method to work properly, don’t give – in front of the options.
Note: .tbz and .tb2 is same as .tar.bz2
Note: In all the above commands v is optional, which lists the file being processed.
You can view the *.tar file content before extracting as shown below.
You can view the *.tar.gz file content before extracting as shown below.
While opening archive file it shows “ls -l” of the files available in the archive, so you can see the size of file, permissions of it and owner, group too.
For the archived and compressed file also less command shows the output in “ls -l” format.
Use the relevant option z or j according to the compression method gzip or bzip2 respectively as shown below.
To extract multiple directories from a tar archive, specify those individual directory names at the end of the tar xvf command as shown below.
Use the relevant option z or j according to the compression method gzip or bzip2 respectively as shown below.
Options explanation:
This newfile will be added to the existing archive_name.tar. Adding a directory to the tar is also similar,
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.
If you are planning to remove a directory/file from an archive file or from the file system, you might want to verify the archive file before doing it as shown below.
If an output line starts with Verify, and there is no differs line then the file/directory is Ok. If not, you should investigate the issue.
Note: for a compressed archive file ( *.tar.gz, *.tar.bz2 ) you cannot do the verification.
Finding the difference between an archive and file system can be done even for a compressed archive. It also shows the same output as above excluding the lines with Verify.
Finding the difference between gzip archive file and file system
Finding the difference between bzip2 archive file and file system
The following command, estimates the compressed tar file size ( in KB ) before you create the tar.gz, tar.bz2 files.
In this article, let us review various tar examples including how to create tar archives (with gzip and bzip compression), extract a single file or directory, view tar archive contents, validate the integrity of tar archives, finding out the difference between tar archive and file system, estimate the size of the tar archives before creating it etc.,
1. Creating an archive using tar command
Creating an uncompressed tar archive using option cvf
This is the basic command to create a tar archive.
$ tar cvf archive_name.tar dirname/In the above command:
- c – create a new archive
- v – verbosely list files which are processed.
- f – following is the archive file name
Creating a tar gzipped archive using option cvzf
The above tar cvf option, does not provide any compression. To use a gzip compression on the tar archive, use the z option as shown below.$ tar cvzf archive_name.tar.gz dirname/
- z – filter the archive through gzip
Note: I like to keep the ‘cvf’ (or tvf, or xvf) option unchanged for all archive creation (or view, or extract) and add additional option at the end, which is easier to remember. i.e cvf for archive creation, cvfz for compressed gzip archive creation, cvfj for compressed bzip2 archive creation etc., For this method to work properly, don’t give – in front of the options.
Creating a bzipped tar archive using option cvjf
Create a bzip2 tar archive as shown below:$ tar cvfj archive_name.tar.bz2 dirname/
- j – filter the archive through bzip2
Note: .tbz and .tb2 is same as .tar.bz2
2. Extracting (untar) an archive using tar command
Extract a *.tar file using option xvf
Extract a tar file using option x as shown below:
$ tar xvf archive_name.tar
- x – extract files from archive
Extract a gzipped tar archive ( *.tar.gz ) using option xvzf
Use the option z for uncompressing a gzip tar archive.
$ tar xvfz archive_name.tar.gz
Extracting a bzipped tar archive ( *.tar.bz2 ) using option xvjf
Use the option j for uncompressing a bzip2 tar archive.
$ tar xvfj archive_name.tar.bz2
Note: In all the above commands v is optional, which lists the file being processed.
3. Listing an archive using tar command
View the tar archive file content without extracting using option tvf
You can view the *.tar file content before extracting as shown below.
$ tar tvf archive_name.tar
View the *.tar.gz file content without extracting using option tvzf
You can view the *.tar.gz file content before extracting as shown below.
$ tar tvfz archive_name.tar.gz
View the *.tar.bz2 file content without extracting using option tvjf
You can view the *.tar.bz2 file content before extracting as shown below.$ tar tvfj archive_name.tar.bz2
4. Listing out the tar file content with less command
When the number of files in an archive is more, you may pipe the output of tar to less. But, you can also use less command directly to view the tar archive output, as explained below.
While opening archive file it shows “ls -l” of the files available in the archive, so you can see the size of file, permissions of it and owner, group too.
$ less autocorrect.tar -rwxrwxrwx anthony/anthony 84149 2009-02-02 03:20 autocorrect.dat -rwxrwxrwx anthony/anthony 443 2009-02-02 03:21 generator.rb -rwxrwxrwx anthony/anthony 181712 2009-02-02 03:21 autocorrect.vim
$ less XML-Parser-2.36.tar.gz drwxr-xr-x matt/matt 0 2007-11-20 19:58 XML-Parser-2.36/ -rw-r--r-- matt/matt 25252 2007-11-20 19:52 XML-Parser-2.36/Changes drwxr-xr-x matt/matt 0 2007-11-20 19:58 XML-Parser-2.36/Expat/ -rw-r--r-- matt/matt 3184 2003-07-27 16:37 XML-Parser-2.36/Expat/encoding.h -rw-r--r-- matt/matt 33917 2007-11-20 19:54 XML-Parser-2.36/Expat/Expat.pm -rw-r--r-- matt/matt 45555 2007-11-17 01:54 XML-Parser-2.36/Expat/Expat.xs
5. Extract a single file from tar, tar.gz, tar.bz2 file
To extract a specific file from a tar archive, specify the file name at the end of the tar xvf command as shown below. The following command extracts only a specific file from a large tar file.
$ tar xvf archive_file.tar /path/to/file
Use the relevant option z or j according to the compression method gzip or bzip2 respectively as shown below.
$ tar xvfz archive_file.tar.gz /path/to/file $ tar xvfj archive_file.tar.bz2 /path/to/file
6. Extract a single directory from tar, tar.gz, tar.bz2 file
To extract a single directory (along with it’s subdirectory and files) from a tar archive, specify the directory name at the end of the tar xvf command as shown below. The following extracts only a specific directory from a large tar file.
$ tar xvf archive_file.tar /path/to/dir/
To extract multiple directories from a tar archive, specify those individual directory names at the end of the tar xvf command as shown below.
$ tar xvf archive_file.tar /path/to/dir1/ /path/to/dir2/
Use the relevant option z or j according to the compression method gzip or bzip2 respectively as shown below.
$ tar xvfz archive_file.tar.gz /path/to/dir/ $ tar xvfj archive_file.tar.bz2 /path/to/dir/
7. Extract group of files from tar, tar.gz, tar.bz2 archives using regular expression
You can specify a regex, to extract files matching a specified pattern. For example, following tar command extracts all the files with pl extension.
$ tar xvf archive_file.tar --wildcards '*.pl'
Options explanation:
- –wildcards *.pl – files with pl extension
8. Adding a file or directory to an existing archive using option -r
You can add additional files to an existing tar archive as shown below. For example, to append a file to *.tar file do the following:
$ tar rvf archive_name.tar newfile
This newfile will be added to the existing archive_name.tar. Adding a directory to the tar is also similar,
$ tar rvf archive_name.tar newdir/
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.
$ tar rvfz archive_name.tgz newfile tar: Cannot update compressed archives Try `tar --help' or `tar --usage' for more information.
9. Verify files available in tar using option -W
As part of creating a tar file, you can verify the archive file that got created using the option W as shown below.
$ tar cvfW file_name.tar dir/
If you are planning to remove a directory/file from an archive file or from the file system, you might want to verify the archive file before doing it as shown below.
$ tar tvfW file_name.tar Verify 1/file1 1/file1: Mod time differs 1/file1: Size differs Verify 1/file2 Verify 1/file3
If an output line starts with Verify, and there is no differs line then the file/directory is Ok. If not, you should investigate the issue.
Note: for a compressed archive file ( *.tar.gz, *.tar.bz2 ) you cannot do the verification.
Finding the difference between an archive and file system can be done even for a compressed archive. It also shows the same output as above excluding the lines with Verify.
Finding the difference between gzip archive file and file system
$ tar dfz file_name.tgz
Finding the difference between bzip2 archive file and file system
$ tar dfj file_name.tar.bz2
10. Estimate the tar archive size
The following command, estimates the tar file size ( in KB ) before you create the tar file.
$ tar -cf - /directory/to/archive/ | wc -c 20480
The following command, estimates the compressed tar file size ( in KB ) before you create the tar.gz, tar.bz2 files.
$ tar -czf - /directory/to/archive/ | wc -c 508 $ tar -cjf - /directory/to/archive/ | wc -c
428