Unix Flashcards

You may prefer our related Brainscape-certified flashcards:
1
Q

What do the columns in ls -l represent?

A

First Column − Represents the file type and the permission given on the file. Below is the description of all type of files.

Second Column − Represents the number of memory blocks taken by the file or directory.

Third Column − Represents the owner of the file. This is the Unix user who created this file.

Fourth Column − Represents the group of the owner. Every Unix user will have an associated group.

Fifth Column − Represents the file size in bytes.

Sixth Column − Represents the date and the time when this file was created or modified for the last time.

Seventh Column − Represents the file or the directory name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What does every file begin with?

A

In the ls -l listing example, every file line begins with a d, -, or l. These characters indicate the type of the file that’s listed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What does the ‘-‘ mean in ls -l

A

Regular file, such as an ASCII text file, binary executable, or hard link.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What does the ‘d’ mean in ls -l

A

Directory file that contains a listing of other files and directories.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What does the ‘l’ mean in ls -l

A

Symbolic link file. Links on any regular file.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

What does the ‘p’ mean in ls -l

A

Named pipe. A mechanism for interprocess communications.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the ‘s’ mean in ls -l

A

Socket used for interprocess communication.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What does the ‘c’ mean in ls -l

A

Character special file. Raw input/output device file such as a physical hard drive.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What does the ‘b’ mean in ls -l

A

Block special file. Block input/output device file such as a physical hard drive.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What are the two metacharacters?

A

Metacharacters have a special meaning in Unix. For example, * and ? are metacharacters. We use * to match 0 or more characters, a question mark (?) matches with a single character.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What would this produce $ls ch*.doc?

A

ch01-1.doc ch010.doc ch02.doc ch03-2.doc
ch04-1.doc ch040.doc ch05.doc ch06-2.doc
ch01-2.doc ch02-1.doc c

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

How to display the contents of a file?

A

You can use the cat command to see the content of a file. Following is a simple example to see the content of the above created file −

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

How to count words in a file?

A

You can use the wc command to get a count of the total number of lines, words, and characters contained in a file.
$ wc filename
2 19 103 filename

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

What do the 4 columns produced by typing ‘wc filename’ mean?

A

Here is the detail of all the four columns −

First Column − Represents the total number of lines in the file.

Second Column − Represents the total number of words in the file.

Third Column − Represents the total number of bytes in the file. This is the actual size of the file.

Fourth Column − Represents the file name.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

How to rename files?

A

mv old_file new_file

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What are the 3 streams opened when Unix starts up?

A

stdin − This is referred to as the standard input and the associated file descriptor is 0. This is also represented as STDIN. The Unix program will read the default input from STDIN.

stdout − This is referred to as the standard output and the associated file descriptor is 1. This is also represented as STDOUT. The Unix program will write the default output at STDOUT

stderr − This is referred to as the standard error and the associated file descriptor is 2. This is also represented as STDERR. The Unix program will write all the error messages at STDERR.

17
Q

How to create parent directories?

A

$mkdir -p /tmp/amrood/test

18
Q

What are the 3 types of file permissions in Unix?

A

Owner permissions − The owner’s permissions determine what actions the owner of the file can perform on the file.

Group permissions − The group’s permissions determine what actions a user, who is a member of the group that a file belongs to, can perform on the file.

Other (world) permissions − The permissions for others indicate what action all other users can perform on the file.

19
Q

How to use chmod in symbolic mode?

A

chmod o+wx,u-x,g = rx testfile

20
Q

How to use chmod in absolute mode?

A

Number Octal Permission Representation Ref
0 No permission —
1 Execute permission –x
2 Write permission -w-
3 Execute and write permission: 1 (execute) + 2 (write) = 3 -wx
4 Read permission r–
5 Read and execute permission: 4 (read) + 1 (execute) = 5 r-x
6 Read and write permission: 4 (read) + 2 (write) = 6 rw-
7 All permissions: 4 (read) + 2 (write) + 1 (execute) = 7 rwx

chmod 755 testfile

21
Q

how to use chown?

A

The chown command changes the ownership of a file. The basic syntax is as follows −

$ chown user filelist

22
Q

Explain the initialization phase when you log into the system?

A

The process is as follows −

The shell checks to see whether the file /etc/profile exists.

If it exists, the shell reads it. Otherwise, this file is skipped. No error message is displayed.

The shell checks to see whether the file .profile exists in your home directory. Your home directory is the directory that you start out in after you log in.

If it exists, the shell reads it; otherwise, the shell skips it. No error message is displayed.

As soon as both of these files have been read, the shell displays a prompt −

23
Q

What is the grep command?

A

The grep command searches a file or files for lines that have a certain pattern. The syntax is −

$grep pattern file(s)

24
Q

What is -v in various options which you can use along with the grep command?

A

-v

Prints all lines that do not match pattern.

25
Q

What is -n in various options which you can use along with the grep command?

A

-n

Prints the matched line and its line number.

26
Q

What is -l in various options which you can use along with the grep command?

A

-l

Prints only the names of files with matching lines (letter “l”)

27
Q

What is -c in various options which you can use along with the grep command?

A

c

Prints only the count of matching lines.

28
Q

What is -i in various options which you can use along with the grep command?

A

-i

Matches either upper or lowercase.

29
Q

Give an example of the sort command.

A

There are many options that control the sorting −

$ls -l | grep “Aug” | sort +4n

  • rw-rw-r– 1 carol doc 1605 Aug 23 07:35 macros
  • rw-rw-r– 1 john doc 2488 Aug 15 10:51 intro
  • rw-rw-rw- 1 john doc 8515 Aug 6 15:30 ch07
  • rw-rw-rw- 1 john doc 11008 Aug 6 14:10 ch02

This pipe sorts all files in your directory modified in August by the order of size, and prints them on the terminal screen. The sort option +4n skips four fields (fields are separated by blanks) then sorts the lines in numeric order.

30
Q

What does the -n option represent in the sort command?

A

-n

Sorts numerically (example: 10 will sort after 2), ignores blanks and tabs.

31
Q

What does the -r option represent in the sort command?

A

-r

Reverses the order of sort.

32
Q

What does the -f option represent in the sort command?

A

-f

Sorts upper and lowercase together.

33
Q

What does the +x option represent in the sort command?

A

+x

Ignores first x fields when sorting.

34
Q

How to add a background process?

A

The simplest way to start a background process is to add an ampersand (&) at the end of the command.