Sponsored Content
Top Forums UNIX for Dummies Questions & Answers Loop through directory and extract sub directory names Post 302551102 by personalt on Monday 29th of August 2011 11:59:36 AM
Old 08-29-2011
Loop through directory and extract sub directory names

I am trying to loop through folders and extract the name of the lowest level subfolder

I was running the script below, it returns
/bb/bin/prd/newyork
/bb/bin/prd/london
/bb/bin/prd/tokyo

I really want
newyork
london
tokyo

I couldn't find a standard variable for the lowest level subfolder, does something like that exist? If not what is the best way to through away everything in front of the last /

Code:
 for dir in /bb/bin/prd/*
       do
         (echo $dir)
 done

 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

Use of $ in directory names

I have a TAR (compressed) file that I uncompressed using the following command $ tar xvf uagent.tar It created a directory structure as follows <root>/arcagent/UAGENT/reloc/$UAGENT_HOME/ How do I access files under the $UAGENT_HOME? Every time I do change directory command, the OS... (3 Replies)
Discussion started by: pkappaz
3 Replies

2. Shell Programming and Scripting

Directory names that contain spaces and other suggestions?

The script below was written to select files and convert a particular string to something other and replace that file. However, I came across some issues with filenames that contain spaces, any suggestions to get around this? Any other suggestions that may apply to this code would also be... (5 Replies)
Discussion started by: Shakey21
5 Replies

3. Shell Programming and Scripting

How to sort directory names and use only last?

I need help writing a bash script for the windows cygwin environment. I'm not sure if bash is the optimal tool. Perhaps perl would be better? Either would work. I have directories whose names include the date they were created. The directory names are in the format of... (0 Replies)
Discussion started by: siegfried
0 Replies

4. UNIX for Dummies Questions & Answers

How to display only Owner and directory/sub directory names under particular root

hai, I am new to Unix, I have a requirement to display owner name , directory or sub directory name, who's owner name is not equal to "oasitqtc". (here "oasitqtc" is the owner of the directory or sub directory.) i have a command (below) which will display all folders and sub folders, but i... (6 Replies)
Discussion started by: gagan4599
6 Replies

5. Shell Programming and Scripting

Grepping file names, comparing them to a directory of files, and moving them into a new directory

got it figured out :) (1 Reply)
Discussion started by: sHockz
1 Replies

6. UNIX for Advanced & Expert Users

Directory with same names and different inode no

I am having a problem where i have two directories with same name and different inode number.I want to get rid of newer one but not sure how should i? Because when i change directory i am not sure where i get in and what i am removing:wall: root@server # ls -lia |grep us000xyz_R5 ... (10 Replies)
Discussion started by: sahil_shine
10 Replies

7. UNIX for Dummies Questions & Answers

[Solved] Writing a loop to changing the names of files in a directory

Hi, I would like to write a loop to change the names of files in a directory. The files are called data1.txt through data1000.txt. I'd like to change their names to a1.txt through a1000.txt. How do I go about doing that? Thanks! (2 Replies)
Discussion started by: evelibertine
2 Replies

8. UNIX for Dummies Questions & Answers

Loop through directory names

Some guidance is highly appreciated. I have 10 directories with names ending with 'xyz', each of them have about 30000 files. I want to loop through the contents of each directory and produce a single output per directory. So I want to have 10 output files named 'directory_name'_out. With... (1 Reply)
Discussion started by: newbie83
1 Replies

9. UNIX for Dummies Questions & Answers

Extract directory name from the full directory path in UNIX using shell scripting

My input is as below : /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/rebate/IFIND.REBTE.WROC.txt /splunk/scrubbed/loyal/IFIND.HELLO.WROC.txt /splunk/scrubbed/triumph/ifind.triumph.txt From the above input I want to extract the file names only . Basically I want to... (5 Replies)
Discussion started by: IshuGupta
5 Replies

10. Shell Programming and Scripting

Directory containing files,Print names of the files in the directory that are exactly same content.

Given a directory containing say a few thousand files, please output a list of all the names of the files in the directory that are exactly the same, i.e. have the same contents. func(a_directory_name) output -> {“matches”: , ... ]} e.g. func(“/home/my/files”) where the directory... (7 Replies)
Discussion started by: anuragpgtgerman
7 Replies
CPMAC(1)						    BSD General Commands Manual 						  CPMAC(1)

NAME
/usr/bin/CpMac -- copy files preserving metadata and forks SYNOPSIS
/usr/bin/CpMac [-rp] [-mac] source target /usr/bin/CpMac [-rp] [-mac] source ... directory DESCRIPTION
In its first form, the /usr/bin/CpMac utility copies the contents of the file named by the source operand to the destination path named by the target operand. This form is assumed when the last operand does not name an already existing directory. In its second form, /usr/bin/CpMac copies each file named by a source operand to a destination directory named by the directory operand. The destination path for each operand is the pathname produced by the concatenation of the last operand, a slash, and the final pathname compo- nent of the named file. The following options are available: -r If source designates a directory, /usr/bin/CpMac copies the directory and the entire subtree connected at that point. This option also causes symbolic links to be copied, rather than indirected through, and for /usr/bin/CpMac to create special files rather than copying them as normal files. Created directories have the same mode as the corresponding source directory, unmodified by the process' umask. -p Causes /usr/bin/CpMac to preserve in the copy as many of the modification time, access time, file flags, file mode, user ID, and group ID as allowed by permissions. -mac Allows use of HFS-style paths for both source and target. Path elements must be separated by colons, and the path must begin with a volume name or a colon (to designate current directory). NOTES
The /usr/bin/CpMac command does not support the same options as the POSIX cp command, and is much less flexible in its operands. It cannot be used as a direct substitute for cp in scripts. As of Mac OS X 10.4, the cp command preserves metadata and resource forks of files on Extended HFS volumes, so it can be used in place of CpMac. The /usr/bin/CpMac command will be deprecated in future versions of Mac OS X. SEE ALSO
cp(1) MvMac(1) Mac OS X April 12, 2004 Mac OS X
All times are GMT -4. The time now is 08:54 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy