?
Solved

Shell script to move files, add extension and change permissions

Posted on 2009-02-22
6
Medium Priority
?
230 Views
Last Modified: 2013-10-08
Need help writing a shell script to do the following:

1) Move all files listed in a text file located in /tmp/filelist from their current dir to /home/user/testfiles/ and add the extension .COPY to the end of each file.

2) Modify the files so that they are only readable by myself (chmod 400)
0
Comment
Question by:Awk2009
4 Comments
 
LVL 40

Accepted Solution

by:
omarfarid earned 1000 total points
ID: 23704160

cat /tmp/filelist | while read file
do
   mv $file /home/user/testfiles/$file.COPY
  chmod 400 /home/user/testfiles/$file.COPY # or chmod 400 $file - if you mean orig. files
done

here assumed that filelist contains files full path names , other wise you need to cd to dir before the while loop
0
 
LVL 23

Assisted Solution

by:Maciej S
Maciej S earned 1000 total points
ID: 23704538
If filelist contains full path, then - destination path with your script can be for example: /home/user/testfiles/usr/local/etc/file :)

Another version:
for file in `cat /tmp/filelist`; do
   NAME=`basename ${file}`
   mv ${file} /home/user/testfiles/${NAME}.COPY
   chmod 400 /home/user/testfiles/${NAME}.COPY
done

Open in new window

0
 

Author Comment

by:Awk2009
ID: 23707974
Awesome - Thanks!
0
 
LVL 10

Expert Comment

by:TRW-Consulting
ID: 34090476
I was browsing through some old, but still open questions and this one popped up. Out of curiosity why has this one been open for so long without points being awarded?  Do the moderators not monitor open questions and close them when they have obviously been answered?
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
Suggested Courses
Course of the Month13 days, 22 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question