LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-04-2020, 08:23 AM   #1
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Rep: Reputation: 56
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
 
Old 06-04-2020, 08:31 AM   #2
Guttorm
Senior Member
 
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,448

Rep: Reputation: 446Reputation: 446Reputation: 446Reputation: 446Reputation: 446
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.
 
1 members found this post helpful.
Old 06-04-2020, 08:37 AM   #3
sxy
Member
 
Registered: Aug 2019
Posts: 43

Rep: Reputation: Disabled
Hi,

You can also use a pipeline:
Code:
find -type f -executable | xargs zip foo.zip
 
1 members found this post helpful.
Old 06-04-2020, 08:41 AM   #4
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Original Poster
Rep: Reputation: 56
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
 
Old 06-04-2020, 08:42 AM   #5
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,669

Rep: Reputation: Disabled
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 {} +
 
1 members found this post helpful.
Old 06-04-2020, 10:11 AM   #6
ehartman
Senior Member
 
Registered: Jul 2007
Location: Delft, The Netherlands
Distribution: Slackware
Posts: 1,674

Rep: Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888Reputation: 888
Quote:
Originally Posted by ddenial View Post
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.
 
1 members found this post helpful.
Old 06-04-2020, 10:23 AM   #7
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Original Poster
Rep: Reputation: 56
Quote:
Originally Posted by ehartman View Post
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
 
Old 06-04-2020, 10:29 AM   #8
shruggy
Senior Member
 
Registered: Mar 2020
Posts: 3,669

Rep: Reputation: Disabled
How interesting. What would this command show:
Code:
find -type f -perm /+x -exec file {} \;
 
1 members found this post helpful.
Old 06-04-2020, 10:36 AM   #9
sxy
Member
 
Registered: Aug 2019
Posts: 43

Rep: Reputation: Disabled
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.
 
1 members found this post helpful.
Old 06-04-2020, 10:37 AM   #10
ddenial
Member
 
Registered: Dec 2016
Distribution: CentOS, Fedora, Ubuntu
Posts: 359

Original Poster
Rep: Reputation: 56
Quote:
Originally Posted by shruggy View Post
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.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] How can I have zip -d file.zip "__MACOSX*" work on all zip files in directory? thomwblair Linux - Newbie 10 10-08-2018 03:30 PM
How to zip csv files having specific pattern in a directory using UNIX shell script? ROOTS_S Linux - Newbie 3 12-23-2016 07:36 AM
Linux zip program's -d -tt option deletes all files from zip archive Arun Gupta Linux - Software 4 04-27-2011 08:06 PM
Strange warning message when accessing zip files on specific samba share bdb4269 Linux - General 4 01-31-2011 03:26 PM
How to zip several files to several zip with one command? thomas2004ch Linux - Newbie 4 02-08-2010 09:13 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 04:08 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration