This set of Unix Multiple Choice Questions & Answers (MCQs) focuses on “Listing Directory Contents: Is Command”.
1. Which command is used for listing files in a directory?
a) ps
b) list
c) ls
d) wc
View Answer
Explanation: ls command is one of the most powerful commands used in UNIX system. It comes available with a bunch of options for listing files available in the directory. There are a number of options like -l, -a which are used for listing files in different manners according to user’s need.
$ ls 001.sh FILE2 abc.txt dir08
2. Which option is used with ls command for long listing of files with seven attributes?
a) -a
b) -l
c) -x
d) -i
View Answer
Explanation: -l is used with ls command for long listing of files in ASCII collating sequence. The attributes displayed are:
-> File type and permissions
-> Links
-> Ownership
-> Group ownership
-> File size
-> Last modification time
-> Filename
$ ls -l drwxr-xr-x 5 abd users 4096 Aug 12 08:30 go drwx------ 3 mash users 4096 Nov 28 10:49 irc drwxr-xr-x 2 ryan users 32768 July 25 09:15 logs drwxr-xr-x 8 anki users 4096 Oct 2 17:13 src
3. Which option is used with ls to display attributes of the directory ?
a) -a
b) -ld
c) -d
d) -o
View Answer
Explanation: ls command when used with directory name as an argument, lists all the files in the directory. To force ls to list the attributes of the directory we use the -ld option.
$ ls -ld drwxr-xr-x 5 george users 4096 Sep 25 08:30 go drwx------ 3 george users 4096 Sep 27 10:49 irc drwxr-xr-x 2 george users 32768 Oct 4 09:15 logs drwxr-xr-x 8 george users 4096 Oct 2 17:13 src
4. -a option is used with ls command for what purpose?
a) for showing hidden files
b) for showing executables
c) for showing directories
d) for multi columnar output
View Answer
Explanation: -a option when used with ls command displays all the files including hidden files. Files beginning with a ( . ) are listed using -a option. There are certain files (filenames beginning with a . ) These files are not listed without -a option.
$ ls -ax ./ . ./ calendar .file .rhost abc_001
5. Which option is used with ls command to produce multi columnar output?
a) -x
b) -F
c) -a
d) -v
View Answer
Explanation: If there are multiple files present in a directory for listing, it is better that we display these files in multiple columns. For this purpose -x is used. For example,
$ ls -x File1 file2 abc.txt Dir08 res.c txt05 Dep.lst emp.sh udisk
6. What is the collating sequence of ls command for listing files?
a) Numerals > Uppercase > Lowercase
b) Numerals > Lowercase > Uppercase
c) Lowercase > Uppercase > Numerals
d) Uppercase > Numerals > Lowercase
View Answer
Explanation: The output of ls commad is arranged in ASCII collating sequence which is, filenames starting with Numerals first, then Uppercase, then lowercase.
$ ls 001_dir //numeral first 09_abc ABD.txt //uppercase prog.sh //lowercase
7. How can we identify executables and directories from the output of ls command?
a) using -F option
b) using -x option
c) using -a option
d) using -i option
View Answer
Explanation: The output of the ls command simply displays filenames without indicating the file type. For identifying the file type we use -F option. The output of ls -F displays filenames with two symbols * and /, which are type indicators. The filenames containing * are executables while those containing / are directories.
$ ls -Fx 008abc.txt TOX.sh* calendar* Dept.lst helpdir/ progs/
8. $ ls -R outputs all files and subdirectories in a recursive manner.
a) True
b) False
View Answer
Explanation: The above command traverses the directory tree in a recursive manner until no subdirectories are left. In simple words, we can say that it produces a recursive listing of files.
9. -r option is same as -R option in ls command.
a) True
b) False
View Answer
Explanation: Both -r and -R are different options and performs different tasks. -r is used to sort the filenames in reverse order while sorting while -R is used for recursive listing of files.
10. What does the -S option do in ls command?
a) sorts according to modification time
b) sorts according to last access time
c) sorts according to file size
d) sorts according to inode number
View Answer
Explanation: ls -S sorts the filenames according to the file size with largest size first.
drwxr-xr-x 5 abd users 78988 Aug 12 08:30 go drwx------ 3 mash users 56899 Nov 28 10:49 irc drwxr-xr-x 2 ryan users 32768 July 25 09:15 logs drwxr-xr-x 8 anki users 4096 Oct 2 17:13 src
11. ls -s prints the allocated file size in blocks.
a) True
b) False
View Answer
Explanation: Files are stored onto the disk in terms of block size. The block size allocated to the file can be displayed using -s option with ls command.
12. -u option sorts the files according to ____
a) last modification time
b) last access time
c) ASCII collating sequence
d) file size
View Answer
Explanation: ls -u displays the filenames based on the value of the last access time of the file i.e. it sorts all the filenames according to their last access time.
13. -t option sorts the files according to ____
a) last modification time
b) last access time
c) ASCII collating sequence
d) file size
View Answer
Explanation: ls -t displays the filenames based on the value of the last modification time of the file i.e. it sorts all the filenames in accordance with their last modification time.
14. The output of ls dir* is ___
a) all files in the current directory
b) all files in the directory having a filename starting with dir
c) no filename is displayed
d) erroneous
View Answer
Explanation: The above command displays those files in the directory, the names of which will be starting with a prefix ‘dir’. Here * is a meta-character which is used for pattern matching.
$ ls dir* dir01 dir02 dir00.txt
Sanfoundry Global Education & Learning Series – Unix.
To practice all areas of Unix, here is complete set of 1000+ Multiple Choice Questions and Answers.
- Get Free Certificate of Merit in Unix
- Participate in Unix Certification Contest
- Become a Top Ranker in Unix
- Take Unix Tests
- Chapterwise Practice Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Chapterwise Mock Tests: Chapter 1, 2, 3, 4, 5, 6, 7, 8, 9, 10
- Buy MCA Books
- Apply for Computer Science Internship
- Buy Computer Science Books
- Apply for Unix Internship
- Buy Unix Books