UNIX Exam 1 questions

0.0(0)
studied byStudied by 0 people
learnLearn
examPractice Test
spaced repetitionSpaced Repetition
heart puzzleMatch
flashcardsFlashcards
Card Sorting

1/78

flashcard set

Earn XP

Description and Tags

Study Analytics
Name
Mastery
Learn
Test
Matching
Spaced

No study sessions yet.

79 Terms

1
New cards

What do we call the type of path name that begins with a slash?

absolute pathname

2
New cards

Does a relative pathname start from the current working directory (wd)?

YES, it does start from current wd (no slash to start it)

3
New cards

What if you enter a cd command with no arguments?

It takes you to the home directory

4
New cards

What's the organizational arrangement of the directories of files of the UNIX system?

hierarchy

5
New cards

When you login and the prompt comes up, what is the directory called that you are in?

Home

6
New cards

What does cd.. do?

Moves you to the parent directory

7
New cards

What does cd. do?

Keeps you in the current directory

8
New cards

SAMPLE QUESTION:

Given the following directory structure:

/home/user

│── a

│ ├── b

│ │ ├── c

│ │ ├── d

│ ├── e

Starting from /home/user, what will be displayed by the pwd command after executing the following commands?

-cd a

-cd b

-cd d

-pwd

/home/user/a/b/d

9
New cards

SAMPLE QUESTION:

Given the following directory structure:

/home/user

│── a

│ ├── b

│ │ ├── c

│ │ │ ├── d

│ │ │ │ ├── e

│ │ │ │ │ ├── f (Current Directory)

Starting from /home/user/a/b/c/d/e/f, what will be the current working directory after executing the following command?

-cd ../../../../b

-pwd

/home/user/a/b

10
New cards

Identify a command that provides additional helpful information

-help (for built-in commands)

-man (for manual pages)

11
New cards

SAMPLE QUESTION:

Which of the following commands can provide additional information or explanations about other commands?

A) ls

B) cd

C) man

D) pwd

C) man

12
New cards

Hidden files in a directory start with what character?

.

13
New cards

What's the command when you do an echo with a dollar sign ($) that causes the shell you are running to display its name?

echo $0

14
New cards

What command uses man and cp utility and sends the output to a pipeline to less?

man cp | less

--> man cp : Displays the manual (help) page for the cp (copy) command.

--> | : The pipe symbol takes the output of the man cp command and sends it as input to the next command.

--> less : Displays the content of the man cp output one screen at a time, allowing you to scroll through it.

15
New cards

If I have a variable 'total' that I have defined in the shell as equal to 10, which of the following commands will display the value of total?

echo $total

16
New cards

If you type echo $PATH in the bash shell command line, what does the display?

displays the current value of the PATH environment variable

17
New cards

If I have a command 'ls -l myfile', what list of permissions associated with the file 'myfile'?

SAMPLE OUTPUT:

-rw-r--r-- 1 user group 1024 Feb 24 12:34 myfile

command displays files permissions, owner, group, size, and modification date

SAMPLE OUTPUT ANALYSIS:

owner = read and write

group = read

others = read

18
New cards

If your search path does not include the path to a particular program and you try to run that program by typing its name on the command line, what happens?

You will get an error message, "command not found"

19
New cards

In a bash shell script, you can access the process id (PID of the script) with the which environment variable?

echo $$

20
New cards

What's the command that changes permissions information associated with the file?

chmod

21
New cards

This command changes your current directory to the home directory location.

cd ~

22
New cards

This command copies a file, preserving the original and creating an identical copy.

cp

23
New cards

This command displays the classification of a file (also known as the file type).

file

24
New cards

This command displays the text files one screen at a time (or holds it one screen at a time).

less

25
New cards

This command is most commonly used to list all the files that have a certain name in the tree structure below the specified directory.

find

26
New cards

Choose the correct command that makes a link named 'myfilelink' to a file named 'myfile'.

ln myfile myfilelink --> hard link

ln -s myfile myfilelink --> symbolic link

27
New cards

What's the acronym for the command that displays the contents of a text file?

cat

28
New cards

What's the acronym name of the command that searches for a pattern in files?

grep

29
New cards

What command lists the files and subdirectories in a directory?

ls

30
New cards

What's the command for creating a new subdirectory in your current directory?

mkdir

31
New cards

What's the command that will rename or move a file?

mv

32
New cards

What's the command that displays information about users that have logged in?

who

33
New cards

Given the command 'rm mydir', does this command remove the non empty directory 'mydir'?

FALSE

--> 'rm -r directoryname' will remove non empty directories

--> 'rm directoryname' will remove ONLY empty directories

34
New cards

What command removes files?

rm

35
New cards

The following command 'touch myfile' will create the file 'myfile' if it does not exist?

TRUE, the command will create the new file

36
New cards

In the bash shell, the values of all command line arguments (args) are passed to a shell script int eh following shell variable. What is this variable?

$*

37
New cards

In the bash shell, the following command creates the user-defined shell variable called 'name' and initializes it to "johndoe".. Which statement does this?

name="johndoe"

38
New cards

Given the following command 'echo who | more', what does this command do?

Will only display 'who' (no more pages)

--> echo who : This command outputs the string who. It's not executing the who command, but just printing the word who.

--> | (pipe) : The pipe sends the output of the echo who command as input to the next command (more).

--> more : This command displays the input one screen at a time. Since the output from echo who is just a simple string (who), more will display it and immediately exit because the output is only one line.

39
New cards

In the bash shell, you can use the following command to read a line from standard in into a variable, which we are going to call 'word'. What command in the bash shell reads in to a variable from the keyboard?

read word

40
New cards

On the bash shell, the environment variable 'home' contains the absolute path of what directory?

HOME directory

41
New cards

If I do a find command with the -name option, what does it do?

-find /path/to/search -name "file.txt"

finds files by their name, or in other words, allows you to search for files and directories that match a specific name or pattern.

42
New cards

What command line lists all your hidden files in the current directory?

ls .* --> Lists only files and directories that start with a dot (.), including hidden files and special entries (current directory and parent directory)

--> NOTE: ls -a also works but lists ALL files and directories, including hidden ones

43
New cards

A meta character matches 0 or more characters. What is this meta character?

*

44
New cards

What is the meta character symbol on UNIX that matches to 1 character?

?

45
New cards

What's the shell character or symbol that creates a pipe between commands?

pipe symbol --> |

46
New cards

When vim is in edit mode, what keystroke do you enter in order to go to native mode?

escape (esc)

47
New cards

When vim is in native mode, what keystroke do you enter to be able to use the editor?

i

48
New cards

When vim starts up from the shell command, what mode is the editor in?

native mode

49
New cards

In vim native mode, what keystroke do you enter to go into command mode?

:

50
New cards

In vim native mode, the following command writes out the file contents and quits the editor. Which command is this?

:wq! --> Forces the file to be written and then quits Vim. (used when the file is read-only or you don't have write permissions for the file. It forces the save and exit even if Vim warns you that you don't have permission to write the file)

:wq --> Saves the file and quits Vim. (works when you have permission to write the file or if the file is not read-only)

51
New cards

When in vim native mode, the following command deletes the line the cursor is located on. Which command is this?

:dd

52
New cards

The command vim can only open on files that already exist. True or false?

FALSE, vim will create a new file if trying to open an non-existing file

53
New cards

Which of the following displays directories and hidden files?

ls -a

54
New cards

Given the results of an 'ls -l' command on a file, identify the permissions:

- If the first character is a dash '-', what does that first character in the permissions indicate?

the first character indicates file

55
New cards

Given the results of an 'ls -l' command on a file, identify the permissions:

- If the first character is a 'd', what does that first character in the permissions indicate?

the first character indicates directory

56
New cards

SAMPLE QUESTION:

Given the results of an 'ls -l' command on a particular file, identify the permissions that the owner has. Output shown after file is '-rwxr-xr-- 1 user group 1024 Feb 24 12:34 myfile'.

The owner does read, write, and execute permissions

--> First character: File type (- for regular file, d for directory, l for symbolic link)

--> Next three: Owner's permissions (r = read, w = write, x = execute)

--> Middle three: Group's permissions

--> Last three: Others' permissions

57
New cards

SAMPLE QUESTION:

Given the results of an 'ls -l' command on a particular file, identify the group from the file. Output shown after file is '-rwxr-xr-- 1 user1 developers 1024 Feb 18 12:34 myfile'

The group is developers

--> File type: - (Regular file)

--> Owner's permissions: rwx (Read, Write, Execute)

--> Group's permissions: r-x (Read, Execute)

--> Others' permissions: r-- (Read-only)

--> Links: 1 (One hard link)

--> Owner: user1 (The owner of the file)

--> Group: developers (This is the group that the file belongs to)

--> Size: 1024 bytes (File size in bytes)

--> Date: Feb 18 12:34 (Last modification date)

--> File name: myfile (The name of the file)

58
New cards

SAMPLE QUESTION:

Given the 'ls -l' command on a file and the chmod command, what results when the following chmod command is run on the file?

--> Output shown after file is '-rw-r--r-- 1 user1 developers 2048 Feb 18 12:34 myfile'

--> the following command is 'chmod u+x,g-w,o-r myfile'

The updated permissions are '-rwxr----- 1 user1 developers 2048 Feb 18 12:34 myfile'

--> u+x: Add execute (x) permission for the user (owner).

--> g-w: Remove write (w) permission for the group.

--> o-r: Remove read (r) permission for others

--> Owner: rwx (Now has read, write, and execute permissions)

--> Group: r-- (Read-only, write permission removed)

--> Others: --- (Read permission removed)

59
New cards

A user can only use 'ls -l' to see permissions on the files they own. True or false?

FALSE, user can use the command to see the permissions on all files in the directory

60
New cards

The root can modfiy permissions on any directory or file. True or false?

TRUE, root user has unrestricted access

61
New cards

The command 'rmdir' removes or deletes a directory and its files. True or false?

FALSE, rmdir can only remove empty directories

62
New cards

Touching the file that already exists resets the permissions to the default permissions. True or false?

FALSE, only updates the file's access time and modification time without changing its content or permissions

63
New cards

On a command line, each sequence of nonblank characters is called a token or word. True or false?

TRUE, tokens (sequence of nonblank characters) can be commands, options, or arguments

64
New cards

What character symbol do options start with on commands?

-

65
New cards

Pwd is a command that has 0 arguments. True or false?

TRUE, just write pwd

66
New cards

Echo is an example of a builtin command. True or false?

TRUE, echo is implemented directly in the shell itself

67
New cards

the following command 'ls -l lsout' redirects the output of the 'ls -l' command to a file named 'lsout'. True or false?

FALSE, only lists the details of a file called 'lsout'

--> NOTE: to redirect output to a file, use the command 'ls -l > lsout'

68
New cards

What's the comment line that you stick at the first/front of a script file that causes the script to be run by the bash shell?

#!/bin/bash

69
New cards

If you want to run a script in your current working directory, do you have to put './' before the script name?

TRUE, for example, you can run a script called myscript.sh by writing './myscript.sh'

70
New cards

If I have a function that I defined in the shell, how do I run the function?

Run by simply typing the function's name. For example, you can run a function called 'greet' by just typing 'greet' in the command line (also followed by any necessary arguments)

71
New cards

Given the alias command 'alias l='ls -l'' this command sets 'l' as an alias for 'ls -l'. True or false?

TRUE, new the 'ls -l' can be run using 'l' in the bash shell

72
New cards

We cat a file and it produces 'Sunday/Monday/Tuesday/Wednesday/Thursday/Friday/Saturday' and then we give the command 'grep myfile myfile t'. Does this command produce the results 'Tuesday/Thursday'?

FALSE, the correct structure for grep is 'grep "pattern" file name', so the correct command would be 'grep T myfile'

73
New cards

Variables, functions, and aliases the are set up in your .bashrc file will exist at login start up. True or false?

TRUE, but they MUST be set up in .bashrc or less they will not appear

74
New cards

If I have a command in the shell of 'echo $HOME', does that display the home directory for the current user? True or false?

TRUE, because $HOME holds the home directory path in its variable

75
New cards

Symbolic links can only link to files. True or false?

FALSE, can point to both files and directories

76
New cards

Only the owner of a file can change a file's permissions with the chmod command. True or false?

FALSE, the root user can change permissions on ANY file

77
New cards

What is a user that can change any file or any directory's permission?

Root user

78
New cards

All variables that you define and use in a script file are global by default. True or false?

FALSE, variables in a script are local unless explicitly exported

79
New cards

Functions created and defined in a current bash shell session will still exist in the next sessions log on after you log off. True or false?

FALSE, functions exist only in the current session unless defined in .bashrc