Which command should you use to list all files of your current directory in Linux?

The ls command is used to list files. "ls" on its own lists all files in the current directory except for hidden files. "ls *.tex" lists only those files ending in ".tex". There are a large number of options; here are some of the most useful. Options can be combined [this is a general principle of Unix commands] - for example "ls -la" gives a long listing of all files.

  • ls -a will list all files including hidden files [files with names beginning with a dot].
  • ls -F gives a full listing, indicating what type files are by putting a slash after directories and a star after executable files [programs you can run].
  • ls -l gives a long listing of all files. Here is an example section of the output of ls -l :
    drwxr-xr-x   6 eva        users         1024 Jun  8 16:46 sabon
    -rw-------   1 eva        users         1564 Apr 28 14:35 splus
    -rw-------   1 eva        users         1119 Apr 28 16:00 splus2
    -rw-r--r--   1 eva        users         9753 Sep 27 11:14 ssh_known_hosts
    -rw-r--r--   1 eva        users         4131 Sep 21 15:23 swlist.out
    -rw-r--r--   1 eva        users        94031 Sep  1 16:07 tarnti.zip
    

    What does it all mean?

    • The first column gives the type of the file [e.g., directory or ordinary file] and the file permissions.
    • The second column is the number of links to the file i.e., [more or less] the number of names there are for the file. Generally an ordinary file will only have one link, but a directory will have more, because you can refer to it as ``dirname'', ``dirname/.'' where the dot means ``current directory'', and if it has a subdirectory named ``subdir'', ``dirname/subdir/..'' [the ``..'' means ``parent directory''].
    • The third and fourth columns are the user who owns the file and the Unix group of users to which the file belongs. Unless you are working together on the same file, you need not worry about Unix groups.
    • The fifth column is the size of the file in bytes.
    • The next three columns are the time at which the file was last changed [for a directory, this is the time at which a file in that directory was last created or deleted].
    • The last column is the name of the file.
  • ls -R gives a recursive listing, including the contents of all subdirectories and their subdirectories and so on.
  • ls -t lists the files in order of the time when they were last modified [newest first] rather than in alphabetical order.
  • ls -r lists the files in the reverse of the order that they would otherwise have been listed in. Thus, ls -lrt will give a long listing, oldest first, which is handy for seeing which files in a large directory have recently been changed.

Subscribe to our newsletter.

Stay on top of the latest thoughts, strategies and insights from enterprising peers.

Learn how to use the ls command to list files in the terminal with this Linux tutorial.

To list files on a computer with a graphical interface, you usually open a file manager [Files on Linux, Finder on MacOS, Windows Explorer on Windows], and look at the files.

To list files in a terminal, you use the ls command to list all files in the current directory. The pwd commands tells you what directory you're currently in.

$ pwd
/home/tux
$ ls
example.txt
Documents
Downloads
Music
Pictures
Templates
Videos

You can view hidden files with the --all option:

$ pwd
/home/tux
$ ls --all
.               Downloads
..              .local
.bashrc         Music
.config         Pictures
example.txt     Templates
Documents       Videos

As you can see, the first items listed are dots. The single dot is actually a meta location meaning the folder you are currently in. The two dots indicate that you can move back from this location. That is, you are in a folder in another folder. Once you start moving around within your computer, you can use that information to create shortcuts for yourself or to increase the specificity of your paths.

Files and folders and how to tell the difference

You may notice that it's hard to tell a file from a folder. Some Linux distributions have some nice colors set up so that all folders are blue and the files are white and binary files are pink or green, and so on. If you don't see those colors, you can try ls --color. If you're color blind or on a display that doesn't provide colors, you can alternately use the --classify option:

$ pwd
/home/tux/Downloads
$ ls --classify
android-info.txt
cheat/
test-script.sh*

As you can see, folders are given a trailing slash [/] to denote that they are steps within your file system. Binary entities, like zip files and executable programs, are indicated swith an asterisk [*].

Seth Kenlon is a UNIX geek, free culture advocate, independent multimedia artist, and D&D nerd. He has worked in the film and computing industry, often at the same time.

Related Content

This work is licensed under a Creative Commons Attribution-Share Alike 4.0 International License.

Which command is used to list all the files in your current directory in Linux?

The ls command is used to list files. "ls" on its own lists all files in the current directory except for hidden files.

Which command should you use to display the current path of your current directory in Linux?

Use the pwd command to write to standard output the full path name of your current directory [from the /[root] directory].

Which command should you use to change directory in Linux?

cd command in linux known as change directory command. It is used to change current working directory.

What is list command in Linux?

The ls is the list command in Linux. It will show the full list or content of your directory. Just type ls and press the enter key.

Chủ Đề