Linux How-To

10 Helpful ‘ls’ Command Interview Questions – Half 2

SEOClerks

Persevering with the legacy of ls command right here is the second interview article on Itemizing command. The primary article of the sequence was extremely appreciated by the Tecmint Group. If you happen to’ve missed the primary a part of this sequence you could like to go to at:

15 Interview Questions on “ls” Command – Half 1

This text is effectively introduced within the method that it offers deep perception of ls command with examples. We’ve got taken further care within the making of article in order that it stays easy to grasp but serve the aim to the fullest.

ls Command Interview Questionsls Command Interview Questions

10 Interview Questions on ls Command

1. You might be purported to record the content material of a listing in lengthy record format, however not print the title of the creator and group the file belongs. Additionally present the distinction in output.

a. ls command itemizing the title of the recordsdata in lengthy itemizing format when used with swap (-l).

# ls -l

List Files in- Long List FormatList Files in- Long List Format

Checklist Recordsdata in- Lengthy Checklist Format

b. ls command itemizing the title of the recordsdata in lengthy itemizing format together with the title of the creator file belongs, when used with swap (–creator) together with swap (-l).

# ls -l –author

List Files By AuthorList Files By Author

Checklist Recordsdata By Creator

c. ls command itemizing the title of the recordsdata with out the title of its proprietor, when used with swap (-g).

# ls -g

List Files Without Printing Owner NameList Files Without Printing Owner Name

Checklist Recordsdata With out Printing Proprietor Identify

d. ls command itemizing the title of recordsdata in lengthy itemizing format with out the title of group it belongs, when used with swap (-G) together with swap (-l).

# ls -Gl

List Files Without Printing GroupList Files Without Printing Group

Checklist Recordsdata With out Printing Group

2. Print the dimensions of recordsdata and folders within the present listing, in human readable format. How will you do that?

Properly we have to use swap -h (human-readable) together with swap (-l) and/or (-s) with the command ls to get the specified output.

# ls -hl

List Files in Human Readable FormatList Files in Human Readable Format

Checklist Recordsdata in Human Readable Format

# ls -hs

List File Sizes in Long List FormatList File Sizes in Long List Format

Checklist File Sizes in Lengthy Checklist Format

Observe: The choice -h makes use of the facility of 1024 (normal in computation) and output the dimensions of recordsdata and folders within the items of Ok, M and G.

three. Properly if swap (-h) output measurement in energy of 1024, that’s normal, What else energy values are supported in ls command?

There exist a swap -si which has similarities to change -h. The one distinction is swap -si makes use of energy of 1000 in contrast to swap -h which makes use of the facility of 1024.

# ls -si

Supported Power Values of ls CommandSupported Power Values of ls Command

Supported Energy Values of ls Command

It can be used with swap -l to output the dimensions of folder within the energy of 1000, in lengthy itemizing format.

# ls -si -l

List Files by Power ValuesList Files by Power Values

Checklist Recordsdata by Energy Values

four. You might be purported to print the contents of a listing separated with comma. Is it potential? Can or not it’s performed in lengthy itemizing format?

Yup! Linux ls command can output the contents of a listing separated by comma when used with the swap (-m). Since this comma separated entries are crammed horizontally, ls command can’t separate contents with comma when itemizing contents vertically.

# ls -m

Print Contents of Directory by CommaPrint Contents of Directory by Comma

Print Contents of Listing by Comma

When utilized in lengthy itemizing format, swap -m will get ineffective.

# ls -ml

Listing Content HorizontallyListing Content Horizontally

Itemizing Content material Horizontally

5. If there any method to print the contents of a listing the other way up? i.e., in reverse order.

Yeah! The above scenario can simply be achieved utilizing the swap -r. The swap ‘-r‘ reverse the order of output. It can be used with swap -l (lengthy itemizing format).

# ls -r

List Content in Reverse OrderList Content in Reverse Order

Checklist Content material in Reverse Order

# ls -rl

Long List Content in Reverse OrderLong List Content in Reverse Order

Lengthy Checklist Content material in Reverse Order

6. You might be given a scenario to print the sub-directories recursively. How will you obtain this case? Thoughts it solely sub directories and no recordsdata.

Okay! That’s fairly straightforward with the swap -R when used with command ls. It could additional be grouped with different choices like -l (lengthy record) and -m (comma separated), and many others.

# ls -R

Print Sub Directories in RecursivelyPrint Sub Directories in Recursively

Print Sub Directories in Recursively

7. Learn how to type the recordsdata primarily based upon the dimensions?

The Linux command line choice -S when used with ls offers the specified output. To type the recordsdata primarily based upon measurement in descending order with the biggest file listed at first and smallest finally.

# ls -S

Sort Files in LinuxSort Files in Linux

Type Recordsdata with ls Command

To type the recordsdata primarily based upon measurement in descending order with the smallest file listed at first and largest finally.

# ls -Sr

Sort Files in Descending OrderSort Files in Descending Order

Type Recordsdata in Descending Order

eight. Checklist the contents of a listing with no further data showing one file per line.

The swap -1 involves rescue right here. ls command with swap -1 output the contents of the listing with one file per line and no further data.

# ls -1

List Files Without InformationList Files Without Information

Checklist Recordsdata With out Data

9. You might be given a scenario through which you need to print the contents of a listing on normal output enclosed by double quotes. How will you do that?

There exist an choice -Q (quote-name) which output the content material of ls enclosed in double quotes.

# ls -Q

Print Files with Double QuotesPrint Files with Double Quotes

Print Recordsdata with Double Quotes

10. You might be working in a listing which incorporates numerous recordsdata and folders. It’s worthwhile to print the title of folders earlier than directories. How will you get this?

# ls –group-directories-first

Print Directories FirstPrint Directories First

Print Directories First

That’s all for now. We might be arising with the subsequent a part of this text sequence about Quirky ‘ls’ Command Tips. Until then keep tuned and related to Tecmint. Don’t forget to offer us with priceless suggestions within the remark part beneath. Like and share us and assist us get unfold!

Source link

Related Articles

Leave a Reply

Back to top button