08. Command Line Operations Flashcards

(123 cards)

1
Q

The command line interface provides the following advantages:

A
  • No GUI overhead is incurred.
  • Virtually any and every task can be accomplished while sitting at the command line.
  • You can implement scripts for often-used (or easy-to-forget) tasks and series of procedures.
  • You can sign into remote machines anywhere on the Internet.
  • You can initiate graphical applications directly from the command line instead of hunting through menus.
  • While graphical tools may vary among Linux distributions, the command line interface does not.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

A _______________ program emulates (simulates) a standalone terminal within a window on the desktop.

A

terminal emulator

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

available terminal programs include:

A
  1. xterm
  2. konsole (default on KDE)
  3. terminator
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

If you do not have the Applications menu, you will have to install the appropriate ____________ package and turn it on with gnome-tweaks.

A

gnome-shell-extension

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

Open terminal

A
  1. Applications > System Tools > Terminal or Applications > Utilities > Terminal.
  2. right-clicking anywhere on the desktop background and selecting Open in Terminal.
  3. Alt-F2 and type gnome-terminal.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

There are some basic command line utilities that are used constantly:

A
  1. cat: used to type out a file (or combine files).
  2. head: used to show the first few lines of a file.
  3. tail: used to show the last few lines of a file.
  4. man: used to view documentation.
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Note the use of the _____________ used to have one program take as input the output of another

A

pipe symbol (|)

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

Most input lines entered at the shell prompt have three basic elements:

A
  1. Command
  2. Options
  3. Arguments
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

The command is the ____________ or script you are executing. It may be followed by one or more options (or switches) that modify what the command may do

A

name of the program

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

(1)______________ usually start with one or two dashes, for example, -p or –print, in order to differentiate them from (2)______________

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

_____________ allows users to run programs using the security privileges of another user, generally root (superuser)

A

sudo

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

Steps for Setting Up and Running sudo:

A

CHECK THE SLIDE (Steps for Setting Up and Running sudo)

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

Why Linux production servers are usually installed without the GUI?

A

maintaining a lean system, which can be easier to support and keep secure.

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

______________ are console sessions that use the entire display and keyboard outside of a graphical environment.

A

Virtual Terminals (VT)

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

Why Virtual Terminals (VT) Such terminals are considered “virtual” ?

A

Such terminals are considered “virtual” because, although there can be multiple active terminals, only one terminal remains visible at a time.

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

VT vs command line Terminal

A

In a command line terminal, you can have many of those visible simultaneously on a graphical desktop.

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

One virtual terminal (usually ____________) is reserved for the graphical environment, and text logins are enabled on the unused VTs.

A

VT 1 or VT 7

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

To switch between VTs, press

A
  • CTRL-ALT-function key for the VT (CTRL-ALT-F6 for VT 6)
  • press the ALT-F6 key combination if you are in a VT and want to switch to another VT
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q

For the newer system-based distributions, the display manager is run as a service, and you can stop the GUI desktop with the ________ utility

A

systemctl

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

Turning Off the Graphical Desktop

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

The preferred method to shut down or reboot the system is to use the _________ command. This sends a warning message, and then prevents further users from logging in

A

shutdown

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

The _________ process will control shutting down or rebooting the system.

A

init

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

The (1)________ and (2)________commands issue shutdown -h to halt the system;

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

_________ issues shutdown -r and causes the machine to reboot instead of just shutting down

A

reboot

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
25
Both rebooting and shutting down from the command line requires ________ access.
superuser (root)
26
When administering a multi-user system, you have the option of notifying all users prior to shutdown, as in:
$ sudo shutdown -h 10:00 "Shutting down for scheduled maintenance
27
In general, executable programs and scripts should live in the (1)__________________________________. They can also appear in (2)________________________, or in a directory in a user's account space, such as (3)______________________.
1. /bin, /usr/bin, /sbin, /usr/sbin directories, or somewhere under /opt 2. /usr/local/bin and /usr/local/sbin 3. /home/student/bin
28
One way to locate programs is to employ the __________ utility.
which $ which diff /usr/bin/diff
29
If which does not find the program, __________ is a good alternative because it looks for packages in a broader range of system directories: . . . as well as locating source and man files packaged with the program.
whereis
30
When you first log into a system or open a terminal, the default directory should be ________________.
your home directory
31
You can see the exact location by typing ________________.
echo $HOME
32
most Linux distributions open new graphical terminals in __________________ instead
$HOME/Desktop
33
Displays the present working directory
ps
34
Change to your home directory; shortcut name is ~ (tilde)
cd ~ or cd
35
Change to parent directory
cd ..
36
Change to previous working directory
cd -
37
An ___________ begins with the root directory (/) and follows the tree, branch by branch, until it reaches the desired directory or file. ____________ always start with /.
absolute pathname
38
A ___________starts from the present working directory. __________never start with /.
relative pathname
39
While ////usr//bin is valid, it is seen as just _________ by the system.
/usr/bin
40
~
your home directory
41
..
parent directory
42
.
present directory
43
For example, suppose you are currently working in your home directory and wish to move to the /usr/bin directory. The following two ways will bring you to the same directory from your home directory: - Absolute pathname method (1)________________________ - Relative pathname method (2)________________________
1. $ cd /usr/bin 2. $ cd ../../usr/bin
44
The __________ command is a good way to get a bird’s-eye view of the filesystem tree.
tree
45
Use ___________ to view just the directories and to suppress listing file names as a tree.
tree -d
46
Changes your current directory to the root (/) directory (or path you supply)
cd /
47
List the contents of the present working directory
ls
48
List all files, including hidden files and directories (those whose name start with .)
ls -a
49
Displays a tree view of the filesystem
tree
50
The ________ utility is used to create hard links and (with the -s option) soft links, also known as symbolic links or symlinks.
ln
51
Suppose that file1 already exists. A hard link, called file2, is created with the command:
$ ln file1 file2
52
Note that two files now appear to exist. However, a closer inspection of the file listing shows that this is not quite true.
$ ls -li file1 file2
53
___________________ are created with the -s option, as in: $ ln -s file1 file3 $ ls -li file1 file3 Notice file3 no longer appears to be a regular file, and it clearly points to file1 and has a different inode number.
Soft (or Symbolic) links
54
For remembering more than just the last directory visited, use __________ to change the directory instead of cd;
pushd
55
Using _______ will then send you back to those directories, walking in reverse order
popd
56
The list of directories is displayed with the _____ command
dirs
57
Used for viewing files that are not very long; it does not provide any scroll-back.
cat
58
Used to look at a file backwards, starting with the last line.
tac
59
Used to view larger files because it is a paging program. It pauses at each screen full of text, provides scroll-back capabilities, and lets you search and navigate within the file.
less
60
Used to print the last 10 lines of a file by default. You can change the number of lines by doing -n 15 or just -15 if you wanted to look at the last 15 lines instead of the default.
tail
61
The opposite of tail; by default, it prints the first 10 lines of a file.
head
62
_______ is often used to set or update the access, change, and modify times of files. By default, it resets a file's timestamp to match the current time.
touch
63
you can also create an empty file using _____
touch
64
the _____ option allows you to set the date and timestamp of the file to a specific value
-t
65
______ is used to create a directory
mkdir
66
Removing a directory is done with ______. The directory must be empty or the command will fail
rmdir
67
To remove a directory and all of its contents you have to do _______
rm -rf
68
Note that ________does double duty, in that it can: Simply rename a file Move a file to another location, while possibly changing its name at the same time.
mv
69
Rename a file
mv
70
Remove a file
rm
71
Forcefully remove a file
rm -f
72
Interactively remove a file
rm -i
73
The _____ variable is the character string that is displayed as the prompt on the command line.
PS1 (student@r9 $)
74
setting the PS1 variable to: \u@\h \$, provides:
$ echo $PS1 \$ $ PS1="\u@\h \$ " student@r9 $ echo $PS1 \u@\h \$ student@r9 $
75
By convention, most systems are set up so that the root user has a pound sign (____) as their prompt.
#
76
When commands are executed, by default there are three standard file streams (or descriptors) always open for use: 1. _________________________ 2. _________________________ 3. _________________________
1. standard input (standard in or stdin), 2. standard output (standard out or stdout) 3. standard error (or stderr).
77
Standard File Streams (keyboard)
standard input
78
Standard File Streams (terminal)
standard output
79
Standard File Streams (log file)
standard error
80
_________ is supplied by directing input to come from a file or from the output of a stdout and stderr commands through a pipe
stdin
81
In Linux, all open files are represented internally by what are called file ______________.
descriptors
82
stdin is file descriptor # ____ stdout is file descriptor # ____ stderr is file descriptor # ____.
1. 0 2. 1 3. 2
83
Typically, if other files are opened in addition to these three (stdin, stdout, stderr), which are opened by default, they will start at file descriptor ______ and increase from there.
3
84
We can redirect the standard in file stream so that we can get input from either a (1)___________ or (2)__________, instead of from our keyboard
1. file 2. another command
85
we can write output and errors to (1)_________ or use them to provide input for (2)__________.
1. files 2. subsequent commands
86
write the command: use the less-than sign (<) followed by the name of the file to be consumed for input data
$ do_something < input-file
87
If you want to send the output to a file, use the greater-than sign (>) as in:
$ do_something > output-file
88
use the less-than sign (<) and greater-than sign (>) at the same command
$ do_something < input-file > output-file
89
If you want to redirect stderr to a separate file, you use command"
$ do_something 2> error-file
90
A special shorthand notation can send anything written to file descriptor 2 (stderr) to the same place as file descriptor 1 (stdout):
2>&1 $ do_something > all-output-file 2>&1 bash permits an easier syntax for the above: $ do_something >& all-output-file
91
allows Linux to combine the actions of several commands into one
pipeline
92
The main tools for Searching for Files are the (1)__________ and (2)__________ utilities.
1. locate 2. find
93
The _________ utility program performs a search while taking advantage of a previously constructed database of files and directories on your system, matching all entries that contain a specified character string.
locate
94
To get a shorter (and possibly more relevant) list using locate, we can use the ______ program as a filter.
grep
95
_____ will print only the lines that contain one or more specified strings
grep
96
locate utilizes a database created by a related utility, _________.
updatedb
97
Most Linux systems run this automatically once a day. However, you can update it at any time by just running _______ from the command line as the root user.
updatedb
98
Wildcard (?)
Matches any single character
99
Wildcard (*)
Matches any string of characters
100
Wildcard ([set])
Matches any character in the set of characters, for example [adf] will match any occurrence of a, d, or f
101
Wildcard ([!set])
Matches any character not in the set of characters
102
For example, if you know only the first two letters are 'ba' of a three-letter filename with an extension of .out, type ___________
ls ba?.out
103
When no arguments are given, find lists all files in the current directory and all of its subdirectories.
find
104
Commonly used options to shorten the list include:
1. -name 2. -iname 3. -type
105
will restrict the results to files of a certain specified type, such as d for directory, l for symbolic link, or f for a regular file
-type
106
find option to ignore the case of file names
-iname
107
find option to list files with a certain pattern in their name
-name
108
Searching for files and directories named gcc:
$ find /usr -name gcc
109
Searching only for directories named gcc:
$ find /usr -type d -name gcc
110
Searching only for regular files named gcc:
$ find /usr -type f -name gcc
111
Good use of find is being able to run commands on the files that match your search criteria. The ______ option is used for this purpose.
-exec
112
To find and remove all files that end with .swp:
$ find -name "*.swp" -exec rm {} ';' Please note that you have to end the command with either ';' (including the single-quotes) or \;. Both forms are fine.
113
The ____________ is a placeholder that will be filled with all the file names that result from the find expression, and the preceding command will be run on each one individually.
{} (squiggly brackets)
114
One can also use the _____ option, which behaves the same as -exec, except that find will prompt you for permission before executing the command.
-ok
115
To find files based on time:
$ find / -ctime 3
116
______ is when the inode metadata (i.e. file ownership, permissions, etc.) last changed; it is often, but not necessarily, when the file was first created
-ctime
117
search for accessed/last read :
(-atime)
118
modified/last written _______ times
(-mtime)
119
The number is the number of days and can be expressed as either a number (n) that means exactly that value, (1)____, which means greater than that number, or (2)_____, which means less than that number. There are similar options for times in minutes (as in (3)___, (4)____ and (5)____).
1. +n 2. -n 3. -cmin, 4. -amin 5. -mmin
120
To find files based on sizes:
$ find / -size 0
121
Note the size here is in 512-byte blocks, by default; you can also specify bytes (c), kilobytes (k), megabytes (M), gigabytes (G), etc. As with the time numbers above, file sizes can also be exact numbers (n), +n or -n. For details, consult the man page for find.
check this URLs 1. https://trainingportal.linuxfoundation.org/learn/course/introduction-to-linux-lfs101/command-line-operations/searching-for-files?page=14 2. https://trainingportal.linuxfoundation.org/learn/course/introduction-to-linux-lfs101/command-line-operations/searching-for-files?page=15
122
to find files greater than 10 MB in size and running a command on those files:
$ find / -size +10M -exec command {} ’;’
123