tar command unable to find file in archive - shell

I am trying to extract a file from tar using the following command:
tar xzfv mysql-connector-java-5.1.29.tar.gz mysql-connector-java-5.1.29-bin.jar
However tar command is unable to find mysql-connector-java-5.1.29-bin.jar even though it seems to be present. The folder structure which I get when extracting the tar file is:
The jar is present at http://cdn.mysql.com/Downloads/Connector-J/mysql-connector-java-5.1.29.tar.gz.
|-- mysql-connector-java-5.1.29
| |-- CHANGES
| |-- COPYING
| |-- README
| |-- README.txt
| |-- build.xml
| |-- docs
| | |-- README.txt
| | |-- connector-j.html
| | `-- connector-j.pdf
| |-- mysql-connector-java-5.1.29-bin.jar
| `-- src
| |-- com
| | `-- mysql
| | `-- jdbc
I have not included the complete structure for brevity. But it can be seen that mysql-connector-java-5.1.29-bin.jar is present. I am unable to figure out the issue here.

First, try to list the files in the tar.
tar tvf mysql-connector-java-5.1.29.tar.gz
Then you can find that your file is located inside a directory in the tar
mysql-connector-java-5.1.29/mysql-connector-java-5.1.29-bin.jar
So to extract that file, you should use
tar zxvf mysql-connector-java-5.1.29.tar.gz mysql-connector-java-5.1.29/mysql-connector-java-5.1.29-bin.jar

Related

How to synchronize two folders in Bash?

I am writing a short script. One functionality is synchronizing two folders. Now I have two variables with directories to two different folder: DIRECTORY_1 and DIRECTORY_2. In both folders are files and other folders. I need to synchronize these folder to have all files in both folders. For example:
In DIRECTORY_1 I have file1, file2, file3 and folder1
In DIRECTORY_2 I have file4, file5, file6 and folder2
I need comment after which I will have in both directories files1-6 and folders1-2.
I was trying rsync command but it doesn't work properly.
$ mkdir dir1
$ mkdir dir2
$ touch dir1/file1 dir1/file2 dir1/file3
$ mkdir dir1/folder1
$ touch dir2/file4 dir2/file5 dir2/file6
$ mkdir dir2/folder2
$ tree
.
|-- dir1
| |-- file1
| |-- file2
| |-- file3
| `-- folder1
`-- dir2
|-- file4
|-- file5
|-- file6
`-- folder2
$ rsync -a dir1/ dir2
$ tree
.
|-- dir1
| |-- file1
| |-- file2
| |-- file3
| `-- folder1
`-- dir2
|-- file1
|-- file2
|-- file3
|-- file4
|-- file5
|-- file6
|-- folder1
`-- folder2
I guess rsync -d dir2/ dir1 would be next?
Use unison, it's a real folder synchroniser (such as Dropbox or Mega did).
https://www.cis.upenn.edu/~bcpierce/unison/
Mac installation with brew:
brew install unison
I used this command:
unison -auto /path/folder1 /path/folder2
Moreover, and most important to me, if 2 files have the same name, it replaces with the most recent version.
Likely not the most efficient, but this would do the trick:
comm <(ls DIR1) <(ls DIR2) -23 | while read f; do cp -r DIR2/$f DIR1; done
comm <(ls DIR1) <(ls DIR2) -13 | while read f; do cp -r DIR1/$f DIR2; done

CMAKE avoid compilation of HLSL shader files on Visual Studio

I have a DirectX11 project with CMake on Windows.
The project contains (at least) three sub-projects - one is for the core 3D engine library - a common asset directory which contains all the binary data used by the test or sample apps that builds on top of the engine.
./
+-- src/
| +-- api/
| +-- CmakeLists.txt
+-- tests/
| +-- assets/
| | +-- shaders/
| | | +-- 1.hlsl
| | | +-- 2.hlsl
| | | ...
| | +-- images/
| | | ...
| | +-- models/
| | | ...
| | +-- CmakeLists.txt
| +-- sampleApp1/
| | +-- CmakeLists.txt
| | ...
| +-- sampleApp2
| | +-- CmakeLists.txt
| | +-- ...
| | ...
| +-- CmakeLists.txt
+-- CmakeLists.txt
The asset files are just being copied in relative to the test projects binary dir (${CMAKE_CURRENT_BINARY_DIR}) to make them available in relative to their work directory (../assets).
I have hlsl shader files in assets as well. When such files are being added to the project with CMake, VS will treat them as compilable source - obviously - which I wish to avoid, because I want such files to be edited with the IDE and just copy them to the binary folder and use the engine to compile, rather than let VS to do it.
I have tried to set as header file, like another source files that I wish to avoid building, but it seems that something sets them as shader file and overrides this for some reason.
Here is my setup I'm attempting with:
cmake_minimum_required (VERSION 2.6)
project (Project)
subdirs(assets)
In the asset folder I have the following:
file(GLOB_RECURSE FILES *.*)
add_custom_target(assets SOURCES ${FILES})
set_target_properties(assets PROPERTIES FOLDER tests)
# copy static sources
foreach(_source IN ITEMS ${FILES})
# this does not work for some reason
set_source_files_properties(${_source} PROPERTIES HEADER_FILE_ONLY TRUE)
if (IS_ABSOLUTE "${_source}")
file(RELATIVE_PATH _source_rel "${CMAKE_CURRENT_SOURCE_DIR}" "${_source}")
else()
set(source_rel "${_source}")
endif()
get_filename_component(_source_path "${_source_rel}" PATH)
get_filename_component(_source_name "${_source_rel}" NAME)
set(dst_path "${CMAKE_CURRENT_BINARY_DIR}/${_source_path}")
file(MAKE_DIRECTORY ${dst_path})
# -- win32 only
if (WIN32)
string(REPLACE "/" "\\" _source "${_source}")
string(REPLACE "/" "\\" _dest "${dst_path}/${_source_name}")
else()
message("win32 required")
endif(WIN32)
add_custom_command(
TARGET assets
COMMAND copy ${_source} ${_dest}
DEPENDS ${_source}
)
endforeach()
I have tried the following method described in this answer, but didn't succeed.
In CMake HLSL is handled as a source extra, and HEADER_FILE_ONLY doesn't apply here, as you discovered.
You can override this default behaviour by using VS_TOOL_OVERRIDE:
set_source_files_properties(my_shader.hlsl PROPERTIES VS_TOOL_OVERRIDE "None")
See cmVisualStudio10TargetGenerator::WriteExtraSource in CMake source code.

how to list all files directories and sub directories in a folder using shellscript

Hi all i am trying to print all the files present in a file here for instance a folder name "WebstormProjects" when i am trying to print the files it is going only upto 2nd sub directory(as written there) only if i want to go much deep into the sub-directory(2nd level) how to go deep down recursively??
here is the tree
WebstormProjects/
|-- goutham
| |-- goutham.js
| |-- demo.html
| |-- format.js
| `-- login.html
`-- Nodejs
|-- prototype
|`-- app.js
`-- requests
`-- app.js
4 directories, 6 files
here is the code
enter code here
#!/bin/bash
target="/home/goutham/WebstormProjects"
for f in "$target"/*
do
if [[ -d $f ]]; then
for k in "$f"/*
do
echo "$k"
done
echo ""
else
echo $f
fi
done
echo ""
Use find:
find WebstormProjects
If you want only files and no directories:
find WebstormProjects -type f
You want the output as list. Use
find WebstormProjects
Or if you want in a tree like you post
tree -af

Select theme in Revealjs from pandoc

When I run below command to generate slides from markdown, the theme not selected correctly.
pandoc slides -o slides.html -s -V theme=beige -t revealjs
My slide is in a directory with reveal.js there:
|-- reveal.js
| |-- css
| | |-- reveal.min.css
| | `-- theme
| | |-- beige.css
| |-- js
| | |-- reveal.js
| | `-- reveal.min.js
| `-- lib
| |-- css
| | `-- zenburn.css
| `-- js
| |-- classList.js
`-- slides.md
But it seems it still not use the theme.
Take a look at:
https://gist.github.com/aaronwolen/5017084
The syntax you need is very likely
--variable theme="beige"
For me the solution was to upgrade pandoc from version 1.12 to 1.18
This is the line that I'm using for my transformation:
pandoc -t revealjs -s \
-V theme=beige #specify the theme
-V revealjs-url=https://cdn.jsdelivr.net/reveal.js/3.0.0 \#use a cdn so that I don't need to have it installed
./my_slides.md -o my_slides.html
In order to upgrade pandoc
Download the latest pandoc version from here: https://github.com/jgm/pandoc/releases/latest
Then
sudo aptitude purge pandoc #uninstall current pandoc
sudo dpkg -i <name of the file you just downloaded>
If I remember correctly the syntax is like this:
pandoc slides -o slides.html -s -V theme:beige -t revealjs
(it might even be case-sensitive if you are on *nix)

BASH: excluding a directory in "find" command

I'd like to use find command with excluding a directory.
I have this:
GLUE="$GLUE -not -iwholename */dir3/*"
And I want to use a GLUE variable in a find command (find $GLUE [...]). Unfortunately, instead of -not -iwholename */dir3/* in GLUE I get -not -iwholename dir3/file1 dir3/file2 dir3/file3, i.e., */dir3/* turns into names of files which meet this condition. And, of course, find doesn't work because of it. How to stop that?
find ./ -iname ! -iname <dirname of file name to be not part of search results>
find ./ -iname <file name> ! -path "./dirt o be Excluded/*"
I hope one will help
Let me answer this question first:
How can I use find to search recursively while excluding a directory from the search? My find command supports the -prune action and the common extensions (e.g., provided by GNU find).
You're very lucky that your find supports the -prune action. Congratulations!
In this case, only add:
\! \( -name 'dir_to_exclude' -prune \)
This will be false if the current name processed by find is dir_to_exclude, and at the same time prune (i.e., cut that branch) from the search tree1.
Let's try it (in a scratch directory):
$ mkdir {a,b,c,d}/{,1,2,3}
$ touch {a,b,c,d}/{,1,2,3}/{file1,file2}
$ tree
.
|-- a
| |-- 1
| | |-- file1
| | `-- file2
| |-- 2
| | |-- file1
| | `-- file2
| |-- file1
| `-- file2
|-- b
| |-- 1
| | |-- file1
| | `-- file2
| |-- 2
| | |-- file1
| | `-- file2
| |-- file1
| `-- file2
`-- c
|-- 1
| |-- file1
| `-- file2
|-- 2
| |-- file1
| `-- file2
|-- file1
`-- file2
9 directories, 18 files
$ find \! \( -name a -prune \)
.
./b
./b/file2
./b/1
./b/1/file2
./b/1/file1
./b/file1
./b/2
./b/2/file2
./b/2/file1
./c
./c/file2
./c/1
./c/1/file2
./c/1/file1
./c/file1
./c/2
./c/2/file2
./c/2/file1
Looks good!
Now, you shouldn't put your arguments to find (or, more generally your commands and arguments) in a variable, but in an array! If you don't you'll very soon run into problems with arguments containing spaces or, like in your OP, wildcards.
Put your glue stuff in an array: for example, to find all the files that have a 1 in their name and are empty2:
glue=( '-name' '*1*' '-type' 'f' '-empty' )
Then an array of the exclude this directory:
exclude_dir=( '!' '(' '-name' 'a' '-prune' ')' )
Then find all files that have a 1 in their name and are empty, while excluding directory a (in the same scratch directory as before):
$ find "${exclude_dir[#]}" "${glue[#]}"
./b/1/file1
./b/file1
./b/2/file1
./c/1/file1
./c/file1
./c/2/file1
Looks really good! (and observe the quotes!).
1
If you really want to be sure that you're only excluding the directory with name dir_to_exclude, in case you have a file called dir_to_exclude, you can specify it thus:
\! \( -name 'dir_to_exclude' -type d -prune \)
2
I'm using a lot of quotes here. Just a good habit that actually saves me for the wildcard part *1* and for the parentheses too!

Resources