How to tar all executable file in a directory


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to tar all executable file in a directory
# 1  
Old 07-06-2009
How to tar all executable file in a directory

Dear all

I want to create a tar file which contains all executable files in a specific directory

cd /appl/home/
file some_exe
some_exe: 64-bit XCOFF executable or object module not stripped

My current approach is to tar it one by one
tar -cvf test.tar exefile1
tar -uvf test.tar exefile2
tar -uvf test.tar exefile3
....

But this is a stupid method, please advise me if there is some clever solution.

Many thanks
Valentino
# 2  
Old 07-06-2009
If you can identify them by name like exefile1, exefile2 and so on, why not use a wildcard like exe*
Else you might want to write a small loop testing each file in the directory like for example:
Code:
$> ls
infile  ksh  ls
$> file *
infile: ASCII text
ksh: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.2.0, ...
ls: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Linux 2.4.1, ...
$> tar -cvf archive.tar `ls -1| while read LINE; do file $LINE| grep -i exec| cut -d: -f1; done`
ksh
ls
$> tar tvf archive.tar
-rwxr-xr-x root/root    184896 2009-07-06 09:18 ksh
-rwxr-xr-x root/root     77352 2009-07-06 09:05 ls

If you want it recursively with subdirectories, you might want to use find instead of ls.
# 3  
Old 07-06-2009
If you need all those files which have execute priviledges:
Code:
tmf=$$.tar.txt
> $tmf
for f in some*
do
     [ -x "$f" ] && echo "$f" >> $tmf
done
tar -cvfF xx.tar "$f"
rm -f "$f"

Or using file cmd output
Code:
tmf=$$.tar.txt
> $tmf
for f in *
do
     filetype=$( file "$f" )
     case "$filetype" in
              *ELF*)  echo "$f" >> $tmf ;;
     esac
done
tar -cvfF xx.tar "$f"
rm -f "$f"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Script to Tar file in a specific Directory

I'm trying to write a Unix script that will go to a specific directory (/tmp/Sanbox/logs) and tar.gz all the log files in that directory and delete the original files that are older than 2 days. So far I have this but it doesn't work. Any help would be appreciated. #!/bin/bash ... (7 Replies)
Discussion started by: Loc
7 Replies

2. AIX

Making Tar of directory and tar file is going to be placed

Quick question, is it possible to make a Tar of completely directory and placing the tar file in it (will this cause even the tar file to tarred ?) sample: /opt/freeware/bin/tar -cvf - /oracle | gzip > /oracle/backup.tgz will the tar file backup.tgz also include backup.tgz ? i tried... (5 Replies)
Discussion started by: filosophizer
5 Replies

3. UNIX for Dummies Questions & Answers

No such file or directory for existing executable

Hi, I have a very puzzling problem. I have a binary file, it is executable but it says "No such file or directory" when I try to run it : root@debian:~# ls -l bmcfwul -rwxr-xr-t 1 root root 762808 Mar 11 2010 bmcfwul root@debian:~# ./bmcfwul -su: ./bmcfwul: No such file or directory... (9 Replies)
Discussion started by: chebarbudo
9 Replies

4. Shell Programming and Scripting

Extract a single file from a tar file to another directory

Hi, I need to extract a single file from a tar file to another directory. So far I have this: This one extract a single file to same directory: tar -xvf filename.tar ./file.txt I tried this but its not working tar -xvf filename.tar /home/dir ./file.txt or this: (6 Replies)
Discussion started by: erin00
6 Replies

5. Solaris

HOW TO extract.tar file to specific directory..?

Hi all, In Solaris howto extract tar file to specific folder. This is what we do in Linux, but how to do the same thing in Solaris ? -tar -xzvf /tmp/etc.tar.bz -C /tmp (Will extract in /tmp dir) 3.gzip COMPRESSION AND EXTRACTION -tar -czvf /tmp/etc.tar.bz /etc -du ... (5 Replies)
Discussion started by: manalisharmabe
5 Replies

6. Shell Programming and Scripting

Tar file with logging and directory via parameter

Hi all, I am fairly new to shell scripting and I am trying the following: My shell script creates a tar file with files with the ending ~. The directory - where the files and sub directories are located - comes as a parameter when I call the script. Files that are archived will be written in... (1 Reply)
Discussion started by: neg42
1 Replies

7. UNIX and Linux Applications

Tar executable

Hi, I need to download tar.exe to archive the files before doing gzip...... I downloaded the executables from Browse GnuWin Files on SourceForge.net but my concern is whether this particular exe is safe to use? is it a licensed version? Have anybody downloaded from this site? Need ur advice. (2 Replies)
Discussion started by: Codesearcher
2 Replies

8. UNIX for Dummies Questions & Answers

file restoration to new directory - tar command

hi, i face some problem which need URGENT assistance. am performing a restoration for recovery in an AIX UNIX server. when i use the tar -tvf command to view the tape contents, it gives me /ata1/mydir/myfile. i understand that how the file was backed up determine whether we could restore... (2 Replies)
Discussion started by: newbie168
2 Replies

9. Shell Programming and Scripting

TAR manipulation of file directory

I want to insert file to tar file (by tar command). The file is currently in a diffrenet directory and i want to be saved at the tar file as it was in other directory. I write the script in korn shell. How can i do it? (0 Replies)
Discussion started by: arielromi
0 Replies

10. UNIX for Advanced & Expert Users

extract a sub directory form a tar file

anyone know if it is possable to extract a subdirectory in a tar file. IE tarfile contains parent dir -sub dir A -sub dir B I want to extract sub dir B. (2 Replies)
Discussion started by: Optimus_P
2 Replies
Login or Register to Ask a Question