Would like to pigz an entire directory in Linux  and move each file after it compresses to a new directory

Nathan Kaufman
Nathan Kaufman used Ask the Experts™
on
Would like to pigz an entire directory in Linux  and move each file after it compresses to a new directory.

pigz --best -r /directory/backup/ then move .gz file to new directory
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2004
Commented:
[senateuser@MJZFCBM:~/IMAP]
$> ls
total 45
drwxr-xr-x+ 1 senateuser None    0 Apr 14 11:00 ./
drwxr-xr-x+ 1 senateuser None    0 Apr  8 10:54 ../
-rwxr-xr--  1 senateuser None 3076 Mar 18 13:10 ajax_helper.js*
-rwxr-xr--  1 senateuser None 7222 Mar 18 13:10 imap_helper.js*
-rwxr-xr--  1 senateuser None 3222 Mar 18 13:10 imap_reader.css*
-rwxr-xr--  1 senateuser None 6286 Mar 18 13:10 imap_reader.php*
-rwxr-xr--  1 senateuser None 3377 Mar 18 13:10 imap_reader_ajax.php*
drwxr-xr-x+ 1 senateuser None    0 Apr 14 11:00 my_gzips/
-rwxr-xr--  1 senateuser None  503 Mar 18 13:10 raw-text.png*

[senateuser@MJZFCBM:~/IMAP]
$> ls my_gzips
total 8
drwxr-xr-x+ 1 senateuser None 0 Apr 14 11:00 ./
drwxr-xr-x+ 1 senateuser None 0 Apr 14 11:00 ../

[senateuser@MJZFCBM:~/IMAP]
$> for x in $(ls | awk '{print $NF}'); do if [[ -f $x ]]; then gzip -k $x; mv $x.gz ./my_gzips; fi; done;

[senateuser@MJZFCBM:~/IMAP]
$> ls
total 45
drwxr-xr-x+ 1 senateuser None    0 Apr 14 11:01 ./
drwxr-xr-x+ 1 senateuser None    0 Apr  8 10:54 ../
-rwxr-xr--  1 senateuser None 3076 Mar 18 13:10 ajax_helper.js*
-rwxr-xr--  1 senateuser None 7222 Mar 18 13:10 imap_helper.js*
-rwxr-xr--  1 senateuser None 3222 Mar 18 13:10 imap_reader.css*
-rwxr-xr--  1 senateuser None 6286 Mar 18 13:10 imap_reader.php*
-rwxr-xr--  1 senateuser None 3377 Mar 18 13:10 imap_reader_ajax.php*
drwxr-xr-x+ 1 senateuser None    0 Apr 14 11:01 my_gzips/
-rwxr-xr--  1 senateuser None  503 Mar 18 13:10 raw-text.png*

[senateuser@MJZFCBM:~/IMAP]
$> ls my_gzips/
total 29
drwxr-xr-x+ 1 senateuser None    0 Apr 14 11:01 ./
drwxr-xr-x+ 1 senateuser None    0 Apr 14 11:01 ../
-rwxr-xr--  1 senateuser None 1359 Mar 18 13:10 ajax_helper.js.gz*
-rwxr-xr--  1 senateuser None 2181 Mar 18 13:10 imap_helper.js.gz*
-rwxr-xr--  1 senateuser None 1075 Mar 18 13:10 imap_reader.css.gz*
-rwxr-xr--  1 senateuser None 1678 Mar 18 13:10 imap_reader.php.gz*
-rwxr-xr--  1 senateuser None 1410 Mar 18 13:10 imap_reader_ajax.php.gz*
-rwxr-xr--  1 senateuser None  534 Mar 18 13:10 raw-text.png.gz*

Open in new window

murugesandinsShell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT
Commented:
Reason for adding comment:
1)
This will be closed after 14 days once inactive.
$ /bin/date --date=2016-04-14 "+%d/%b/%Y"
14/Apr/2016

Open in new window

2) For knowledge transfer:
a)
Always use full path while executing any commands.
/bin/ls
/bin/awk or /bin/gawk
/usr/bin/gzip
/bin/mv
b) handle exceptions
if test ! -f my_gzips/currentfile
then
         echo /bin/mv -i currentfile my_gzips/currentfile
         /bin/mv -i currentfile my_gzips/currentfile
fi
murugesandinsShell_script Automation /bin/bash /bin/bash.exe /bin/ksh /bin/mksh.exe AIX C C++ CYGWIN_NT HP-UX Linux MINGW32 MINGW64 SunOS Windows_NT

Commented:
1. Helped on wait list (2016-04-14)
2. It was resolved.
3. Knowledge transfer
4. Question inactive more than a year.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial