LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Zip specific files... (https://www.linuxquestions.org/questions/linux-newbie-8/zip-specific-files-4175676470/)

ddenial 06-04-2020 07:23 AM

Zip specific files...
 
Hello All

I have some script files in a folder along with many other types of files. Is there a way to zip files by username or by permission of files. I want to zip all script files (with execution bit) in a directory.

Thanks

Guttorm 06-04-2020 07:31 AM

Hi

You could combine it with find it with the find command.

Something like this:

Code:

zip test.zip $(find . -type f -executable)
The find command has lots of options, see "man find" for details.

sxy 06-04-2020 07:37 AM

Hi,

You can also use a pipeline:
Code:

find -type f -executable | xargs zip foo.zip

ddenial 06-04-2020 07:41 AM

Thanks. For some reason -f executable didn't list all files with execution bit. The following worked for me.
Code:

zip scripts.zip $(find . -type f -perm /+x)
Thanks

shruggy 06-04-2020 07:42 AM

zip creates test.zip archive if it doesn't exist and adds new members to it if it already exists, so this should also work:
Code:

find . \! -name '*~' -type f -executable -exec zip ../test.zip {} +

ehartman 06-04-2020 09:11 AM

Quote:

Originally Posted by ddenial (Post 6130667)
Thanks. For some reason -f executable didn't list all files

It's not -f, but "-type f" (normal files only) combined with "-executable" (has a "x" bit in its permissions). The first is to exclude directories and sym-links with that X-bit.

ddenial 06-04-2020 09:23 AM

Quote:

Originally Posted by ehartman (Post 6130709)
It's not -f, but "-type f" (normal files only) combined with "-executable" (has a "x" bit in its permissions). The first is to exclude directories and sym-links with that X-bit.

Sorry, it was a typo mistake. In the terminal I did put correct syntax
Code:

$ ll
-rw-rw-r--. 1 neon neon  119 Jun  4 18:03 gnome-mimial.txt
-rwx------. 1 neon neon  6.4K Jun  4 17:44 hevc
-rw-rw-r--. 1 neon neon  2.2K Jun  4 18:03 hevc-script.txt
-rw-r--r--. 1 neon neon    71 Jun  4 18:03 java.txt
-rwx------. 1 neon neon  202 Jun  3 23:47 jeda
-rwx------. 1 neon neon  2.1K Jun  3 23:47 nvd
-rw-r--r--. 1 neon neon    34 Jun  4 18:03 xfce-cent.txt
-rwx------. 1 neon neon  2.1K Jun  3 23:47 xvd
-rwx------. 1 neon neon  6.1K Jun  3 23:47 xvEncode
-rwx------. 1 neon neon  2.9K Jun  3 23:47 xvJoin
-rwx------. 1 neon neon  2.6K Jun  3 23:47 xvjoin.sh
-rwx------. 1 neon neon  4.1K Jun  3 23:47 xvSlow
-rwx------. 1 neon neon  1.9K Jun  3 23:47 xvTag
-rwx------. 1 neon neon  3.8K Jun  3 23:47 xvYuv4
-rwx------. 1 neon neon  9.6K Jun  3 23:47 yama
-rwx------. 1 neon neon  495 Jun  4 17:44 ytpl
-rw-r--r--. 1 neon neon  161 Jun  4 18:03 yt.txt


$ find . -type f -executable
./hevc
./ytpl

$ find . -type f -perm /+x
./jeda
./nvd
./xvd
./xvEncode
./xvJoin
./xvjoin.sh
./xvSlow
./xvTag
./xvYuv4
./yama
./hevc
./ytpl


shruggy 06-04-2020 09:29 AM

How interesting. What would this command show:
Code:

find -type f -perm /+x -exec file {} \;

sxy 06-04-2020 09:36 AM

re: #7

from manpage of find:
Code:

-executable
              Matches files which are executable  and  directories  which  are
              searchable  (in  a  file  name  resolution sense) by the current
              user.  This takes into account access control  lists  and  other
              permissions  artefacts  which the -perm test ignores.
  This test
              makes use of the access(2) system call, and so can be fooled  by
              NFS servers which do UID mapping (or root-squashing), since many
              systems implement access(2) in the client's kernel and so cannot
              make use of the UID mapping information held on the server.  Be‐
              cause this test is based only on the  result  of  the  access(2)
              system  call,  there  is no guarantee that a file for which this
              test succeeds can actually be executed.


ddenial 06-04-2020 09:37 AM

Quote:

Originally Posted by shruggy (Post 6130723)
How interesting. What would this command show:
Code:

find -type f -perm /+x -exec file {} \;

Executed 'file <filename>' and realized the mistake I did. The executable shell scripts were having different owner usernames. In my previous post, I had changed every username to 'neon' for easy reading. the '-type f -executable' only showed the files by an active user (me), whereas '-perm /+x' showed executable files of all users.

My bad. Sorry.


All times are GMT -5. The time now is 10:13 PM.