tar command on AIX is not working unzip - tar

tar -zxvf unzip and untar command work on RHEL and Solaris however the not working on AIX 5/6/7 what is the equivalent command?

A good answer was provided in a comment. Adding an answer, though.
The portable version of tar -zxvf is that I reach for on old non-linux unix systems is:
gzip -dc foo.tgz | tar xvf -

gunzip <filename>.tar.gz
tar xvf <filename>.tar
Note that gunzip command outputs a .tar file. Then tar xvf untars this .tar file.

Related

Strange Tar behavior with -C option

I am trying to create a tar archive using -C option. I also am using $(ls ) to make sure that tar does not complain about missing files.
I am seeing a strange behavior that the command works when run from some paths and not from others. I am unable to explain this.
What I want to tar: /opt/server/nginx/etc/nginx/nginx.conf
[In this case the file is present].
I don't want to preserve the full path, so I use -C /opt/server/nginx/etc/nginx
/tmp/backup/ folder is present.
Fails:
(venv) root#bhakta-at-host-1:/opt/server/agent# cd /root
(venv) root#bhakta-at-host-1:~# tar -cvzf /tmp/backup/NginxServer_cfg_save.tgz -C /opt/server/nginx/etc/nginx/ $(ls -d nginx.conf)
ls: cannot access 'nginx.conf': No such file or directory
tar: Cowardly refusing to create an empty archive
Try 'tar --help' or 'tar --usage' for more information.
(venv) root#bhakta-at-host-1:~#
(venv) root#bhakta-at-host-1:~#
Fails:
(venv) root#bhakta-at-host-1:/tmp# cd /var/tmp
(venv) root#bhakta-at-host-1:/var/tmp# tar -cvzf /tmp/backup/NginxServer_cfg_save.tgz -C /opt/server/nginx/etc/nginx/ $(ls -d nginx.conf)
ls: cannot access 'nginx.conf': No such file or directory
tar: Cowardly refusing to create an empty archive
Try 'tar --help' or 'tar --usage' for more information.
(venv) root#bhakta-at-host-1:/var/tmp#
Works:
(venv) root#bhakta-at-host-1:~# cd /tmp
(venv) root#bhakta-at-host-1:/tmp# tar -cvzf /tmp/backup/NginxServer_cfg_save.tgz -C /opt/server/nginx/etc/nginx/ $(ls -d nginx.conf)
nginx.conf
Works:
(venv) root#bhakta-at-host-1:/opt/server/nginx/etc/nginx# tar -cvzf /tmp/backup/NginxServer_cfg_save.tgz -C /opt/server/nginx/etc/nginx/ $(ls -d nginx.conf)
nginx.conf
(venv) root#bhakta-at-host-1:/opt/server/nginx/etc/nginx#
Works:
(venv) root#bhakta-at-host-1:/var/tmp# tar -cvzf /tmp/backup/NginxServer_cfg_save.tgz -C /opt/server/nginx/etc/nginx/ nginx.conf
nginx.conf
So what is going on here? It seems to be something to do with -C and $(ls )
Versions:
(venv) root#bhakta-at-host-1:/opt/server/nginx/etc/nginx# tar --version
tar (GNU tar) 1.29
Copyright (C) 2015 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by John Gilmore and Jay Fenlason.
(venv) root#bhakta-at-host-1:/opt/server/nginx/etc/nginx# lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.1 LTS
Release: 18.04
Codename: bionic

Dockerfile wget fails

I have the following code
RUN apt-get update
RUN apt-get install -y wget #install wget lib
RUN mkdir -p example && cd example #create folder and cd to folder
RUN WGET -r https://host/file.tar && tar -xvf *.tar # download tar file to example folder and untar it in same folder
RUN rm -r example/*.tar # remove the tar file
RUN MV example/foo example/bar # rename untar directory from foo to bar
But i get the following errors:
/bin/sh: 1: WGET: not found
tar: example/*.tar: Cannot open: No such file or directory
tar: Error is not recoverable: exiting now
I am a newbie in docker.
Each subsequent RUN command in your Dockerfile will be in the context of the / directory. Therefore your .tar file is not in the example/ directory, it would actually be in the / directory since your 'cd to the folder' would mean nothing for subsequent RUN commands. Instead of doing cd example, rather do WORKDIR example before running wget, eg:
RUN apt-get update
RUN apt-get install -y wget #install wget lib
RUN mkdir -p example # create folder and cd to folder
WORKDIR example/ # change the working directory for subsequent commands
RUN wget -r https://host/file.tar && tar -xvf *.tar # download tar file to example folder and untar it in same folder
RUN rm -r example/*.tar # remove the tar file
RUN mv example/foo example/bar # rename untar directory from foo to bar
Or alternatively, add cd example && ... some command before any command you'd like to execute within theexample directory.
As Ntokozo stated, each RUN command is a separate "session" in the build process. As such, Docker is really designed to pack as many commands into a single RUN as possible allowing for smaller overall image size and fewer layers. So the command could be written like so:
RUN apt-get update && \
apt-get install -y wget && \
mkdir -p example && \
cd example/ && \
wget -r https://host/file.tar && \
tar -xvf *.tar && \
rm -r example/*.tar && \
mv example/foo example/bar

How to mount the current working directory onto Docker container?

I am trying to mount the current working directory onto Docker container but isn't working. Here is my Dockerfile
FROM ubuntu:14.04.3
MAINTAINER Upendra Devisetty
RUN apt-get update && apt-get install -y g++ \
make \
git \
zlib1g-dev \
python \
wget \
curl \
python-matplotlib
ENV BINPATH /usr/bin
ENV HISAT2GIT https://upendra_35#bitbucket.org/upendra_35/evolinc.git
RUN git clone "$HISAT2GIT"
RUN chmod +x evolinc/evolinc-part-I.sh && cp evolinc/evolinc-part-I.sh $BINPATH
RUN wget -O- http://cole-trapnell-lab.github.io/cufflinks/assets/downloads/cufflinks-2.2.1.Linux_x86_64.tar.gz | tar xzvf -
RUN wget -O- https://github.com/TransDecoder/TransDecoder/archive/2.0.1.tar.gz | tar xzvf -
RUN wget -O- http://seq.cs.iastate.edu/CAP3/cap3.linux.x86_64.tar | tar vfx -
RUN curl ftp://ftp.ncbi.nlm.nih.gov/blast/executables/blast+/LATEST/ncbi-blast-2.2.31+-x64-linux.tar.gz > ncbi-blast-2.2.31+-x64-linux.tar.gz
RUN tar xvf ncbi-blast-2.2.31+-x64-linux.tar.gz
RUN wget -O- http://ftp.mirrorservice.org/sites/download.sourceforge.net/pub/sourceforge/q/qu/quast/quast-3.0.tar.gz | tar zxvf -
RUN curl -L http://cpanmin.us | perl - App::cpanminus
RUN cpanm URI/Escape.pm
ENV PATH /CAP3/:$PATH
ENV PATH /ncbi-blast-2.2.31+/bin/:$PATH
ENV PATH /quast-3.0/:$PATH
ENV PATH /cufflinks-2.2.1.Linux_x86_64/:$PATH
ENV PATH /TransDecoder-2.0.1/:$PATH
ENTRYPOINT ["/usr/bin/evolinc-part-I.sh"]
CMD ["-h"]
When i run the following to mount the current working directory to make sure everything is doing ok, what i see is that all those dependencies are getting installed in the current working directory.
docker run --rm -v $(pwd):/working-dir -w /working-dir ubuntu/evolinc:2.0 -c cuffcompare_out_annot_no_annot.combined.gtf -g Brassica_rapa_v1.2_genome.fa -r Brassica_rapa_v1.2_cds.fa -b TE_RNA_transcripts.fa
I thought, they should only be installed on the container and only the output is going to generate in the current working directory. Sorry, i am very new to Docker and i would need some help with this....
Mouting a volume in docker (-v) allows a container to share directories/volumes with the host. Therefore when changing the volume you are in fact changing the mounted directory. If you wanted to copy some files, rather than point at them, you may need to build your own container and use the COPY or ADD instructions.
What is the difference between the `COPY` and `ADD` commands in a Dockerfile?

How to wget url like this `https://www.apache.org/dyn/closer.cgi?path=/kafka/0.8.2.1/kafka_2.11-0.8.2.1.tgz` on CentOS 7

Basic environment:
[root#0b3608de9c84 tmp]# cat /etc/redhat-release
CentOS Linux release 7.1.1503 (Core)
I want to install Kafka in Dockerfile,below is my Dockerfile instruction:
#choose scala and kafka version
ENV KAFKA_VERSION="0.8.2.1" SCALA_VERSION="2.11"
#install kafka
RUN cd /tmp && wget https://www.apache.org/dyn/closer.cgi?path=/kafka/$KAFKA_VERSION/kafka_$SCALA_VERSION-$KAFKA_VERSION.tgz && tar xf kafka_${SCALA_VERSIO N}-${KAFKA_VERSION}.tgz -C /opt && rm kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz
I know https://www.apache.org/dyn/closer.cgi?path=/kafka/$KAFKA_VERSION/kafka_$SCALA_VERSION-$KAFKA_VERSION.tgz(or https://www.apache.org/dyn/closer.cgi?path=/kafka/0.8.2.1/kafka_2.11-0.8.2.1.tgz) is not true resource address.Can you help me use wget and the URL on Kafka web page to install Kafka correctly?
As you’ve pointed out, https://www.apache.org/dyn/closer.cgi?path=/kafka/0.8.2.1/kafka_2.11-0.8.2.1.tgz is not the real address. Instead, it links to a mirror site that is close to your location, e.g., I live in Ireland so ftp.heanet.ie is the closest mirror to my location.
You should (manually) use the URL of the relevant mirror site in your wget command, e.g.
wget http://ftp.heanet.ie/mirrors/www.apache.org/dist/kafka/0.8.2.1/kafka_2.11-0.8.2.1.tgz
The other issue is the spaces within the shell variable of your tar command:
tar xf kafka_${SCALA_VERSIO N}-${KAFKA_VERSION}.tgz
Combining the above fixes should give you something similar to:
RUN cd /tmp && wget http://ftp.heanet.ie/mirrors/www.apache.org/dist/kafka/$KAFKA_VERSION/kafka_$SCALA_VERSION-$KAFKA_VERSION.tgz && tar xf kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz -C /opt && rm kafka_${SCALA_VERSION}-${KAFKA_VERSION}.tgz

tar on one line?

For some tar adept, I'm sure all of the following could be achieved on one line?
mkdir site_media/media
cp fixtures/media.tar site_media/media/media.tar
cd site_media/media/
tar -xvf media.tar
rm media.tar
cd ../../
There is really no need to copy the tar file if you are only going to delete the copy anyway. This will work for you without the copying, deleting, and changing directories:
mkdir site_media/media; tar -xvf fixtures/media.tar -C site_media/media
Comedy answer:
mkdir site_media/media && cp fixtures/media.tar site_media/media/media.tar &&
cd site_media/media/ && tar -xvf media.tar && rm media.tar && cd ../../
Slightly more serious: I don't know of a way to create the base directory as part of a single tar, but it can be reduced somewhat:
mkdir -p site_media/media
tar -xvf fixtures/media.tar -C site_media/media
This avoids the delete by avoiding the copy in the first place. The C option in extract mode means 'change to this directory after opening the archive but before extracting anything'.
As #Steve-o humorously points out, you can combine lines with &&, which also has the effect of Boolean short-circuiting: stopping if a command fails.

Resources