Shell script to move files, add extension and change permissions

Posted on 2009-02-22
Medium Priority
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)
Question by:Awk2009
LVL 40

Accepted Solution

omarfarid earned 1000 total points
ID: 23704160

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

here assumed that filelist contains files full path names , other wise you need to cd to dir before the while loop
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

Open in new window


Author Comment

ID: 23707974
Awesome - Thanks!
LVL 10

Expert Comment

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?

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