I use jar xf file in a script to unzip a zip-file, which also contains empty folders but the empty folders are not extracted. Is it possible to extract empty folders with jar xf file?
Edit: In fact it works as Mike Slinn pointed out in the answer. I have now noticed that the empty folders actually turn into empty files when I use another zip-file which was not created by myself. What could be the difference between the empty folders in those zip-files? I use Windows 10 and JDK 1.8.0_144 64 Bit.
Yes. Here is proof:
$ mkdir empty # create an empty directory
$ jar -cf ~/junk.jar empty ./cache # add the empty directory and other directory to a new jar
$ jar -tf ~/junk.jar # list the contents of the jar
META-INF/
META-INF/MANIFEST.MF
empty/
cache/
cache/ssh/
cache/ssh/hostkeys
$ mkdir blah # make a temporary directory
$ cd blah # move to the temporary directory
$ jar -xf ~/junk.jar # extract the jar into the temporary directory
$ l empty # verify that the "empty" directory exists and is actually empty
total 8
drwxrwxr-x 2 mslinn mslinn 4096 Dec 24 19:42 ./
drwxrwxr-x 5 mslinn mslinn 4096 Dec 24 19:43 ../
Related
I have two different folders, say folder 1 and folder 2. A bunch of files get created into folder 1 all the time (they're not there yet).
I would like to have those files "physically" in folder 2, but that they are "symbolically" in folder 1 (because for new files to still get created in folder 1, it needs to have the previous files in it too).
I know I can create a symlink for a particular file from one folder to another.
But how would it work to have in general ALL future files from folder 1 (with different names) be physically in folder 2 and symbolically in folder 1?
I guess I would have to have a line that moves them physically to folder 2, AND that creates a symlink to folder 1.
I tried:
ln -s ./output/* ../../data/jadecheclair/plasim_output/fix_alb/output_try/*
where ./output/ is the folder they get created in (folder 1) and ../../data/jadecheclair/plasim_output/fix_alb/output_try/ is the folder I would like them to be in physically.
What you could try is move all old files the nes directory, remove it and create your link:
mv ./output/* ../../data/jadecheclair/plasim_output/fix_alb/output_try/
rm -ri ./output/
ln -s ../../data/jadecheclair/plasim_output/fix_alb/output_try/ ./output/
Then you should have
$ ls -la
[..]
output -> ../../data/jadecheclair/plasim_output/fix_alb/output_try/
And files created in ./output/ should be physically in ..../output_try/
I want to extract tar file in Unix tar xvf /home/test/group.tar and once extracted got a folder group which has list of xls,pdf,txt files.
How can i extract contents of group.tar inside /home/test/list of xls, pdf files without creating group folder.
Any specific command available or have to follow with copy and move??
Thanks!
You may use the --strip-components 1 parameter.
tar xvf group.tar --strip-components 1
I have over 500 sub directories coming off of one root directory that each contain >6000 files each. the directories are named 20150218, 20150217, etc., one for each day of the year.
I want to develop a script that will zip all of the files in a directory, i.e. 20150217 and name the directory 20150217.zip. I then want to delete the original files.
so, all of the sud directories in ~/public_html/ispy/dlink/ would be zipped separately.
I appreciate any guidance.
Copy and paste following script into any unix editor (vim, geany, mousepad) and save it in directory with Your "date" subfolders. Name it as you wish, with no extension e.g. zipscript. From terminal: go to directory with Your script, allow to execute it: chmod +x zipscript and fire it: sudo ./zipscript.
#!/bin/bash
for D in *
do
if [ -d "${D}" ]; then
zip -r -j "${D}".zip "${D}"
rm -R "${D}"
fi
done
Script runs as follows: for every file (directory is also a file under unix) in current directory check if it is a directory and, if true, make zip with the same name, then delete subdirectory with all files in it.
I have 36 subdirectories in the same directory named 10,11,12,....45 and a subdirectory logs
in each subdirectory (except for the directory logs) there is the same file called log.lammps
i was wondering if there was a way where i could copy each log.lammps file from each subdirectory 10-45 and put it in the sub directory logs while also adding the number of the directory that it originated from to the end of the filename
so i am looking for a code that copies the file log.lammps one by one from each subdirectory and every time the file gets copied into the directory logs, the filename gets changed from log.lammps to log.lammps10 if it came from the subdirectory 10 and when the file log.laamps from subdirectory 11 is copied into logs its name changes to log.lammps11 etc.
any help would be appreciated since right now i am only dealing with 30-40 files and in time i will be working with hundreds of files
Something along this line should work:
for f in [0-9][0-9]/log.lammps; do
d=$(dirname ${f})
b=$(basename ${f})
cp ${f} logs/${b}.${d}
done
That's easy-peasy with the magic of shell scripting. I'm assuming you have bash available. Create a new file in the directory that contains these subdirectories; name it something like copy_logs.sh. Copy-paste the following text into it:
#!/bin/bash
# copy_logs.sh
# Copies all files named log.lammps from all subdirectories of this
# directory, except logs/, into subdirectory logs/, while appending the name
# of the originating directory. For example, if this directory includes
# subdirectories 1/, 2/, foo/, and logs/, and each of those directories
# (except for logs/) contains a file named log.lammps, then after the
# execution of this script, the new file log.lammps.1, log.lammps.2, and
# log.lammps.foo will have been added to logs/. NOTE: any existing files
# with those names in will be overwritten.
DIRNAMES=$( find . -type d | grep -v logs | sed 's/\.//g' | sed 's/\///g' | sort )
for dirname in $( echo $DIRNAMES )
do
cp -f $dirname/foo.txt logs/foo$dirname
echo "Copied file $dirname/foo.txt to logs/foo.$dirname"
done
See the script's comments for what it does. After you've saved the file, you need to make it executable by commanding chmod a+x copy_logs.sh on the command line. After this, you can execute it by typing ./copy_logs.sh on the command line while your working directory is the directory that contains the script and the subdirectories. If you add that directory to your $PATH variable, you can command copy_logs.sh no matter what your working directory is.
(I tested the script with GNU bash v4.2.24, so it should work.)
For more on bash shell scripting, see any number of books or internet sites; you might start with the Advanced Bash-Scripting Guide.
At 10 A.M files are like below say in one of the location
A.log,B.log
Tar file should contain A.log and B.log. Tar file name should be like
archival_file__oror_datetimestamp.tar
At 11 A.M if files are like below
A.log,B.log,C.log
Now the tar file which is getting created now should not contain A.log and B.log it should contain C.log only
If I correctly guess the intention of your question you might want to do something like
# 10AM:
tar -cf /path/to/tarfile/archival_file__oror_10AM.tar /path/to/logfiles/*.log
# 11 AM
tar -N /path/to/tarfile/archival_file__oror_10AM.tar -cf /path/to/tarfile/archival_file__oror_11AM.tar /path/to/logfiles/*.log
The second command will only put files newer than archival_file__oror_10AM.tar into the new archive.