Linux How-To

15 Interview Questions on Linux “ls” Command – Half 1

The itemizing command in UNIX and UNIX like working System ‘ls‘ is among the most simple and extensively used utility in command-line. It’s POSIX compliant utility out there for GNU coreutils and BSD variants.

The ‘ls’ command can be utilized with a wide range of choices to get desired outcomes. This text goals at deep perception of file itemizing command in Linux with related examples.

ls Command Questionsls Command Questions

15 ls Command Questions

1. How will you Checklist information from a listing?

Ans: The Linux file itemizing command ‘ls‘ involves rescue right here.

# ls

List Files in LinuxList Files in Linux

Checklist Recordsdata

Alternatively, we are able to use ‘echo’ command to record information inside a listing in affiliation with wildcard (*).

# echo *

List All Files in LinuxList All Files in Linux

Checklist All Recordsdata

2. How will you record all of the directories solely utilizing echo command?

# echo */

List All Directories in LinuxList All Directories in Linux

Checklist All Directories

three. How will you record all of the information inside a listing together with hidden information aka (.) dot information?

Ans: We have to use possibility ‘-a‘ (record hidden information) with command ‘ls‘.

# ls -a

List All Hidden Files in LinuxList All Hidden Files in Linux

Checklist All Hidden Recordsdata

four. How do you record all of the information inside a listing together with hidden information, however don’t record implied ‘.’ and ‘..’?

Ans: We have to use possibility ‘-A‘ (don’t record implied . and ..) with command ‘ls‘.

# ls -A

Do Not List ImpliedDo Not List Implied

Do Not Checklist Implied

5. How will you print the content material of a listing in lengthy format itemizing?

Ans: We have to use possibility ‘l‘ (lengthy format) with command ‘ls‘.

# ls -l

List Files LongList Files Long

Checklist Recordsdata Lengthy

Within the above instance, the output looks as if.

drwxr-xr-x 5 avi tecmint 4096 Sep 30 11:31 Binary

Right here, drwxr-xr-x is file permission for proprietor, group and world. Proprietor has Learn(r), Write(w) and Execute(x) permission. The group to which this file belongs has Learn(r) and Execute(x) permission however not Write(w) permission, identical permission implies for the world which have entry to this file.

The Preliminary ‘d‘ means its a Listing.
Quantity ‘5‘ represents Symbolic Hyperlink.
The File Binary belongs to consumer avi and group tecmint.
Sep 30 11:31 represents the date and time it was final modified.

6. You might be purported to print the content material of listing in lengthy format itemizing, exhibiting hidden/dot information. How will you obtain this?

Ans: We have to use possibility ‘-a‘ (record hidden information) and ‘-l‘ (lengthy itemizing) along with command ‘ls‘.

# ls -la

Print Content of DirectoryPrint Content of Directory

Print Content material of Listing

Alternatively We are able to use possibility ‘-A‘ and ‘-l‘ with ‘ls‘ command, if we don’t need to record implied ‘.’ and ‘..’.

# ls -lA

7. How will you determine the creator of every file?

Ans: We have to use possibility ‘–creator‘ together with possibility ‘-l‘ to print the creator identify of every file.

# ls –author -l

List Author FilesList Author Files

Checklist Writer Recordsdata

eight. How will you print escape for non-graphic character?

Ans: We simply want to make use of possibility ‘-b‘ to print escape for non-graphic character.

# ls -b

Print Escape CharacterPrint Escape Character

Print Escape Character

9. Checklist the scale of information and folders in desired scale format. How will you obtain this?

Ans: Right here possibility ‘–block-size=scale‘ together with possibility ‘-l‘ must be used. We have to take away ‘scale’ within the instance with the specified scale viz M, Okay, and so forth.

# ls –block-size=M -l
# ls –block-size=Okay -l

List File Scale FormatList File Scale Format

Checklist File Scale Format

10. Checklist the information inside a listing, however don’t present the backup information, i.e., these information that finish with ~.

Ans: Right here possibility ‘-B‘ (don’t record implied entries ending with ~) involves rescue.

# ls -B

List File Without BackupList File Without Backup

Checklist File With out Backup

11. Kind all of the information inside a listing by identify and present related final modification data.

Ans: We have to use possibility ‘-c‘ and possibility ‘-l‘ with command ls to fulfil the necessity as advised above.

# ls -cl

Sort Files in LinuxSort Files in Linux

Kind Recordsdata

12. Kind all of the information inside a listing by modification time and present related data.

Ans: We have to use three choices collectively i.e., ‘-l‘, ‘-t‘ and ‘-c‘ with command ls to type information by modification time, latest first.

# ls -ltc

Sort Files by ModificationSort Files by Modification

Kind Recordsdata by Modification

13. How will you management the output of ‘ls’ command to be colourful or no-color?

Ans: We have to use possibility ‘–colour=parameter‘. The parameter for use with colour possibility are ‘auto’, ‘all the time’ and ‘by no means’ that are self explanatory.

# ls –color=by no means
# ls –color=auto
# ls –color=all the time

ls Colorful Outputls Colorful Output

ls Colourful Output

14. You might be purported to record listing entries themselves, not their contents. What is going to you do?

Ans: Right here the choice ‘-d‘ comes helpful.

# ls -d

List Directory EntriesList Directory Entries

Checklist Listing Entries

15. Create an alias for lengthy format itemizing “ls -l” as “ll” and output the outcome to a file and never commonplace output.

Ans: Right here within the above situation, we have to add alias to .bashrc file after which use redirect operator to jot down the output to file and never commonplace output. We can be utilizing editor nano.

# ls -a
# nano .bashrc
# ll >> ll.txt
# nano ll.txt

Create Alias for ls commandCreate Alias for ls command

Create Alias for ls command

That’s all for now. Don’t neglect to offer us together with your priceless suggestions within the feedback under. I’ll be right here once more with one other attention-grabbing article quickly. Until then keep tuned and linked.

Actual Additionally:

10 ‘ls’ Command Interview Questions – Half 2
15 Fundamental ‘ls’ Instructions in Linux

Source link

Related Articles

Back to top button