-2

what's the difference between the following commands?

ls -al

ls -al /

because it shows me different content list for them.

I tried to find the answer but failed, if this is a duplicate question please paste the answer for it.

2
  • ls -Al lists file in the current directory and ls -al lists file in /. What exactly do you have a problem with? May 7, 2017 at 16:20
  • 1
    Hi Arkadiusz and John, your answers are very helpful, my question is about the difference between those two commands, :)
    – schumi
    May 7, 2017 at 16:41

2 Answers 2

2

From the manpage:

ls [OPTION]... [FILE]...

List information about the FILEs (the current directory by default).

So ls -al lists the current directory (the default), ls -al / lists the root directory. Unless your current directory is the root directory, you’ll get different results.

0
1

ls -al lists all files and directories in the current directory, because when no directory is specified, ls assumes you want it to list the current working directory. You can view the current working directory via the pwd command. In most cases the default working directory is your home directory (/home/username) .

ls -al / on the other hand lists all files in the root directory (/) instead of the working directory (by default /home/username). You can change the default working directory via cd /path/to/desireddirectory

If you want you default working directory to be / then do cd /

1
  • ok, thank you. current directory is ok, so i won't change it.
    – schumi
    May 7, 2017 at 16:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .