YUI Compressor on Windows 7 - unable to minify multiple files - yui

I can minify individual files with the command
java -jar yuicompressor-2.4.8.jar <file to compress> -o <output file>
But I cannot minify multiple files. I tried:
java -jar yuicompressor-2.4.8.jar -o <output file> *.js
java -jar yuicompressor-2.4.8.jar *.js -o <output file>
and
java -jar yuicompressor-2.4.8.jar --type js -o <output file>
...no dice. Any suggestions?

Related

Selective decompression, ommitting the existing absolute folder structure, of tar to a directory

Say the example.tar.gz archive contains the following:
volumes/wordpress/a
volumes/wordpress/.b
volumes/wordpress/c/d
volumes/service2/a
volumes/service2/.b
volumes/service3/c/d
volumes/service3/a
volumes/service3/.b
volumes/service3/c/d
I want to extract the contents of volumes/wordpress of the archive to /var/www/html directory on the host (which already exists and cannot be removed), to end up with:
/var/www/html/a
/var/www/html/.b
/var/www/html/c/d
I have no way of reformating the tar file.
What I have tried:
gunzip -c example.tar.gz | tar -C /var/www/html -xf - volumes/wordpress
but this creates /var/www/html/volumes/wordpress/...
gunzip -c example.tar.gz | bash -c 'tar -C /tmp -xf - volumes/wordpress && mv /tmp/volumes/wordpress/* /var/www/html'
but this skips the .b file
gunzip -c example.tar.gz | bash -c 'tar -C /tmp -xf - volumes/wordpress && rsync -a --remove-source-files /tmp/volumes/wordpress/ /var/www/html/'
but rsync does not exist in the context of a docker container
Note, because I don't think it is relevant to this question I skipped out on Docker related specifics but in case useful, the commands I am running are of this format:
gunzip ... | docker-compose run --rm wordpress tar ...
This allows the wordpress container to be defined in docker-compose yml (hence why I state I cannot remove /var/www/html/, as it is mounted as a volume)
Edit It turned out that I ended up finding a satisfactory (although hacky) solution to my problem and it WAS Docker specific (so edited question to include Docker tag). I will supply hacky answer as an answer to the question. Still interested in a non Docker related answer if possible.
I was able to remount the already defined (by docker-compose.yml) volume, my-volume to a docker-compose run of my-service, but in this case mapped to a second containerized directory, where tar would output its contents.
e.g.
gunzip -c example.tar.gz | docker-compose run --rm -v my-volume:/volumes/wordpress my-service tar -C / -xf - volumes/wordpress

Find files with a string in filename and unzip

I have a folder full to zip files. Using linux terminal, I need to find files with a certain string in the zip file name and unzip only them to another folder. I tried the following but no luck.
find /some_folder/ -name "*[temperature]*.zip" | parallel unzip '/some_folder/unzippedfiles/'
First, the pattern is not matching and second, I am not sure if the output could be redirected to another folder. Could someone suggest a fix please? Thanks a advance
/some_folder/ must be absolute path:
find /some_folder/ -name "*temperature*.zip" |
parallel 'mkdir -p /some_folder/unzippedfiles/; cd /some_folder/unzippedfiles/ && unzip'
To find a pattern in file names and unzip to a new folder
find /some_folder/ -name "*temperature*.zip" |
parallel "mkdir -p {//}/unzippedfiles && cd {//}/unzippedfiles && unzip -q {}"
To ignore files with a pattern file names and unzip to a new folder
find /some_folder/ ! -name "*temperature*.zip" |
parallel "mkdir -p {//}/unzippedfiles && cd {//}/unzippedfiles && unzip -q {}"
mkdir -p --> Creates a folder if it does not exist
-q --> quiet mode
{//} --> mydir/mysubdir (In this case, it is /some_folder)

How to make shell script executable after decompress without chmod

I am studying linux, and I have to make all shell scripts executable by this command:
find ./ -name "*.sh" -exec chmod u+x {} \;
But when I download Logstash.tar.gz and extract it to /opt, all shell scripts were executable, no chmod needed. And /opt is not in $PATH.
echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin:/usr/lib/jvm/java-8-oracle/bin:/usr/lib/jvm/java-8-oracle/db/bin:/usr/lib/jvm/java-8-oracle/jre/bin
How do I build an app like logstash works?
===updated test steps for verification===
mkdir testtar && cd testtar
## create a executable script
echo test_with_x >> test_with_x.sh
chmod u+x test_with_x.sh
## create a not executable script
echo test_without_x >> test_without_x.sh
cd ..
## compress with gzip
tar -zcvf testtar.tar.gz ./testtar
mkdir testextract
mv testtar.tar.gz ./testextract
cd ./testextract
tar -zxvf testtar.tar.gz
## decompressed and see a executable and not executable script
Logstash tar bundle might have been created with executable permissions on all scripts. It should be the reason why it works fine after extracting without using chmod u+x command. If you also create a tar bundle with executable scripts, you should also get executable scripts after decompressing without using chmod u+x.
If you want your shell scripts to be executed without using chmod u+x, provide your shell script as an argument to your shell interpreter.
For e.g,
bash MyScript.sh
sh MyScript.sh
ksh MyScript.sh
You have two solution:
Add /opt to the PATH:
export PATH=${PATH}:/opt
call logstash with full path:
/opt/<anywhere.it.may.be>/logstash

how to use relative path in .sh in order to make my tar files include only the folder tar is created from instead of its fullpath

In a mono exe I am creating .sh scripts file containing codes as below
tarcreator.sh:
tar -cvf /data/folder1/folder2/.../xyz.tar /data/...../tarHomeFolder/myTarFolder > /data/logs/tarLogs.txt
....
and the codes continue.
this .sh file is located in /data/...../tarHomeFolder and in my .exe I call it using "bash 'full path of .sh file'"
When I run this code in this way, it creates the tar but when I open the tar I see folders from the root directory.. (data/..../tarHomeFolder/myTarFolder/.....) instead of this I want my tar contain only directory structure of its folder (myTarFolder).
Then I changed the code to :
tar -cvf /data/folder1/folder2/.../xyz.tar myTarFolder > /data/logs/tarLogs.txt
knowing that .sh file is in tarHomeFolder but then my script tells no such file or directory for myTarFolder ..
when I use tar command right in command prompt, using the command
tar -cvf /data/folder1/folder2/.../xyz.tar myTarFolder > /data/logs/tarLogs.txt
it creates the tar directory structure as I want, so, how can I make it do the same in my bash file created and executed by mono .exe ?
All you need to do is change your directory before running tar. Something like this:
# If your full path to the directory is in DIR = "/data/...../tarHomeFolder/myTarFolder"
cd $(dirname $DIR)
tar -cvf /data/folder1/folder2/.../xyz.tar $(basename $DIR) > /data/logs/tarLogs.txt
This will leave you with relative paths, starting with myTarFolder, in your tar file.
Useful references:
basename
dirname
Something like this:
tar -cvf /data/folder1/folder2/.../xyz.tar -C /data/...../tarHomeFolder/ myTarFolder > /data/logs/tarLogs.txt

How do I tar a directory without retaining the directory structure?

I'm working on a backup script and want to tar up a file directory:
tar czf ~/backup.tgz /home/username/drupal/sites/default/files
This tars it up, but when I untar the resulting file, it includes the full file structure: the files are in home/username/drupal/sites/default/files.
Is there a way to exclude the parent directories, so that the resulting tar just knows about the last directory (files)?
Use the --directory option:
tar czf ~/backup.tgz --directory=/home/username/drupal/sites/default files
Hi I've a better solution when enter in the specified directory it's impossible (Makefiles,etc)
tar -cjvf files.tar.bz2 -C directory/contents/to/be/compressed .
Do not forget the dot (.) at the end !!
cd /home/username/drupal/sites/default/files
tar czf ~/backup.tgz *
Create a tar archive
tar czf $sourcedir/$backup_dir.tar --directory=$sourcedir WEB-INF en
Un-tar files on a local machine
tar -xvf $deploydir/med365/$backup_dir.tar -C $deploydir/med365/
Upload to a server
scp -r -i $privatekey $sourcedir/$backup_dir.tar $server:$deploydir/med365/
echo "File uploaded.. deployment folders"
Un-tar on server
ssh -i $privatekey $server tar -xvf $deploydir/med365/$backup_dir.tar -C $deploydir/med365/
To gunzip all txt (*.txt) files from /home/myuser/workspace/zip_from/
to /home/myuser/workspace/zip_to/ without directory structure of source files use following command:
tar -P -cvzf /home/myuser/workspace/zip_to/mydoc.tar.gz --directory="/home/myuser/workspace/zip_from/" *.txt
If you want to tar files while keeping the structure but ignore it partially or completely when extracting, use the --strip-components argument when extracting.
In this case, where the full path is /home/username/drupal/sites/default/files, the following command would extract the tar.gz content without the full parent directory structure, keeping only the last directory of the path (e.g. files/file1).
tar -xzv --strip-components=5 -f backup.tgz
I've found this tip on https://www.baeldung.com/linux/tar-archive-without-directory-structure#5-using-the---strip-components-option.
To build on nbt's and MaikoID's solutions:
tar -czf destination.tar.gz -C source/directory $(ls source/directory)
This solution:
Includes all files and folders in the directory
Does not include any of the directory structure (or .) in the final product
Does not require you to change directories.
However, it requires the directory to be given twice, so it may be most useful in another script. It may also be less efficient if there are a lot of files/folders in source/directory. Adjust the subcommand as necessary.
So for instance for the following structure:
|- source
| |- one
| `- two
`- working
the following command:
working$ tar -czf destination.tar.gz -C ../source $(ls ../source)
will produce destination.tar.gz where both one and two (and sub-files/-folders) are the first items.
This worked for me:
gzip -dc "<your_file>.tgz" | tar x -C <location>
For me -C or --directory did not work, I use this
cd source/directory/or/file
tar -cvzf destination/packaged-app.tgz *.jar
# this will put your current directory to what it previously was
cd -
Kindly use the below command to generate tar file without directory structure
tar -C <directoryPath> -cvzf <Path of the tar.gz file> filename1 filename2... filename N
eg:
tar -C /home/project/files -cvzf /home/project/files/test.tar.gz text1.txt text2.txt
tar -Cczf ~/backup.tgz /home/username/drupal/sites/default/files
-C does the cd for you

Resources