Can anyone tell me what is the difference between the
ls -p commands in Linux?
-p option adds a
/ at the end of directories, it helps you easily detect which one of the outputs is a directory and which one is a file.
A similar option to
-F which uses these characters to indicate:
@--> symbolic links
|--> fifo files (named pipes).
On the other hand,
ls does not do any of these.
These options are useful when you don't use an option like
--color or your terminal does not support colorizing the output.
$ ls block dm-1 hwrng
It's hard to tell which one is a directory and which one is a file, right? So:
$ ls -p block/ dm-1 hwrng
Now I can tell the
block is a directory.
If you don't notice the effect of
-p, you should check what
ls is aliased to.
As others have said,
ls -p causes directory names to be shown with a trailing
/. However, sometimes people ask about what flags like
-F do because they may appear to have no effect.
Typically the effect is clearly apparent:
ek@Io:~/tmp$ ls directory regular-file ek@Io:~/tmp$ ls -p directory/ regular-file
However, it is common for users to have a shell alias
ls that adds options. If one of those options is
-p or another option that adds the trailing slash to directory names, then adding
-p yourself won't make any difference.
type ls usually shows
ls is aliased to `ls --color=auto'. (This alias is provided by
alias ls='ls --color=auto' in the user's
.bashrc file, which is copied from
/etc/skel when the user account is created.) When a user runs
ls on an interactive shell prompt, it is replaced by
-p appears to have no effect when you pass it to
ls, try running
type ls or
alias ls. (Since it is possible, though rare, to have a shell function for
type is more reliable than
alias at figuring out what is going on here.) It may reveal that you have an
ls alias that includes
There are a few ways to bypass alias expansion:
command ls \ls /bin/ls
That third command is only equivalent if the
ls executable is
/bin/ls. That is almost always the case; it would only be different if a second
ls executable were added elsewhere. Run
type -a ls to see.