[SOLVED] move all ".txt" files, adding parent directory to filename
Linux - NewbieThis 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
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
move all ".txt" files, adding parent directory to filename
Hi,
My first post on this forum,
I am trying to move all the txt files with a script from multiple directories to one directory, adding the parent directories of the files to the file names.
It's a little complicated to explain, but i hope the script i have so far explains what im trying to do better:
Code:
for i in `ls /home/monty/scripting`
do
mv -v /home/monty/scripting/$i/*.txt /home/monty/scripting/$i-*.txt
done
exit 0
e.g.
move
/home/monty/scripting/1/file.txt
to
/home/monty/scripting/1-file.txt
repeated for other file names an directories
the script works exactly how i want it to if i specify a filename, but my problem is maintaining the original file name whilst adding the parent directory to the file name.
Im hoping it's something really simple im missing?
Homework? Man i wish i did this for homework.
I'm just relatively new to unix.
Catkin: The shell just prints out that mv cannot stat those locations; because they are files. It works fine for the directories it finds.
Thanks to druuna for that detail i was missing, also thanks to lutsup for the handy tips. And thanks to onebuck for the link, hopefully it's more helpful than all the google searches i did
Thanks for all the help again, this was a last resort after much searching.
Wasnt being lazy
Homework? Man i wish i did this for homework.
I'm just relatively new to unix.
Catkin: The shell just prints out that mv cannot stat those locations; because they are files. It works fine for the directories it finds.
Thanks to druuna for that detail i was missing, also thanks to lutsup for the handy tips. And thanks to onebuck for the link, hopefully it's more helpful than all the google searches i did
Thanks for all the help again, this was a last resort after much searching.
Wasnt being lazy
The presented information in your original post does look like a lot of the typical homework questions. Your script is a basic script assignment to most new users of scripting.
We see a lot of homework type post. No one gains by doing others assigned work. At least you put your attempt (which is a typical assignment) within your post. You can get some additional help from the 'Tutorial' section of 'Slackware-Links'. More than just SlackwareŽ links!
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.