Chapter 06: Command Line operations Flashcards

1
Q

Linux: How can you switch between virtual terminals?

A

ctrl-alt-f(x) => x=1…12

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

Linux: What is a virtual terminal? How is it different from a terminal window in the graphical user interface?

A

Virtual Terminals (VT) are console sessions that use the entire display and keyboard outside of a graphical environment. Such terminals are considered “virtual” because although there can be multiple active terminals, only one terminal remains visible at a time. A VT is not quite the same as a command line terminal window; you can have many of those visible at once on a graphical desktop.

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

Linux: How can you activate ‘sudo’?

A

1) su to root user.
2) Now you need to create a configuration file to enable your user account to use sudo. Typically, this file is created in the /etc/sudoers.d/ directory with the name of the file the same as your username. For example, for this demo, let’s say your username is “student”. After doing step 1, you would then create the configuration file for “student” by doing this: # echo “student ALL=(ALL) ALL” > /etc/sudoers.d/student
3) Finally, some Linux distributions will complain if you don’t also change permissions on the file by doing: # chmod 440 /etc/sudoers.d/student

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

Linux: How do you shutdown or reboot the system?

A

The preferred method to shut down or reboot the system is to use the shutdown command. This sends a warning message and then prevents further users from logging in. The init process will then control shutting down or rebooting the system. It is important to always shut down properly; failure to do so can result in damage to the system and/or loss of data.

The halt and poweroff commands issue shutdown -h to halt the system; reboot issues shutdown -r and causes the machine to reboot instead of just shutting down. Both rebooting and shutting down from the command line requires superuser (root) access.

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

Linux: Where should executable programs be located?

A

In general, executable programs should live in the /bin, /usr/bin,/sbin,/usr/sbin directories or under /opt.

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

Linux: How can you locate programs (executables)?

A

One way to locate programs is to employ the which utility. For example, to find out exactly where the diff program resides on the filesystem:

$ which diff

If which does not find the program, whereis is a good alternative because it looks for packages in a broader range of system directories:

$ whereis diff

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

Linux: How can you return to the previous directory?

A

cd -

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

Linux: How can you find your home directory?

A

echo $HOME

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

Linux: How can you display the directory tree structure?

A

$ tree -d

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

Linux: What is the inode number of a file? How can you display it?

A

A unique quantity (number) for each file object.

$ls -i

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

Linux: What is the difference between soft and hard links?

A

Symbolic links take no extra space on the filesystem (unless their names are very long). They are extremely convenient as they can easily be modified to point to different places. An easy way to create a shortcut from your home directory to long pathnames is to create a symbolic link.

Unlike hard links, soft links can point to objects even on different filesystems (or partitions) which may or may not be currently available or even exist. In the case where the link does not point to a currently available or existing object, you obtain a dangling link.

Hard links are very useful and they save space, but you have to be careful with their use, sometimes in subtle ways. For one thing if you remove either file1 or file2 in the example on the previous screen, the inode object (and the remaining file name) will remain, which might be undesirable as it may lead to subtle errors later if you recreate a file of that name.

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

Linux: Explain the pushd command

A

For remembering more than just the last directory visited, use pushd to change the directory instead of cd; this pushes your starting directory onto a list. Using popd will then send you back to those directories, walking in reverse order (the most recent directory will be the first one retrieved with popd). The list of directories is displayed with the dirs command.

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

Linux: How can you use a file as input to a shell script?

A

$ command < input_file

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

Linux: How can you redirect error output to standard out?

A

2 > &1

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

Linux: Discuss locate command.

A

Search for files.
Locate utilizes the database created by another program, updatedb. Most Linux systems run this automatically once a day. However, you can update it at any time by just running updatedb from the command line as the root user.

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

Linux: Discuss find command.

A

find is extremely useful and often-used utility program in the daily life of a Linux system administrator. It recurses down the filesystem tree from any particular directory (or set of directories) and locates files that match specified conditions. The default pathname is always the present working directory.

17
Q

Linux: Give a command to delete all files ending with .swp

A

$ find -name “.swp” -exec rm {} ’;’
or
$ find -name “
.swp” -ok rm {} ’;’
=> will ask for permission

18
Q

Linux: Which bash wildcard is used to match any single character?

A

?

19
Q

Linux: What is the tac command?

A

Used to look at a file backwards, one line at a time.

20
Q

Linux: What is the less command?

A

Used to view larger files because it is a paging program; it pauses at each screenful of text, provides scroll-back capabilities, and lets you search and navigate within the file. Note: Use / to search for a pattern in the forward direction and ? for a pattern in the backward direction.

21
Q

Linux: How can you change the command line prompt?

A

Modify the PS1 variable.

e.g. PS1=”\u@\h $ “

22
Q

Linux: What are the two levels of package managers?

A

Both package management systems provide two tool levels: a low-level tool (such as dpkg or rpm), takes care of the details of unpacking individual packages, running scripts, getting the software installed correctly, while a high-level tool (such as apt-get, yum, or zypper) works with groups of packages, downloads packages from the vendor, and figures out dependencies.