I tried this command to compress all the css files in all subdirectories.  find . -iname "*.css*" -exec gzip -c '{}' &gt; '{}'.gz  \;   But it only creates a {}.gz file. I ended up using this:  find . -iname "*.css" -exec sh -c "gzip -c '{}' &gt; '{}'.gz"  \;   which works well.   The question is why the first one didn't work and second one did?  Note: I could easily use gzip -k switch to keep the source files, but gzip on CentOS 7 does not support it.
121013
Exec allows us to either pass all arguments at once with {} + or to pass them one by one with {} \;  Now let's say I want to rename all jpeg, no problem doing this:  find . \( -name '*.jpg' -o -name '*.jpeg' \) -exec mv '{}' '{}'.new \;   But if I need to redirect output, '{}' isn't accessible after redirection.  find . \( -name '*.jpg' -o -name '*.jpeg' \) -exec cjpeg -quality 80 '{}' &gt; optimized_'{}' \;   This wouldn't work. I'd have to use a for loop, storing find's output into a variable before using it. Let's admit it, it's cumbersome.  for f in `find . \( -name '*.jpg' -o -name '*.jpeg' \)`; do cjpeg -quality 80 $f &gt; optimized_$f; done;   So is there a better way?
66024
Is there a quick way to check if a gzipped file is empty, or do I have to unzip it first?  example:  $ touch foo $ if [ -s foo ]; then echo not empty; fi $ gzip foo $ if [ -s foo.gz ]; then echo not empty; fi not empty $ wc -l foo.gz       1 foo.gz
95528
GUI-based applications like PKZIP and winzip (and the GUI version of 7z/7zip) let us browse around our directories and create a compressed file that contains lots of different directories and files, complete with [partial or full] paths.  What is the equivalent on Ubuntu Linux (specifically, 64-bit Ubuntu 12.04)?
35033
As per Yahoo's much-ballyhooed , we serve up static content from a CDN using far-future cache expiration headers. Of course, we need to occasionally update these "static" files, so we currently add an infix version as part of the filename (based on the SHA1 sum of the file contents). Thus:  styles.min.css   Becomes:  styles.min.abcd1234.css   However, managing the versioned files can become tedious, and I was wondering if a GET argument notation might be cleaner and better:  styles.min.css?v=abcd1234   Which do you use, and why? Are there browser- or proxy/cache-related considerations that I should consider?
44735
I have got the directory called Test and a few directories inside it. Both Test and the directories inside it have executable files. I'd like to print them with ls. I'd use this command.  ls -l `find Test/ -perm /u=x,g=x,o=x -type f`   Is this a good/right/quick command or not?  My solution is:  find Test/ -executable -type f -exec ls -l {} \;   and got the same result as warl0ck and pradeepchhetri offered.
45426
If you have a series of subfolders (like from a to z) and want to run a command on each one of them (like rm *.pdf or ls *.pdf), how do you do that? The "manual" approach would be cd a, rm *.pdf, or ls *.pdf, cd .., cd b, ... That seems too complicated, so I believe there must be an easier approach.
69741
I have a script which searches all files in multiple subfolders and archives to tar. My script is   for FILE in `find . -type f  -name '*.*'`   do if [[ ! -f archive.tar ]]; then    tar -cpf archive.tar $FILE else    tar -upf archive.tar $FILE  fi done   The find command gives me the following output  find . -type f  -iname '*.*' ./F1/F1-2013-03-19 160413.csv ./F1/F1-2013-03-19 164411.csv ./F1-FAILED/F2/F1-2013-03-19 154412.csv ./F1-FAILED/F3/F1-2011-10-02 212910.csv ./F1-ARCHIVE/F1-2012-06-30 004408.csv ./F1-ARCHIVE/F1-2012-05-08 190408.csv   But the FILE variable only stores first part of the path ./F1/F1-2013-03-19 and then the next part 160413.csv.  I tried using read with a while loop,   while read `find . -type f  -iname '*.*'`;   do ls $REPLY; done   but I get the following error  bash: read: `./F1/F1-2013-03-19': not a valid identifier   Can anyone suggest an alternative way?  Update  As suggested in the answers below I updated the scripts  #!/bin/bash  INPUT_DIR=/usr/local/F1 cd $INPUT_DIR for FILE in "$(find  . -type f -iname '*.*')" do archive=archive.tar          if [ -f $archive ]; then         tar uvf $archive "$FILE"         else         tar -cvf $archive "$FILE"         fi done   The output that i get is  ./test.sh tar: ./F1/F1-2013-03-19 160413.csv\n./F1/F1-2013-03-19 164411.csv\n./F1/F1-2013-03-19 153413.csv\n./F1/F1-2013-03-19 154412.csv\n./F1/F1-2012-09-10 113409.csv\n./F1/F1-2013-03-19 152411.csv\n./.tar\n./F1-FAILED/F3/F1-2013-03-19 154412.csv\n./F1-FAILED/F3/F1-2013-03-19 170411.csv\n./F1-FAILED/F3/F1-2012-09-10 113409.csv\n./F1-FAILED/F2/F1-2011-10-03 113911.csv\n./F1-FAILED/F2/F1-2011-10-02 165908.csv\n./F1-FAILED/F2/F1-2011-10-02 212910.csv\n./F1-ARCHIVE/F1-2012-06-30 004408.csv\n./F1-ARCHIVE/F1-2011-08-17 133905.csv\n./F1-ARCHIVE/F1-2012-10-21 154410.csv\n./F1-ARCHIVE/F1-2012-05-08 190408.csv: Cannot stat: No such file or directory tar: Exiting with failure status due to previous errors
37891
I have a large number of zip files that were compressed using the zip command. I would like to recompress them with the -9 flag to improve the compression ratio. Does anyone know if that can be done without manually decompressing and then compressing.  PS. I need to keep them as zip files since they are served to windows users( and as such have white spaces in their names)
45403
When I try to run the following script in zsh, via the command /bin/zsh ~/.set_color_scheme.sh I get the following error:  command not found: ^M   The script has u+x permissions and it used to work on another machine that also had zsh. Any clues why?   Note: This question is related to  (where I am trying to adapt the script for tcsh)  #!/bin/zsh # Contents of set_color_scheme.sh  export LS_COLORS=$( \ ( grep '\w' | grep -v '^#' | sed 's/#.\+//' | perl -lane 'printf "%s=%s:", shift @F, join ";", @F;' ) &lt;&lt;&lt; "  # HUMAN_FORMATTED_DATA # list one per line  # these are basic filesystem items no 00          # normal fi 00          # file di 01 34       # directory ln 00 36       # link pi 40 33       # pipe so 00 35       # bd 40 33 01 cd 40 33 01 or 01 05 37 41 mi 01 05 37 41 ex 00 91       # executable ow 01 34       # other writables   *.cmd 00 32 *.exe 00 32  # archive, compressed things etc *.gz  00 90 *.bz2 00 90 *.bz  00 90 *.tz  00 90 *.rpm 00 90 *.rar 00 90 *.zip 00 90 *.iso 00 90   *.cpio 00 31    # perl &amp; CODE *.c      33 *.h      33 *.sh     33 *.t      33 *.pm     33 *.pl     33 *.cgi    33 *.pod    33 *.PL     33 *.js     33 *.php    33 #*.xs  # strikethrough *.off 00 9 *.bak 00 9 *.old 00 9   # documents misc, html webstuff # really TEXT *.htm    94 *.html   94 *.txt    94 *.text   94 *.css    94   # MOVIE *.avi    96 *.wmv    96 *.mpeg   96 *.mpg    96 *.mov    96 *.AVI    96 *.WMV    96 *.mkv    96  # images &amp; pdf *.jpg    96 *.jpeg   96 *.png    96 *.xcf    96 *.JPG    96 *.gif    96 *.svg    96 *.eps 00 96 *.pdf 00 96 *.PDF 00 96 *.ps  00 96  *.ai  00 91 # adobe ill *.doc 00 91 # msword   # data, such as .db, .csv *.csv    95 *.dsv    95 *.db     95 *.sql    95 *.meta   95 # CONFS *.xml    95 *.yaml   95 *.yml    95 *.conf   95 # [a-z0-9]*rc ")
27723
I have a single directory that contains dozens of directories inside of it.  I'm new to command line and I'm struggling to come up with a command that will zip each sub-directory into a unique sub-directory.zip file.  So in the end my primary directory will be filled with all of my original sub-directories, plus the corresponding .zip files that contain the zipped up content of each sub-directory.  Is something like this possible? If so, please show me how it's done.
38031
I have a directory called folder that looks like this:  folder       -&gt; root_folder                     -&gt; some files   I want to zip this directory into zipped_dir, I tried:  zip -r zipped_dir.zip folder/*   But this generates a ZIP that looks like this:  zipped_dir           -&gt; folder                    -&gt; root_folder                                  -&gt; some files   in other words, it's including the directory whose contents I want to zip. How can I exclude this parent directory from the ZIP, without moving anything?  IE I would like this end result:  zipped_dir           -&gt; root_folder                         -&gt; some files
105817
I have a directory that I would like to password protect and encrypt. I am using PeaZip to do this using 7zip compression. I'd like to use the 7z like a directory and hard drive space is not a concern, so I have opted for the "Store" compression level, thinking that this would also lead the the fastest decompression time. But if I can make the files take up less space without impacting functionality and decompression time, than I would prefer this. How does 7zip's compression level affect decompression speed?  As a note, I will likely be editing files within the 7z and will be adding files to it over time.
51411
I have a big .gz file. I would like to split it into 100 smaller gzip files, that can each be decompressed by itself. In other words: I am not looking for a way of chopping up the .gz file into chunks that would have to be put back together to be able to decompress it. I want to be able to decompress each of the smaller files independently.  Can it be done without recompressing the whole file?  Can it be done if the original file is compressed with --rsyncable? ("Cater better to the rsync program by periodically resetting the internal structure of the compressed data stream." sounds like these reset points might be good places to split at and probably prepend a header.)  Can it be done for any of the other compressed formats? I would imagine bzip2 would be doable - as it is compressed in blocks.
16320
When I'm using  find . -type f -name "*.htm*" -o -name "*.js*" -o -name "*.txt"  it finds all the types of file. But when I add -exec at the end:  find . -type f -name "*.htm*" -o -name "*.js*" -o -name "*.txt" -exec sh -c 'echo "$0"' {} \;  it seems it only prints .txt files. What am I doing wrong?  Note: using MINGW (Git Bash)
53598
I am learning Linux and I was trying the gzip command. I tried it on a folder which has a hierarchy like  Personal/Folder1/file1.amr Personal/Folder2/file2.amr Personal/Folder3/file3.amr Personal/Folder4/file4.amr   I ran     "gzip -r Personal" and now its like  Personal/Folder1/file1.amr.gz Personal/Folder2/file2.amr.gz Personal/Folder3/file3.amr.gz Personal/Folder4/file4.amr.gz   How do I go back?
115700
I have a directory, dir1 which contains many files whose names end in either .jpg or .png. I want to copy all the .png files to dir2 which is empty.  This command works:  find dir1 -name '*.png' -exec cp {} dir2 \;   but this command doesn't:  find dir1 -name '*.png' -exec cp {} dir2 + find: missing argument to `-exec'   I also tried:  find dir1 -name '*.png' -exec cp {} -t dir2 + find: missing argument to `-exec'   and:  find dir1 -name '*.png' -exec cp {} dir2 \+ find: missing argument to `-exec'   After looking at , I even tried:  find dir1 -name '*.png' -exec cp {} dir2 {} + find: Only one instance of {} is supported with -exec ... +    says that:     -exec {} + was added in [version] 4.2.12 in 2005   My version of find is 4.4.2.  What am I doing wrong?
6637
Is there a good clean conventional way to do this?  For example, if there are any ".gz" files in a certain directory, I want to unzip them.  But if there aren't, I don't want to see any error.  If I use gzip -d /mydir/*.gz, I get the error:  gzip: /mydir/*.gz: No such file or directory   If I first shopt -s nullglob and then gzip -d /mydir/*.gz, I get the following:  gzip: compressed data not read from a terminal. Use -f to force decompression. For help, type: gzip -h   I have one method I know will work, which I'm posting as an answer.  I'm wondering if there's a better/cleaner way.  POSIX compatibility is a bonus, but not required.