Unix Flashcards
What do the columns in ls -l represent?
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.
What does every file begin with?
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.
What does the ‘-‘ mean in ls -l
Regular file, such as an ASCII text file, binary executable, or hard link.
What does the ‘d’ mean in ls -l
Directory file that contains a listing of other files and directories.
What does the ‘l’ mean in ls -l
Symbolic link file. Links on any regular file.
What does the ‘p’ mean in ls -l
Named pipe. A mechanism for interprocess communications.
What does the ‘s’ mean in ls -l
Socket used for interprocess communication.
What does the ‘c’ mean in ls -l
Character special file. Raw input/output device file such as a physical hard drive.
What does the ‘b’ mean in ls -l
Block special file. Block input/output device file such as a physical hard drive.
What are the two metacharacters?
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.
What would this produce $ls ch*.doc?
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 to display the contents of a file?
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 to count words in a file?
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
What do the 4 columns produced by typing ‘wc filename’ mean?
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 to rename files?
mv old_file new_file
What are the 3 streams opened when Unix starts up?
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.
How to create parent directories?
$mkdir -p /tmp/amrood/test
What are the 3 types of file permissions in Unix?
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.
How to use chmod in symbolic mode?
chmod o+wx,u-x,g = rx testfile
How to use chmod in absolute mode?
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
how to use chown?
The chown command changes the ownership of a file. The basic syntax is as follows −
$ chown user filelist
Explain the initialization phase when you log into the system?
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 −
What is the grep command?
The grep command searches a file or files for lines that have a certain pattern. The syntax is −
$grep pattern file(s)
What is -v in various options which you can use along with the grep command?
-v
Prints all lines that do not match pattern.
What is -n in various options which you can use along with the grep command?
-n
Prints the matched line and its line number.
What is -l in various options which you can use along with the grep command?
-l
Prints only the names of files with matching lines (letter “l”)
What is -c in various options which you can use along with the grep command?
c
Prints only the count of matching lines.
What is -i in various options which you can use along with the grep command?
-i
Matches either upper or lowercase.
Give an example of the sort command.
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.
What does the -n option represent in the sort command?
-n
Sorts numerically (example: 10 will sort after 2), ignores blanks and tabs.
What does the -r option represent in the sort command?
-r
Reverses the order of sort.
What does the -f option represent in the sort command?
-f
Sorts upper and lowercase together.
What does the +x option represent in the sort command?
+x
Ignores first x fields when sorting.
How to add a background process?
The simplest way to start a background process is to add an ampersand (&) at the end of the command.