Find the answer to your Linux question:
Results 1 to 3 of 3
ls mydir ls ./mydir ls mydir/ ls ./mydir/ cp xxx mydir cp xxx ./mydir/ ???...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2011
    Location
    STL, USA
    Posts
    8

    Question Do trailing slashes or leading dot-slashes ever matter?


    ls mydir
    ls ./mydir
    ls mydir/
    ls ./mydir/
    cp xxx mydir
    cp xxx ./mydir/


    ???

  2. #2
    Linux User sgosnell's Avatar
    Join Date
    Oct 2010
    Location
    Baja Oklahoma
    Posts
    438
    AFAIK the only time you need the ./ is when you want to run an executable file in the current directory. ./ tells bash to look in the current directory for a command instead of looking in the path. If you want to copy to the current directory, just use the period, not the slash, as in
    Code:
    cp xxx .
    Using ls you don't need anything, because the default, with no other modifiers, is to list the contents of the current directory.

  3. #3
    Linux Guru Cabhan's Avatar
    Join Date
    Jan 2005
    Location
    Seattle, WA, USA
    Posts
    3,252
    They can affect things.

    sgosnell discusses the "./" prefix: it can sometimes change a bareword into a relative path, and this is used, for example:
    Code:
    ls # Run the standard "ls" command (probably /bin/ls)
    ./ls # Run a program called "ls" in the current directory
    bin/ls # Run a program caled "ls" in the bin/ directory
    ./bin/ls # Same as above
    For the case of a trailing slash, this can sometimes matter. A pretty standard example of this is for symlinks to directories:
    Code:
    [alex@niamh ~]$ ls -l test_symlink # List the symlink itself
    lrwxrwxrwx 1 alex users 4 Oct 23 23:45 test_symlink -> test
    [alex@niamh ~]$ ls -l test_symlink/ # List the contents of the link target dir
    total 12
    drwxr-xr-x 2 alex users 4096 Oct 22 10:45 c
    drwxr-xr-x 2 alex users 4096 Oct 22 10:45 perl
    drwxr-xr-x 2 alex users 4096 Oct 22 10:45 ruby

Posting Permissions

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