Find the answer to your Linux question:
Page 1 of 2 1 2 LastLast
Results 1 to 10 of 11
What's the difference between: tar xvf - filename and tar xvf filename and su - username and su username ? Thanks...
  1. #1
    Linux Newbie
    Join Date
    Dec 2004
    Location
    Portland, OR
    Posts
    123

    use of - character in tar, su commands?

    What's the difference between:

    tar xvf - filename
    and
    tar xvf filename

    and

    su - username
    and
    su username

    ?

    Thanks

  2. #2
    Super Moderator MikeTbob's Avatar
    Join Date
    Apr 2006
    Location
    Texas
    Posts
    7,144
    Quote Originally Posted by jwilliams
    What's the difference between:

    tar xvf - filename
    and
    tar xvf filename

    and

    su - username
    and
    su username

    ?

    Thanks
    For commands like tar, usually - is for options
    tar -zxfv

    For su it's a bit different
    su just logs you in as root
    su - logs you in as root with roots path
    Try it yourself, login as root with just su
    issue this command:
    modprobe
    Then login as root with su - and modprobe again
    I do not respond to private messages asking for Linux help, Please keep it on the forums only.
    All new users please read this.** Forum FAQS. ** Adopt an unanswered post.

  3. #3
    Banned
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    1,121
    Quote Originally Posted by jwilliams
    What's the difference between:

    tar xvf - filename
    and
    tar xvf filename
    "-"(stdout/stdin) will tar everyting to stdout, being already the default you shouldn't need this.

    Quote Originally Posted by jwilliams
    su - username
    and
    su username
    same thing as above, "-" is already the default and will not do anything in this case

    see:
    man stdout
    man tar
    man su

  4. #4
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    Quote Originally Posted by jens
    same thing as above, "-" is already the default and will not do anything
    "-" is not default in RedHat and Fedora.
    try this
    Code:
    su 
    echo $PATH
    exit
    su -
    echo $PATH
    compare output of 'echo $PATH'.







    Casper
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  5. #5
    Banned
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    1,121
    Quote Originally Posted by devils_casper
    "-" is not default in RedHat and Fedora.
    try this
    Code:
    su 
    echo $PATH
    exit
    su -
    echo $PATH
    compare output of 'echo $PATH'.

    Casper
    A redhat thingy ...
    It doesn't change anything for me:
    jens@desktop:~$ su others
    Password:
    others@desktop:/home/jens$ echo $PATH
    /usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
    others@desktop:/home/jens$ exit
    exit
    jens@desktop:~$ su - others
    Password:
    others@desktop:~$ echo $PATH
    /usr/local/bin:/usr/bin:/bin:/usr/bin/X11:/usr/games
    others@desktop:~$

  6. #6
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    Normal users have 'common' path and "-" wont do anything but in case of root user, it will make a lot of difference.
    as i suggested earlier, execute 'su' and 'su -' only.
    Last edited by devils casper; 03-06-2007 at 05:06 AM.
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  7. #7
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    i think i am missing something. i am not in Fedora box right now and can't check myself.
    i think "-" changes 'present working directory' too.
    will you please execute 'pwd' command in both cases?
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  8. #8
    Banned
    Join Date
    Nov 2004
    Location
    Belgium
    Posts
    1,121
    Quote Originally Posted by devils_casper
    Normal users have 'common' path and "-" wont do anything
    Isn't that all he asked ("su username" vs "su - username"?

    Quote Originally Posted by devils_casper
    but in case of root user, it will make a lot of difference.
    as i suggested earlier, execute 'su' and 'su -' only.
    "su -" will dump you in / (not really what he asked for in his question though), but their's no standard rule as for why "echo $PATH" would change (as far as I know...).
    jens@desktop:~$ su
    Password:
    desktop:/home/jens# echo $PATH
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11
    desktop:/home/jens# exit
    exit
    jens@desktop:~$ su -
    Password:
    desktop:~# echo $PATH
    /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/bin/X11
    desktop:~#
    Do correct me if I'm missing something...

    EDIT: Oh... you just meant the default Redhat profile ...
    I was under the impression your meant it was "root" that makes a difference (post6).
    I couldn't see your edit and second post before refreshing this page!? (is this forum software supposed to work like this ?).
    All I said is that it doesn't change anything in default (meaning you didn't alter your bash_profile).
    RH/Fedora uses a modified one (also for normal users and not just root, that's what I meant with the redhat thingy).

  9. #9
    Super Moderator devils casper's Avatar
    Join Date
    Jun 2006
    Location
    Chandigarh, India
    Posts
    24,316
    Quote Originally Posted by jens
    I was under the impression your meant it was "root" that makes a difference (post6).
    I couldn't see your edit and second post before refreshing this page!? (is this forum software supposed to work like this ?).
    i didn't edit much in second post. there was typo only. i wrote 'hoot' instead of
    'root'. .

    did you execute pwd command? i can't access Fedora box right now. i will check it in Fedora and post here soon.
    It is amazing what you can accomplish if you do not care who gets the credit.
    New Users: Read This First

  10. #10
    Linux Newbie
    Join Date
    Jan 2007
    Location
    Cupertino, CA
    Posts
    157

    Difference between 'su' and 'su -'

    Plain 'su <user>' spawns a shell thats not a login shell. 'su - <user>' causes a shell to be spawned with first argument as '-' which indicates a login shell.

    Most shells take the first arg as '-' to mean that a new login has been initiated i.e. as if the new user (root or otherwise) logged in afresh over a terminal or ssh or telnet link or whatever. Consequently, they run all the usual login scripts (.bashrc and /etc/bash_profile in case of bash) and so you might get a different PATH according to those files as well as get started with <pwd>=<home directory>.

    Comparing this to plain 'su <user>' case, just a new shell is spawned and all the environment is inherited from the parent process, hence retaining the old PATH and pwd.

    Hope this was not too muddled an explanation.

Page 1 of 2 1 2 LastLast

Posting Permissions

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