Find the answer to your Linux question:
Results 1 to 5 of 5
Lots of commands in Linux require you to type in paths and filenames. Occasionally, they can get long and convoluted. Surely, there's a way around that? How can I store ...
  1. #1
    Just Joined!
    Join Date
    Dec 2006
    Posts
    13

    Saving some time when working with paths

    Lots of commands in Linux require you to type in paths and filenames. Occasionally, they can get long and convoluted. Surely, there's a way around that?

    How can I store the current working directory into some sort of variable? And then be able to use that variable in a command later on? And then delete the variable when I'm done with it?

    Also, how can I do the same with one of the files listed when I enter the ls command? For example, one of the files I was working with lately was called j2sdk-1.4.2-03-linux-i586.bin, which is a monster of a name to type in manually. Is there a way to save some time and effort here?

    All tips welcome, and thanks in advance!

  2. #2
    Linux User
    Join Date
    Feb 2006
    Posts
    484
    for get the current working directory with full path use the pwd command
    and use the command substitute operators `` (its not "" or '')

    example:
    /dir1/dir2/dir3
    cd /dir1/dir2/dir3
    pwd
    /dir1/dir2/dir3

    to run application in the dir3 which not contained in the $PATH
    `pwd`/application
    or us the "./" syntax
    ./application

    2.
    for long names use the bash complement function use TAB key
    example
    you want run j2sdk-1.4.2-03-linux-i586.bin in /dir1/dir2/dir3 with full path
    a,
    cd /dir1/dir2/dir3
    `pwd`/j2sdk-{PRESS TAB KEY} it will became /dir1/dir2/dir3/j2sdk-1.4.2-03-linux-i586.bin , and hit enter

    or
    ./j2sdk-{PRESS TAB KEY}

  3. #3
    Linux User Daan's Avatar
    Join Date
    Aug 2005
    Location
    The Netherlands
    Posts
    320
    You can add a variable to your environment like this:

    Code:
    daan@schmauck:~$ C=/home/daan/code
    Then, you can use "C" as a substitute for the long path name like this:

    Code:
    daan@schmauck:~$ echo $C
    /home/daan/code
    daan@schmauck:~$ cd C
    bash: cd: C: No such file or directory
    daan@schmauck:~$ cd $C
    daan@schmauck:~/code$
    Note the need for a $.

    There's no need to delete when you're done, your variable will have a limited scope and is gone as soon as you close the terminal window.

  4. #4
    Linux Guru Juan Pablo's Avatar
    Join Date
    Mar 2006
    Location
    /home/south_america/ecuador/quito
    Posts
    2,064
    Also, how can I do the same with one of the files listed when I enter the ls command? For example, one of the files I was working with lately was called j2sdk-1.4.2-03-linux-i586.bin, which is a monster of a name to type in manually. Is there a way to save some time and effort here?
    Type j2sdk and hit tab, the shell will auto complete the file name, it's also a great way to avoid typos
    Put your hand in an oven for a minute and it will be like an hour, sit beside a beautiful woman for an hour and it will be like a minute, that is relativity. --Albert Einstein
    Linux User #425940

    Don't PM me with questions, instead post in the forums

  5. #5
    Just Joined!
    Join Date
    Dec 2006
    Posts
    13
    Thanks for the tips!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •