Truncate path and keep only filenames


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Truncate path and keep only filenames
# 1  
Old 09-24-2010
Truncate path and keep only filenames

Hi everyone,

I have a question for you, I'm trying to create a script that will automate creating loading screens for the iPhone.

So what I need to do, is list the directories inside /var/mobile/Applications and scan inside those, for the .app directory inside each. Take that .app name and create a folder in /var/stash/Themes/LoadingScreens.theme/Folders with the same name found earlier.

I tried to get the list with this command:

Code:
find /var/mobile/Applications/ -name "*.app"

But what I get is a list with the full path in front of what I need to get. How could I either truncate it to keep only what I need, or either list only the .app directories, and not the full path preceding it?

Thank you in advance,

Pierre-André
# 2  
Old 09-24-2010
If the file name doesn't contain the "/" character, you could use split function in perl.
# 3  
Old 09-24-2010
Try combining find and basename.
# 4  
Old 09-24-2010
You could pipe the output through sed to strip the path:

Code:
find . -name "*.foo" | sed "s!.*/!!"

# 5  
Old 09-24-2010
Well actually the .app name is a directory name.

I was able to shorten the path to: /ThisIsAnApp.app using the following command:


Code:
find /var/mobile/Applications/ -name "*.app" | sed 's/\/.*\/.*\/.*\/\(.*\)/\/\1/g'

After looking at another post about truncating here.

While I can follow guides, and stuff, and I'm confortable with linux based system, I don't know the commands in enough details to come up with a solution myself. So just by telling me to look at the split function of perl, wouldnt be enough, but sure a starting point for me to look for.


Here is a concrete example of what exactly I'm trying to do.

If I list my /var/mobile/Applications, I will have a bunch of directories named like this:

026E729E-B9D1-4A7A-B07F-A5DAEA4F2E7E and so on.

Inside each is a few folders, and filenames. But what I want to get is the DoodleJump.app directory name inside that 026E729E-B9D1-4A7A-B07F-A5DAEA4F2E7E folder. Then create a DoodleJump.app folder in /var/stash/Themes/LoadingScreens.theme/Folders directory.

And repeat for every directories inside /var/mobile/Applications.

I hope it's more clear now.. Sorry I'm french, so...

---------- Post updated at 07:01 PM ---------- Previous update was at 06:59 PM ----------

Quote:
Originally Posted by agama
You could pipe the output through sed to strip the path:

Code:
find . -name "*.foo" | sed "s!.*/!!"

I get this error message with the following line of code:

-sh: !.*/!!": event not found
# 6  
Old 09-24-2010
Seems I misunderstood the original request; this will just strip the paths which I don't think is what is desired.
# 7  
Old 09-24-2010
I can get the list I want with this line of code:

Code:
find /var/mobile/Applications/ -name "*.app" -printf "%f\n"

How to process each and create the directories from there? would for dir in something works? How to pipe the lists to the for dir loop?
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Command to see the logical volume path, device mapper path and its corresponding dm device path

Currently I am using this laborious command lvdisplay | awk '/LV Path/ {p=$3} /LV Name/ {n=$3} /VG Name/ {v=$3} /Block device/ {d=$3; sub(".*:", "/dev/dm-", d); printf "%s\t%s\t%s\n", p, "/dev/mapper/"v"-"n, d}' Would like to know if there is any shorter method to get this mapping of... (2 Replies)
Discussion started by: royalibrahim
2 Replies

2. Shell Programming and Scripting

print all filenames in directory with path to another file

hi, i have a directory at /path/unix with the following files 1.txt 2.txt 3.txt 4.txt I want to make another file called filenames.txt at a different location called /path/home. So, my output file would be /path/home/filenames.txt with contents /path/unix/1.txt... (1 Reply)
Discussion started by: jacobs.smith
1 Replies

3. AIX

tprof, truncate the process path

Hi, i tryed tprof -skex sleep 6 but... Process PID TID Total Kernel User Shared Other Java ======= === === ===== ====== ==== ====== ===== ==== wait 57372 77863 31.31 31.31 0.00 0.00 0.00 0.00 wait ... (1 Reply)
Discussion started by: zanac
1 Replies

4. Shell Programming and Scripting

Sorting a list of filenames but keeping the path information.

Hi All I've googled around for this and can't see a way of doing it. I have a file that contains a number of records that are layed out something like the following. /path/to/directory/that/contains/a/file/I/need/filename.pdf The path itself can vary both in terms of the names and the... (7 Replies)
Discussion started by: Bashingaway
7 Replies

5. UNIX for Advanced & Expert Users

Truncate folder path

Hello, Given below are 2 sample paths from 2 different servers: /opt/temp/PROD/Script/New/Letters /opt/Share/temp/Share1/PROD/Script/Files/New/Letters I would like to truncate the path till the folder "PROD". Please note that the field count of the folder "PROD" vaires from... (1 Reply)
Discussion started by: DawnNish
1 Replies

6. Shell Programming and Scripting

Truncate table

Hi In unix able to connect to oracle database and create table ,when rerun ,if table exist ,truncate that table.Any idea how to do that a.sh ---- sqlplus -s datadmin/password <<EOF create table xx(col1 number, col2... ); exit; EOF I... (1 Reply)
Discussion started by: mohan705
1 Replies

7. Shell Programming and Scripting

Truncate File contain

I have one file which first line is blank and second line has some data. $cat filename output: 30-MAY-07 I want to store 30-MAY-07 value in one variable. for that I wrote var="`head -2 filename`" It will give that result but I want to truncate the first line which is blank. plz help. (2 Replies)
Discussion started by: rinku
2 Replies

8. Shell Programming and Scripting

Truncate directory path

Is it possibe to use sed for the following? I would like to truncate the output of a directory path if it's over 3 directory levels deep. For example: /dir1/dir2/dir3 -- NO change required but, /dir1/dir2/dir3/dir4 would output as ~/dir4 Thanks. (4 Replies)
Discussion started by: here2learn
4 Replies

9. Shell Programming and Scripting

How to truncate as filesize?

Hello everybody it's me again. I have a procces that is writing in a 'file1' automatically but i want to truncate 'file1' to a filesize 'x' that mean if the 'file1' size is 'x' i want to delete the first lines while the last lines are being writed, that have sence? in the process are an... (1 Reply)
Discussion started by: Lestat
1 Replies

10. UNIX for Dummies Questions & Answers

Truncate what is It?

what does this command do ? as in does this command just make sure everything in the file is executed? or does it flush the file? Actually this is used on a file in a progress database but I believe it is a unix command? (2 Replies)
Discussion started by: rocker40
2 Replies
Login or Register to Ask a Question