Of course, the distributions of the operating system on the Linux kernel often has a built-in GUI and file Manager, enabling you to work with directories as separate objects. However, it is sometimes necessary to know the contents of a folder via the built-in console. In this case, the aid comes standard command ls.
Use the ls command in Linux
Team ls, like most of the other OS based on the Linux kernel, properly functioning with all of the assemblies and have their own syntax. If the user will be able to deal with the correctness of the assignment of arguments and common input algorithm, it can without any problems as quickly as possible to learn the necessary information about the files contained in folders.
Determining the location of a specific folder
First, be sure to understand the process of transition to the necessary location via the Terminal. If you’ll be scanning multiple folders in a single directory, it is easier to do it from from the right place, to avoid the need to type the full path to the object. Define the place and the transition is this:
cd /home/user/folderto navigate to the desired location. User in this case, the user name and folder — name of the destination folder.
You can now safely move to the use of the today command ls with the use of different arguments and options. We suggest to familiarize with the basic examples in more detail next.
Viewing the contents of the current folder
Writing in console
ls without any additional options, you will receive information about the current location. If running the console was not implemented there are no transitions through the
cd, you will see a list of files and folders in your home directory.
Folder marked in blue, and other elements of white. Everything is displayed in one or more rows, depending on the number of located objects. You can see the results and go on.
Displaying directories located in the specified location
In the beginning of the article talked about how to move to the desired path in the console, with just one team. While in the current location, type
ls folder, where folder is the folder to view its contents. Utility properly displays non-Latin characters, but also Cyrillic, taking into account the register, which sometimes is very important.
Please note that if you have not already moved to the location of the folder you should specify the path to it, in order to allow the tool to detect the object. Then the input string takes the form of, for example,
ls /home/user/folder/photo. For such a rule entry and subsequent examples using arguments and functions.
The definition of the Creator of the folder
The syntax of the command ls is constructed in the same way as most other standard utilities, so even a novice user will not find anything new or unfamiliar. Consider the first sample, if necessary the view of the author folders and the modification dates. To do so, enter
ls-l --author folder, where folder is the name of the directory or full path to it. After activation you will see the desired information.
Listing hidden files
In Linux there is a sufficiently large number of hidden elements, especially when it comes to system files. Display them together with all the rest of the contents of a directory by applying a certain option. Then the team looks like this:
ls-a + a name or the folder path.
Found objects will be displayed with links to the place of storage, if you are not interested in this information, just change the register argument, writing in this case
Separately want to note the sorting of the content, because often it is very useful and helps the user literally seconds to find the desired data. There are several options to meet various filtration. First note
ls-lSh folder. This argument displays the file list in descending order of their volume.
If you are interested in displaying in reverse order, will have to add only one letter in the argument to get the
Display the results in alphabetical order is done using
ls-lX + the name or path to directory.
Sorting by last modified time —
ls-lt + the name or path to directory.
Of course, there are a number of options which are used less frequently but can still be useful to certain users. These include:
-Bnot present present backup;
-— Display the results in the form of columns, not rows;
-d— show only folders within the directories without their contents;
-F— display the size or type of each file;
-m— the separation of all elements separated by commas;
-Q— to take the name of the objects in quotation marks.
-1— display one file per line.
Now that you have found the required files in the directories, you might need to edit them or find the necessary parameters in the configuration object. In this case, come to the aid of another built-in command called grep. To find it, you can in our other article on the following link.
Read more: Examples of grep command in Linux
Moreover, on Linux there is still a large list of useful console tools and standard tools that are often useful even for the most inexperienced user. Read detailed information on this topic later.
Our article is completed. As you can see, nothing complicated about the command ls and its syntax, no, the only thing you have to do is follow the rules of entering, to avoid mistakes in the names of directories and account ledgers option.