Chapter 06: Command Line operations Flashcards
Linux: How can you switch between virtual terminals?
ctrl-alt-f(x) => x=1…12
Linux: What is a virtual terminal? How is it different from a terminal window in the graphical user interface?
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.
Linux: How can you activate ‘sudo’?
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
Linux: How do you shutdown or reboot the system?
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.
Linux: Where should executable programs be located?
In general, executable programs should live in the /bin, /usr/bin,/sbin,/usr/sbin directories or under /opt.
Linux: How can you locate programs (executables)?
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
Linux: How can you return to the previous directory?
cd -
Linux: How can you find your home directory?
echo $HOME
Linux: How can you display the directory tree structure?
$ tree -d
Linux: What is the inode number of a file? How can you display it?
A unique quantity (number) for each file object.
$ls -i
Linux: What is the difference between soft and hard links?
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.
Linux: Explain the pushd command
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.
Linux: How can you use a file as input to a shell script?
$ command < input_file
Linux: How can you redirect error output to standard out?
2 > &1
Linux: Discuss locate command.
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.