changing directories (i'm sure there is a simple solution for this)

Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers changing directories (i'm sure there is a simple solution for this)
# 8  
Old 03-03-2002
thanks for the explanation

however, it still wasn't the solution. But the idea for a function was accurate. (I don't know why I didn't try it before)!

I understand how your example works now, (the difference is that the directory I want to change into is the 3rd from the front, but can be any number on the right of the variable) but I thought why not put my script in my bash file as a function, which did the trick.

# was goto before
current_directory=`pwd | cut -f 4 -d "/"`;
new_directory=`pwd | sed s=$current_directory=$1=`
cd $new_directory

Works beautifully, any number of directories down... It's meant to be a time saver when I am like down 10-15 directories and changing to the parallel environment I would either have to recall all the directories (by memory) or copy and paste the directory name (which it would break sometimes the line, so it takes time).

Although your script wasn't exactly what I was looking for LivinFree, thanks for your help as I wouldn't have found my solution without it AND I learnt something.

and FYI everyone:
I renamed the function though, I just realised that there is a man page for goto which I thought was only some DOS based thing for batch files. Although it doesn't cause any confliction, "yet," I thougth it was best to rename to go2. Just in case!
# 9  
Old 04-28-2002
Another simple way to save directory paths that you go to often is to use the "alias" command set up in your login .profile


alias logs='cd /usr/local/bin/logs'

So then by typing logs at your command prompt you will go right there.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Urgent solution for simple sed

Hi Im running this command on AIX in ksh. My input file samp1 contains 1 2 123 12345 When I execute the following sed i dont get a matching pattern sed -n '/{1}/p' samp1 Can anyone help me with this simple thing (3 Replies)
Discussion started by: raghav288
3 Replies

2. Shell Programming and Scripting

What are the differences between 'bash' and 'sh'

Hopefully this doesn't come off as too much of a "newbie" question or a flamebait. But I have recently begun working with a Sun Solaris box after having spent the past five years working with RedHat. From what i can tell, thing look fairly similar and the 'man' command is some help. But I've... (7 Replies)
Discussion started by: deckard
7 Replies

3. UNIX for Advanced & Expert Users

How to remove a file with a leading dash '-' in it's name?

Somehow someone created a file named '-ov' in the root directory. Given the name, the how was probably the result of some cpio command they bozo'ed. I've tried a number of different ways to get rid of it using * and ? wildcards, '\' escape patterns etc.. They all fail with " illegal option --... (3 Replies)
Discussion started by: GSalisbury
3 Replies

4. UNIX for Dummies Questions & Answers

here's how i did a very simple install of invidia drivers

ok i got the nvida drivers for mandrake9 rpm there is 3 rpms you must have glx ,kernel and something else email me if you want the precompiled drivers :: email removed :: once i got the drivers in stalled then i reseted the computer then i put the 1cd of mandrake9 in and did a upgrade i... (2 Replies)
Discussion started by: amicrawler2000
2 Replies

5. Shell Programming and Scripting

Alias's & Functions - simple question

Having a memory lapse: If I redefine a command using an alias or a function - How do I access the "real" command without specifying an absoulte path: i.e. function man { /usr/bin/man |more } alias ls='/usr/bin/ls -l' How do I specify the ls or man command above without the... (6 Replies)
Discussion started by: kornshellmaven
6 Replies

6. UNIX for Dummies Questions & Answers

Changing IP's

How do you change an IP address of an interface. (2 Replies)
Discussion started by: Hordak
2 Replies

7. Shell Programming and Scripting

Clearify what it means under 'WHAT' when hit the 'w'-command

I wonder how I shall read the result below, especially 'what' shown below. The result was shown when I entered 'w'. E.g what is TOP? What is gosh ( what does selmgr mean?)? login@ idle JCPU PCPU what 6:15am 7:04 39 39 TOP 6:34am 6:45 45 45 TOP 6:41am ... (1 Reply)
Discussion started by: Aelgen
1 Replies

8. Programming

may be simple but i don't know -- Print current date from C program

How to print current date of the Unix system accessing thru C++ program ? I wrote like this #include <time.h> ....... time_t tt; struct tm *tod; .... time(&tt); tod = localtime(&tt); cout << tod->tm_mon + 1 << "/" << tod->tm_mday << "/" ... (6 Replies)
Discussion started by: ls1429
6 Replies

9. UNIX for Dummies Questions & Answers

list file's by size order in sepecfied directory and sub directories

How do I list files of type "*.file" for example by size order recursively ? (2 Replies)
Discussion started by: ferretman
2 Replies

10. Programming

a very simple question (but i don't know)

how to write a program that receive a string from keyboard and then print it out. i write a program: main() { char str; gets(str); printf(str); } but when i compile it, the system said something like "new line is not last charicter" and sometime the system said "a3.c is up to date"... (1 Reply)
Discussion started by: dell9
1 Replies
Login or Register to Ask a Question