Finding all script files


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Finding all script files
# 1  
Old 04-30-2009
Finding all script files

Hello All,

After a HDD crash, I would like to selectively back up all my script files. What is the most efficient way to do this?

The pseudo code I was thinking of was something like this:

for a in `find ./ -name "*"`
do
if (file $a) == Bourne|Tcsh|... then
echo $a >> ListofFilestoBeArchived
done

Any ideas? Thanks.

PRU
# 2  
Old 04-30-2009
I would update the find command.
# this would only get executable files
Code:
find . -type f -executable

# this would get that have been updated sense the last backup
Code:
find . type f -executable -newer <lastbackupfile>

# 3  
Old 05-01-2009
The trouble with that is on my external NTFS formatted HDD, everything is mounted as executable. I tried changing the ownership and permissions as root but that does not do anything. (Ubuntu). So I cannot just use
Code:
find . -type f -executable



Quote:
Originally Posted by ldapswandog
I would update the find command.
# this would only get executable files
Code:
find . -type f -executable

# this would get that have been updated sense the last backup
Code:
find . type f -executable -newer <lastbackupfile>

# 4  
Old 05-01-2009
if you have the permission to read from the mounted HDD ( I guess its there), there should not be any problem.

you need to provide mounted device path to the find command.

Code:
find /mnt/external_ntfs_etc -type f -name "<your preference>"

# 5  
Old 05-01-2009
There seems to be some confusion, so let me rephrase the question:
How can I just extract the files are shell scripts?

I can mount the HDD, I have r/w permissions but all files have the executable bit set. So I cannot do something like : find . -perm -664 since that lists all files (including data files)
# 6  
Old 05-01-2009
you have "-name" filter.
if all the files are scripts there should be something similar in the names and their extension
can be same

so you can use the following if you want all the files with ".sh" ext.
Quote:
-name "*.sh"
you can logical OR the filter with any other extension if you have.

It will be better if you can post what type of executable you want from the mounted location.
# 7  
Old 05-01-2009
Sorry, Anchal, if all the scripts had an extension or had a simple filer, I wouldn't be posting this message. There are some scripts with no extension (bad mistake on my part). Many of them have the preable though (#!/bin/bash etc). So to repeat the question, I would like to selectively find files whose file output looks like this:

Code:
file CountRatesWithRootScript 
CountRatesWithRootScript: Bourne-Again shell script text executable


Quote:
Originally Posted by anchal_khare
you have "-name" filter.
if all the files are scripts there should be something similar in the names and their extension
can be same

so you can use the following if you want all the files with ".sh" ext.


you can logical OR the filter with any other extension if you have.

It will be better if you can post what type of executable you want from the mounted location.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Finding total distinct count from multiple csv files through UNIX script

Hi All , I have multiple pipe delimited csv files are present in a directory.I need to find out distinct count on a column on those files and need the total distinct count on all files. We can't merge all the files here as file size are huge in millions.I have tried in below way for each... (9 Replies)
Discussion started by: STCET22
9 Replies

2. Shell Programming and Scripting

Need help in finding and copying list of files using bash shell script

Dear All, I have a situation where I want to copy some files of type .txt. These files are o/p from one program. Some of the files are named as fileName .txt instead of fileName.txt after fileName by mistake I have specified "space". Now I want to move these files as follows. mv fileName*... (13 Replies)
Discussion started by: linuxUser_
13 Replies

3. Shell Programming and Scripting

Help with shell script - not finding files

Hello, I have a shell script like the one below but cannot get it working: #!/bin/bash #$ -cwd CHR=$2 # directories ROOT_DIR=./ RESULTS_DIR=${ROOT_DIR}results/ # executable SHAPEIT_EXEC=${ROOT_DIR}shapeit.v2.r727.linux.x64/shapeit.v2.r727.linux.x64 # parameters THREAT=5... (1 Reply)
Discussion started by: wmelroy
1 Replies

4. UNIX for Dummies Questions & Answers

Script help: Finding Files on a server with no DB reference

Hey Everyone, This is my first post here so I hope I'm in the right spot. I need some help with a script. I don't have much experience in UNIX besides the basic command line stuff which I haven't used much so bear with me. :o I've got a web application which acts as a document repository... (5 Replies)
Discussion started by: Clark_Griswold
5 Replies

5. Shell Programming and Scripting

Finding files with wc -l results = 1 then moving the files to another folder

Hi guys can you please help me with a script to find files with one row/1 line of content then move the file to another directory my script below runs but nothing happens to the files....Alternatively Ca I get a script to find the *.csv files with "wc -1" results = 1 then create a list of those... (5 Replies)
Discussion started by: Dj Moi
5 Replies

6. Shell Programming and Scripting

Need help in writing script for finding files in the unix machine?

I would like to find whether a file exists in the UNIX machine. That i can check using if ;then echo "exists" echo " `cat $file` " else echo "invalid file" fi. and i can find out using : find / -name "filename" . But it i have wanted to search in all directories. How to get... (3 Replies)
Discussion started by: rparsa001
3 Replies

7. Shell Programming and Scripting

script for Finding files in a folder and copying to another folder

Hi all, I have a folder '/samplefolder' in which i have some files like data0.txt, data1.txt and data2.txt. I have to search the folder for existence of the file data0.txt first and if found have to copy it to some other file; next i have to search the folder for existence of file... (5 Replies)
Discussion started by: satish2712
5 Replies

8. Shell Programming and Scripting

Finding files

Hello guys, Please your help, i need to find all the files writed in the last 5 minutes, but without create another file using touch (like im doing right now): I am doing this: anio=`date +%Y` mes=`date +%m` dia=`date +%d` hora=`date +%H` minuto2=`date +%M` minuto=`expr... (1 Reply)
Discussion started by: lestat_ecuador
1 Replies

9. UNIX for Dummies Questions & Answers

Unix shell script for finding top ten files of maximum size

I need to write a Unix shell script which will list top 10 files in a directory tree on basis of size. i.e. first file should be the biggest in the whole directory and all its sub directories. Please suggest any ideas (10 Replies)
Discussion started by: abhilashnair
10 Replies

10. Shell Programming and Scripting

finding duplicate files by size and finding pattern matching and its count

Hi, I have a challenging task,in which i have to find the duplicate files by its name and size,then i need to take anyone of the file.Then i need to open the file and find for more than one pattern and count of that pattern. Note:These are the samples of two files,but i can have more... (2 Replies)
Discussion started by: jerome Sukumar
2 Replies
Login or Register to Ask a Question