Linux Command Fundamentals Flashcards

1
Q

What commands help explain the use of specific commands and their syntax?

A

command –help
man command
pinfo

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

What is the difference between su and sudo?

A
  • su is used to open the shell as another user.
  • sudo allows commands to be run in escalated mode.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is the wheel group used for in RHEL?

A

The wheel group is used to assign a user root privlidges.
Users in this group can be seen in the group configuration.

$ cat /etc/group | grep wheel

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

What is su - used for?

A

su - can be used to open a shell as another user

su - without any username will open as root (if enabled).

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

What is sudo used for?

A

sudo allows authorised users to run tasks with escalated privileges.

sudo ls -l /root
The user must be a member of the wheel group

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

What two types of options are often used with commands?

A
  1. Long options; these start with a – (double dash) e.g. –help
  2. Short options; these start with a - (single dash) e.g. ls -l and mkdir -p
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What does the whoami command do?

A

The whoami prints the username associated with the current user.

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

What is the ls command used for?

A

The ls command lists directory contents.

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

What command line utility is used to administer network interfaces?

A

The ip utility is used to administer network interfaces.

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

What text user interace is used to administer network interfaces?

A

nmtui

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

What command is used to show addresses assigned to all network interfaces?

A

ip a (ip address)

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

What is the cat command used for?

A

The cat command is used to print files to the standard output.

Usage: cat /etc/hosts

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

What command line utility is used to list directory contents?

A

ls lists directory contents

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

What command is used to locate the current directory?

A

The pwd is used to print name of current/working directory.

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

What is the pwd command used for?

A

The pwd is used to print name of current/working directory.

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

What command is used to reset a password?

A

The passwd command is used to update a user’s authentication token(s).

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

What is the passwd command used for?

A

The passwd command is used to update a user’s authentication token(s).

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

What is the touch command useful for?

A

The touch command can be used to quickly create a file and to test if a user has permissions to modify a file e.g.
~~~
$ touch /etc/hosts
$ touch: cannot touch ‘/etc/hosts’: Permission denied
~~~

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

What command can be used to quickly verify if a user has permission to modify a file?

A

The touch command can be used to quickly create a file and to test if a user has permissions to modify a file e.g.
~~~
$ touch /etc/hosts
$ touch: cannot touch ‘/etc/hosts’: Permission denied
~~~

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

What commands can be used to view the manual page names and descriptions?

A
  • apropos
  • man -k

Example:
~~~
$ man -k directory
$ adcli (8) - Tool for performing actions
~~~

man -k & apropos both search the mandb based on a keyword

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

What could cause man -k or apropos to return “nothing appropriate”?

A

The database searched by apropos is updated by the mandb program; this is updated periodicallly by a cron job and may require a manul execution on newly installed systems.

To manually update the mandb, execute the command with root privileges.

$ mandb

see man man (-k) or man apropos and man mandb

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

What ls command displays hidden files?

A

The ls -a command does not ignore entries starting with . (dot).

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

What is ls -d option useful for?

A

The ls -d option is used to see the properties of the directory and not its contents.

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

When using the ls utility, what is the -l option used for?

A

The ls -l command returns the results in the long listing format.

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

When using the ls utility, what is the -s option used for?

A

The ls -s (–size) option prints the allocated size of each file, in blocks.

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

What is the ls -lrt command useful for?

A

The ls -lrt shows the last modified file last.
* -l - use a long listing format
* -r (–reverse) - reverse order while sorting
* -t - sort by time, newest first; see –time

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

What two commands can be used to list the contents of all directories in a parent folder?

A

The ls -R and tree commands returns all subfolders and their contents.

ls -R
tree

Example
$ ls -R
.:
Desktop Documents Downloads Music Pictures Public Templates users Videos

./Desktop:

./Documents:

./Downloads:

./Music:

./Pictures:

./Public:

./Templates:

./Videos:

$ tree
.
├── Desktop
├── Documents
├── Downloads
├── Music
├── Pictures
├── Public
├── Templates
├── users
└── Videos

-R, –recursive list subdirectories recursively

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

.

What key combination can be used to access to terminal session when in desktop session?

A

Ctrl + Alt + F3

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

What key combination can be used to access the desktop session when in a terminal session?

A

Ctrl + Alt + F2

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

What command can be used to create a list of active users and their terminals?

A
$ who

```
$ w
~~~

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

What can the chvt command be used for?

A

The command chvt N (terminal number from who) makes the /dev/ttyN the foreground terminal.

This command must be run using escalated privildeges.

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

What is the difference between command options and arguments and parameters?

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

What are the 9 man sections?

A
  1. User command (executable programs or shell commands)
  2. System calls (functions provided by the kernel)
  3. Library calls (functions within program libraries)
  4. Special files (usually found in /dev)
  5. File formats and conventions eg /etc/passwd
  6. Games
  7. Miscellaneous (including macro packages and conventions),
  8. System administration commands (usually only for root)
  9. Kernel routines [Non standard]

The command below can used to read an introduction of a specific section
~~~
$ man N intro
~~~

Sections 1, 5 and 8 are most important for basic administration (RHCSA)

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

How do you search through a man page?

A

using / (forward slash) with a string

use n to skip forward through the search results. shift + n reverse.

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

How do you find a command in a specific section?

A

If the section is known e.g. it is an adminstrator command (8)
~~~
man -k user | grep 8
~~~

If the section is not known, the man -k user command (without grep) will return all references to user and the section.

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

What are the two most common editors?

A

nano & vim (vi improved)

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

What command outputs the results to a file?

A

’>’ (greater than)
~~~
ls > directory
~~~

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

What command appends the results to a text file?

A

’»’ (double greater than)
~~~
ls&raquo_space; directory
~~~

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

What command is used to view recently used commands?

A

history

The history file is found under ~/.bash_history

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

How do you remove a line from the history file?

A
history -d n
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
41
Q

How do you replay a specific command from history?

A
!n

The history command returns all stored commands with a row number.

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

What does the 2> /dev/null command do?

A

The 2> /dev/null is used to redirect/supress errors.
The command broken down:
* 2 refers to a standard error,
* ‘>’ (greater than) is a file redirection operator and
* /dev/null is a null device used to suppress any data written to it.

The 3 file descriptors are:
‘0’ for standard input
‘1’ for standard output
‘2’ for standard error

What exactly does 2>/dev/null do?

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

What is globbing?

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

How do you search for files and folders begining with a specific character?

A
ls -d a*
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
45
Q

How do you search for files and folders with charachters begining a, b or c?

A
ls -d [abc]*
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
46
Q

How do you create a directory path?

A
mkdir -p /tmp/folder1

-p, –parents no error if existing, make parent directories as needed

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

How do you remove a directory?

A
rmdir -p /tmp/folder1
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
48
Q

How do you create a directory path with multiple subfolders?

A
mkdir -p /tmp/{folder1, folder2, folder3}

-p, –parents no error if existing, make parent directories as needed

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

How do you remove a directory path with multiple specific subfolders?

A
rmdir -p /tmp/{folder1, folder2, folder3}
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
50
Q

How do you copy between directories?

A

cp /tmp/currenthome /tmp/newhome/

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

How do you copy files and folders recursively?

A

cp -R

-R, -r, –recursive copy directories recursively

52
Q

How do you copy files into the current directory?

A

cp /tmp/currenthome .

. (dot) is the current directory

53
Q

How do you move files between locations?

A

The mv command moves files between locations.

Usage: mv [OPTION]… [-T] SOURCE DEST
or: mv [OPTION]… SOURCE… DIRECTORY
or: mv [OPTION]… -t DIRECTORY SOURCE…
Rename SOURCE to DEST, or move SOURCE(s) to DIRECTORY.

54
Q

What command is used to delete folders that are not empty?

A

rm -rf /tmp/somefolder

Usage: rm [OPTION]… [FILE]…
Remove (unlink) the FILE(s).

55
Q

Where is the sudo configuration managed?

A

Sudo configuration is manged through /etc/sudoers

56
Q

What is a hard link?

A

A hard link points to the metadata (the file) on the filesystem (inode). Multiple hard links can point to the same file.

A file is only deleted once all hard links refering to an inode have been deleted; there must be at least one hard link to keep a file on the filesystem.

Hard links cannot point to directories and hardlinks must be on the same filesystem.

Hard links are created using the ln -P command; the -P option is not required, as it is the default option when using ln.

see man ln

57
Q

What is a symbolic link?

AKA soft link

A

A symbolic is a reference to a specific name e.g. filename 2 refers to filename (hard link > inode).

If the referenced filename changes, the symbolic link is broken.

A symbolic link is most commonly used for directories e.g.
/bin > /usr/bin

58
Q

What is the best practice when creating symbolic links?

A

Absolute filenames should be used to avoid braking changes.

59
Q

What command is used to create a symbolic link?

A

ln -s /tmp/filename /tmp/symlink

60
Q

What command is used to create a hard link?

A

ln /tmp/filename /tmp/symlink

the option -P is used for physical (hard links); this is option default.

61
Q

What command is used to search for files in a directory hierarchy?

A

The find command can be used to search for files
~~~
$ find / -name “hosts”
~~~

A wildcard * can be used in the name to broaden the search string.

62
Q

How do you copy the results of the find command?

A

By executing cp against the results e.g.
$ find / -name "hosts" -exec cp {} ~/hosts/ 2>/dev/null \;

63
Q

How do you find files of a specific size?

A

By using the find command along with the size option e.g.
~~~
$ find / type -f -size +100M
~~~

Type -f (regular file) and -size + (greater than), M for mebibytes

64
Q

How do you search for a specific value within a file?

A

Using the find and grep commands together can help locate files with specific values/contents e.g.
~~~
$ find /etc -exec grep -l student {} \;
~~~

65
Q

What is the backslash and semicolon combination used for?

A

The backslash () is an escape character that instructs the shell not to interpret the next character.

Multi-Line Code Techniques

66
Q

What are the curley braces used for in the command:
$ find / -name "hosts" -exec cp {} ~/hosts/ 2>/dev/null \;

A

The results of the first command is used in the second command being executed under -exec.

In this example, the files found with the name “hosts” are then copied to a folder under the users directory called hosts.

67
Q

What command displays the environment variables?

A

The env command displays the environment variables.

68
Q

What can the alias command be used for?

A

To simplify repetitve and/or complex command combinations e.g. alias dir=’ls -ltr’

69
Q

Where can you create user specific and startup programs?

A

The .bash_profile can be used to create run bash scripts and create alias e.g. alias dir=’ls -ltr’

70
Q

How do you mount new partitions such as a USB device?

A

First view all mount points to locate the USB drive
~~~
$ lsblk
~~~
Create a directory to mount the device agaist
~~~
$sudo mkdir /mnt/usbdrive
~~~
Mount the drive to the directory
~~~
$ sudo mount /dev/sdb1 /mnt/usbdrive
~~~

71
Q

How do you remove a mount point?

A

$ sudo umount /mnt/usbdrive

72
Q

How do you create an archive file that contains the home and etc directories?

A

Using the tar command you can create a tar ball file
~~~
$ tar -czvf archive.tar /home /etc
~~~

-z filters through gzip for compression

73
Q

How do you display the contents of a tar file?

A

Using the tar -tvf command you can create a tar ball file
~~~
$ tar -tvf archive.tar
~~~

-tvf lists all files in archive.tar verbosely.

74
Q

What utility can be used in scripts to convert text from upper to lower case?

A

The tr (translate) command can convert case
~~~
$ echo hello | tr [:lower:] [:upper:]
$ HELLO
~~~

75
Q

What grep option can be used to filter out results?

A

The grep -v (–invert-match) selects non-matching lines e.g.
~~~
$ ps aux | grep ssh | grep -v grep
~~~
Without the last option, the results would include both the ssh process and the executed command by the user.

man grep

76
Q

What does grep mean?

A

grep stands for
“global / regular expression search / and print”

grep

77
Q

How do you update the sudoers configuration?

A

the /etc/sudoers configuration must be edited using visudo

78
Q

What is the best practice for editing the sudo configuration?

A

It is best practice to create drop-in files under /etc/sudoers.d

79
Q

How do you add users to the wheel group?

A

usermod -aG wheel username

see man usermod.
-a (append), -G (groups)

80
Q

How do you increase the authentication timeout for sudo access?

A

You can increase the authentication token expiration by adding:
Defaults timestamp_type=global,timestamp_timeout=60

81
Q

What is the best practice when deleting users?

what options should be used?

A

The options remove and force should be used to clearly remove the user
~~~
$ userdel -rf username
~~~

82
Q

What 4 commands are used for creating and managing users?

A
  • useradd: create user accounts
  • usermod: modify user accounts
  • userdel: delete user accounts
  • passwd: set passwords
83
Q

Where are user default settings stored?

A

Default user settings should be stored under /etc/login.defs

useradd settings are located under /etc/default/useradd (don’t use this)

84
Q

How do you create files in the user home directory upon creation?

A

Using the /etc/skel directory; files in this directory are created in the users home directory upon creation.

85
Q

What are the options to lock and unlock a user account?

A

usermod -L username will lock the account
usermod -U username will unlock the account

86
Q

What option is used to set an account to expire?

A

usermod -e 2023-12-31 username is used to expire an account e.g. expire username on 31st December 2023.

87
Q

What option is used to prevent accounts from logining into the system?

A

usermod -s /sbin/nologin myapp

man usermod -s (shell)

88
Q

What command shows the status of an account?

A

passwd -S username outputs a short information about the status of the password for a given account.

The status information consists of 7 fields.

  • username
  • status e.g. LK (locked password), NP (no password), PS (useable password)
  • Last password change
  • Minimum age
  • Maximum age
  • Warning period
89
Q

What command is used to temporarily set primary group membership?

A

The newgrp

90
Q

What command is used to add a user to an existing group?

A

The groupmod -U username groupname command adds a user to a group

The usermod -G command replaces the existing groups with a new list.

91
Q

What command is used to list all members of a group?

A

The lid -g groupname lists all members of the group

92
Q

Where are passwords stored?

A

Passwords are stored (encrypted) in the /etc/shadow file.

93
Q

Other than passwd, what other command can be used to change password settings?

A

The chage command can be used to change password expiry information.

94
Q

What command can be used to display user account settings?

Example last password change, password experation date etc.

A

The chage -l username lists account aging information.

95
Q

What command is used to set user ownership?

A

The chown command sets user ownership
~~~
$ chown user[:group] filename
~~~

group can be used optionally with and without the user possition.

96
Q

What command is used to set group ownership?

A

The chgrp command sets group ownership
~~~
$ chgrp groupname filename
~~~

97
Q

WHat command is used to manage filesystem permissions?

A

The chmod command is used to manage permissions.

chmod can be used in absolute or relative mode.

98
Q

What are the three values used for file system permissions?

A
  1. read (4)
  2. write (2)
  3. execute (1)
99
Q

What are the three groups to define permissions?

A

Owner, Group, Others

  1. Owner: rwx = 4+2+1 = 7
  2. Group: r– = 4+0+0 = 4
  3. Others: r– = 4+0+0 = 4
100
Q

What does the first letter of the ls output (permissions) identify?

example: drwxr-xr-x.

A

The first mode field is the “special file” designator:

d (directory)
c (character device)
l (symlink)
p (named pipe)
s (socket)
b (block device)
D (door, not common on Linux systems, but has been ported)

“special file” designator

101
Q

What is the less command used for?

A

The less utility opens a text file in a pager, which allows for easy reading

102
Q

What is the head command used for?

A

The head utility displays the first ten lines of the text file

man head

103
Q

What is the tail command used for?

A

The tail utility displays the last ten lines of the text file

man tail

104
Q

What is the cut command used for?

A

The cut command is used to filter specific columns or characters from a text file

man cut

105
Q

What is the sort command used for?

A

The sort command sorts the contents of a text file

man sort

106
Q

What is the wc command used for?

A

The wc (word count) command counts the number of lines, words, and characters in a text file

man wc

107
Q

What does the grep option -i do?

A

The -i option matches upper- and lowercase letters (i.e., not case sensitive).

108
Q

What does the grep option -v do?

A

The -v
shows only lines that do not contain the regular expression.

109
Q

What does the grep option -r do?

A

The -r searches files in the current directory and all subdirectories.

110
Q

What does the grep option -e do?

A

The -e searches for lines matching more than one regular expression.

Use -e before each regular expression you want to use.

111
Q

What does the grep option -E do?

A

The -E interprets the search pattern as an extended regular expression.

112
Q

What does the grep option -A <number> do?

A

The -A <number> shows <number> of lines after the matching regular expression.</number>

113
Q

What does the grep option -B <number> do?

A

The -B <number> shows <number> of lines before the matching regular expression.</number>

114
Q

ssh

What does the ssh option -v do?

A

The -v (verbose) option shows in detail what is happening while establishing the connection

115
Q

ssh

What does the ssh option -Y do?

A

The -Y (verbose) option enables support for graphical applications

116
Q

ssh

What does the ssh option -p <PORT> do?

A

The -p <PORT> is used to connect to an SSH service that is not listening on the default port 22

117
Q

Elevated Permissions

What is a PolicyKit?

A

A PolicyKit enables you to set up graphical utilities to run with administrative privileges

118
Q

Execute Permissions

What does the Read permission allow on files and directories?

A

The Read permission allows
* Files: view file content
* Directories: list contents of the directory

119
Q

Execute Permissions

What does the Write permission allow on files and directories?

A

The Write permission allows
* Files: change contents of a file
* Directories: create and delete files

120
Q

Execute Permissions

What does the Execute permission allow on files and directories?

A

The Execute permission allows
* Files: run a program file
* Directories: change to the directory

121
Q

What is the numeric representation for read, write and execute?

A
  • Read: 4
  • Write: 2
  • Execute: 1
122
Q

What is the df -Th intended for?

A

The df -Th command was designed to show available disk space on mounted devices; it includes most of the system mounts.

Because it will look on all mounted file systems, it is a convenient command to use to get an overview of current system mounts.

The -h option summarizes the output of the command in a human-readable way, and the -T option shows which file system type is used on the different mounts.

123
Q

What is the findmnt command used for?

A

The findmnt command shows mounts and the relationship that exists between the different mounts.

Because the output of the mount command is a bit overwhelming, you may like the output of findmnt. Notice that because of width limitations of the book page, the output that belongs in the OPTIONS column appears on the left side of the page.

124
Q

What is the awk utility used for?

A

Awk is a utility that enables a programmer to write tiny but effective programs in the form of statements that define text patterns that are to be searched for in each line of a document and the action that is to be taken when a match is found within a line.

awk -F : '/user/ { print $4 }' /etc/passwd

This command searches the /etc/passwd file for the text user and will print the fourth field of any matching line.

125
Q

What is the sed utility used for?

A

sed is a stream editor. A stream editor is used to perform basic text transformations on an input stream (a file or input from a pipeline).

sed -i s/old-text/new-text/g ~/myfile
~~~

```

In this example, the sed utility is used to search for the text old-text in ~/myfile and replace all occurrences with the text new-text.