Register
It is currently Mon Apr 23, 2018 6:49 pm

Looping through all folders in a folder.


All times are UTC - 6 hours


Post new topic Reply to topic  [ 2 posts ] 
Author Message
 PostPosted: Fri Mar 02, 2018 2:21 pm   

Joined: Fri Mar 02, 2018 12:34 pm
Posts: 2
I am trying to write a script that loops through all the folders within a given folder.
My intention is to access each folder and rename each file ending with fna.gz with the name of the folder it resides in.

Code:

#!/bin/bash

cd /p/w/d/

for f in /p/w/d/*; do
   echo $f

done


I'm going to take this step by step because first of all at this point if I print "f" it prints the whole pwd including the folders i.e. p/w/d/folder1. Instead of printing just folder1. So firstly how can I get it to print just folder1?


Top
 Profile  
 PostPosted: Sat Mar 03, 2018 1:20 am   

Joined: Mon Oct 20, 2014 9:53 am
Posts: 574
Give an example of the target name.
How to something like /path/to/fiile -> path_to_file.some_extensions


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: No registered users and 25 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP