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` 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? Any help would be greatly appreciated :) |
Hi,
You need a second loop. The first loop (for i in `ls /home/monty/scripting`) gives you all the directories. The second loop should give you all the files in a specific directory (found by the first loop). Code:
for i in `ls /home/monty/scripting` Up to you to make it all work together :) Hope this helps. |
Hi,
Welcome to LQ! Now that we are all aware of your 'needs'. You have presented some of your 'deeds'? It still smells like homework to me. :hattip: You could look at 'Advanced Bash-Scripting Guide' or even query your instructor with the information provided via the forum. :) This link and others can be found at 'Slackware-Links'. More than just SlackwareŽ links! |
What happens if one of the /home/monty/scripting/* entries is not a directory?
|
Quote:
To list directories only: Code:
path="/path/of/interest" Code:
path="/path/of/interest" |
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 :) |
Quote:
EDIT: If your question has been answered, please mark the thread SOLVED by using the "Thread tools" drop down list. |
Hi,
Quote:
|
Ah okay,
Well, it's not any sort of assignment i've been given, I'm currently only in year 11 and am not undertaking a unix based course. Im sick of windows and want to become more effective with unix based systems. It was just a task i wanted to learn without reading something like the entire 'Advanced Bash-Scripting Guide'. Thanks for all the help, Ill try and search/think that bit harder before asking again :) |
Hi,
No reason to be gun shy. 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! |
All times are GMT -5. The time now is 05:41 PM. |