You are reading the article Useful Linux Commands To List Contents Of A Directory updated in September 2023 on the website Saigonspaclinic.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested October 2023 Useful Linux Commands To List Contents Of A Directory
When it comes to Linux commands, there are a ton of them that you can use to run tasks. And if you want to list the contents of a directory just like a file manager, there are a few commands to do so. Let’s check them out.ls
The most common Linux command to list the content of a directory is ls. By default, ls lists the contents of a directory in columns. Different colors are used to display files and directories.
Directories created by the user have their names displayed within single quotes. Directories created by the system have their names simply displayed. The colors used to display the names of files, directories and scripts depend on the visual theme used by the terminal.
ls just lists the content of the current directory that you are in. If you want to view the content in another directory, you can add the file path in the command:
You can add the -a flag to show hidden files:
or the -l and -h flag to have it display in long-list format and human readable format.
dir, like ls, also lists the contents of the directory in columns. If any names have special characters in them like spaces, then those characters are preceded by a backslash. All the flags developed for ls have also been made available for dir.
dir behaves similar to the following command:
The next command to show content in a directory is vdir.
This command provides a long listing of the contents of the directory. Again, the special characters in names are preceded with a backslash. In the long listing, details about the permissions associated with a file or directory, link count, the owner, group owner, file size, last modification time and file/directory name are displayed.
vdir behaves similarly to the following command:
whereWhy do we have “dir” and “vdir” when “ls” can do the same job?
Shell commands are often used as a part of scripts. The output of such scripts may be displayed on a terminal screen, redirected to a file or simply piped as input to another command. In certain scenarios, ls did not behave as expected due to some performance issues during script execution. To handle this situation, Linux developers came up with two alternate commands that provide the same output as ls and do not run into such performance issues.
Also, some people consider dir to be the Linux equivalent of the DOS command “dir,” which also lists the contents of the directory. However, this is not a correct assumption.Fun Fact
In the output of ls, the files and folders are color-coded. In the outputs for dir and vdir, the same colors are used throughout. If you are wondering why, the reason lies in the .bashrc file. In the “~/.bashrc” file, which is a hidden file in the home directory, an alias for “ls” has been defined as shown below,
When it comes to Linux commands, there is often more than one way to get things done. Don’t forget to check out some of the commonly-used commands for new users.
Divya divides her time between speculating the existence of aliens and writing about her technical findings.
Subscribe to our newsletter!
Our latest tutorials delivered straight to your inbox
Sign up for all newsletters.
You're reading Useful Linux Commands To List Contents Of A Directory
Update the detailed information about Useful Linux Commands To List Contents Of A Directory on the Saigonspaclinic.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!