Truncate path and keep only filenames


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Truncate path and keep only filenames
# 15  
Old 09-25-2010
If you do get an iphone tho, make sure the one you get is jailbreakable. That's the only downside to having an iphone. You need to get familiar with the jailbreak, and make sure you dont update firmware when a new one comes out.

Once out of jail, it's a wonderful device! I'm not an Apple Fanboy, and the iPhone is the only apple product I own, but it's a really nice device! I'm sure you will like it, specially with your command line skills!

Here is the final product of my script, tell me if I done things right, it now checks for existing directories, and it fixed the problem I had, where even if a file was a link, it was getting removed and recreated.

Code:
#!/bin/sh

tmp=/tmp/list.$$
ls -d /var/stash/Themes.* >$tmp 2>/dev/null     # look for existing directories

if [[ -s $tmp ]]     # if tmp file has size, something was found
then
        count=$(wc -l <$tmp)     
        if (( $count > 1 ))
        then
                echo "found more than one Themes directories in /var/stash; please enter path to use:"
                cat $tmp
                read tpath
        else
                read tpath <$tmp                # just get the one path
        fi

        tpath="$tpath/iMatte Loading Screens.theme/Folders"             # build the whole name
else
        echo "could not find a Themes directory in /var/stash [FAIL]"
        exit 1
fi


rm -f $tmp


find /var/mobile/Applications/ -name "*.app" -printf "%f\n" | while read file_name
do
        if [[ ! -e "$tpath/$file_name" ]]
        then
        	echo "making directory $file_name"    # nice confirmation
        	mkdir "$tpath/$file_name"
        else
        	echo "there is already a directory named $file_name"
        fi
done

find /Applications/ -name "*.app" -printf "%f\n" | while read file_name
do
        if [[ ! -e "$tpath/$file_name" ]]
        then
		echo "making directory $file_name"    # nice confirmation
        	mkdir "$tpath/$file_name"
        else
        	echo "there is already a directory named $file_name"
        fi
done

if ! cd "$tpath"
then
    echo "unable to switch to "$tpath" [FAIL]"
    exit 1
fi

for dir in *
do 
        if [[ -d "$dir" ]] 
        then
                if [[ -L "$dir/Default.png" ]]            # true if exists and is a symbolic file; remove if not a link.
                then
                        echo "All is good for $dir/Default.png, already a link.  Skipping..."
                elif [[ -e "$dir/Default.png" ]]
                then      
                        echo "Removing $dir/Default.png, it was an ordinary image"
			   rm "$dir/Default.png"
                        echo "Creating a link to ../../Default.png in $dir"
			   ln -s ../../Default.png "$dir/Default.png"
                elif [[ ! -e "$dir/Default.png" ]]          # true if it doesnt exist
                then
                        echo "Creating a link to ../../Default.png in $dir"
			   ln -s ../../Default.png "$dir/Default.png"
                fi

        fi
done

cd /var/mobile

Thank you very much for all your help, you have been most helpful!

PS: If you would like to see the theme I built for the iPhone, go to iMatte | Imatte, Theme, Cydia, Iphone, Complete. You will find many screenshots, video, etc about it! It just went live 2 weeks ago! There is lots of work involved in it! Might even tip in the balance even more for you to get an iphone Smilie
# 16  
Old 09-25-2010
Looks good to me. Glad that you were able to make things work for you. Thanks for the scoop on the iPhone. I'll have a look at the site.
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