Here, I describe basic tips to configure and manage systems, mostly from the console.

In a screen session, all keyboard inputs are sent to your current window except for the command keystroke. All screen command keystrokes are entered by typing ^A ("Control-A") plus a single key [plus any parameters]. Here are important ones to remember.

You can save connection fees with screen for metered network connections such as dial-up and packet ones, because you can leave a process active while disconnected, and then re-attach it later when you connect again.

screen magically reattaches all previous screen windows with all actively running programs.

You log in again to the same remote machine (even from a different terminal).

Type ^A DD ("Control-A" followed by "DD") to have screen detach and log you out

Type ^A d ("Control-A" followed by "d") and manually logging out from the remote connection

You may detach the screen session by any methods.

Suddenly you need to leave your terminal, but you don't want to lose your active work by keeping the connection.

You switch among the multiple screen windows by ^A n ("Control-A" followed by "n").

You execute multiple programs in screen windows created with ^A c ("Control-A" followed by "c").

screen(1) not only allows one terminal window to work with multiple processes, but also allows remote shell process to survive interrupted connections . Here is a typical use scenario of screen(1).

screen(1) is a very useful tool for people to access remote sites via unreliable or intermittent connections since it supports interrupted network connections.

You can browse the change history of " /etc " by executing " sudo GIT_DIR=/etc/.git gitk " with clear view for new installed packages, removed packages, and version changes of packages.

As you change your configuration, you can use git(1) normally to record them. It automatically records changes nicely every time you run package management commands, too.

Essentially, running " sudo etckeeper init " initializes the git repository for " /etc " just like the process explained in Section 10.6.5, “Git for recording configuration history” but with special hook scripts for more thorough setups.

I recommend to use the etckeeper package with git(1) which put entire " /etc " under VCS control. Its installation guide and tutorial are found in " /usr/share/doc/etckeeper/README.gz ".

Table 9.6. List of packages to record configuration history in VCS

There are specialized tools to record changes in configuration files with help of DVCS system.

There are few ways to record the graphic image of an X application, including an xterm display.

For Emacs , as follows.

For Vim , as follows.

You can record the editor activities for complex repeats.

You can turn off these colorizing aliases in the interactive environment by invoking shell with " TERM=dumb bash ".

The use of alias limits color effects to the interactive command usage. It has advantage over exporting environment variable " export GREP_OPTIONS='--color=auto' " since color can be seen under pager programs such as less(1). If you wish to suppress color when piping to other programs, use " --color=auto " instead in the above example for " ~/.bashrc ".

Colorized commands are handy for inspecting their output in the interactive environment. I include the following in my " ~/.bashrc ".

For example, try the following

Shell echo to most modern terminals can be colorized using ANSI escape code (see " /usr/share/doc/xterm/ctlseqs.txt.gz ").

ISO 8601 is followed for these iso-formats.

You can eliminate typing long option on commandline using command alias, e.g. " alias ls='ls --time-style=+%d.%m.%y\ %H:%M' " (see Section 1.5.9, “Command alias” ).

Table 9.4. Display examples of time and date for the " ls -l " command for wheezy

If you really wish to customize this display format of time and date beyond the locale , you should set the time style value by the " --time-style " argument or by the " $TIME_STYLE " value (see ls(1), date(1), " info coreutils 'ls invocation' ").

The actual default display format for each locale depends on the version of the standard C library (the libc6 package) used. I.e., different releases of Debian had different defaults.

The default display format of time and date by the " ls -l " command depends on the locale (see Section 1.2.6, “Timestamps” for value). The " $LANG " variable is referred first and it can be overridden by the " $LC_TIME " variable.

For vim(1) and its pager mode alias view(1), " :set hls " enables highlighted search.

You may use emacs(1) with " M-x shell ", " M-x eshell ", or " M-x term " to perform recording of console. You may later use " C-x C-w " to write the buffer to a file.

You may use screen(1) with " ^A H " (see Section 9.1.2, “Key bindings for the screen command” ) to perform recording of console.

Some x-terminal-emulator such as gnome-terminal can record. You may wish to extend line buffer for scrollback.

If you don't have script (for example, during the boot process in the initramfs), you can use the following instead.

Do whatever … and press Ctrl-D to exit script .

The simple use of script(1) (see Section 1.4.9, “Recording the shell activities” ) to record shell activity produces a file with control characters. This can be avoided by using col(1) as the following.

CRM114 provides language infrastructure to write fuzzy filters with the TRE regex library . Its popular use is spam mail filter but it can be used as log analyzer.

Here are notable log analyzers (" ~Gsecurity::log-analyzer " in aptitude(8)).

Many programs record their activities under the " /var/log/ " directory.

9.3. Monitoring, controlling, and starting program activities

Program activities can be monitored and controlled using specialized tools.

Tip The procps packages provide very basics of monitoring, controlling, and starting program activities. You should learn all of them.

9.3.1. Timing a process Display time used by the process invoked by the command. # time some_command >/dev/null real 0m0.035s # time on wall clock (elapsed real time) user 0m0.000s # time in user mode sys 0m0.020s # time in kernel mode

9.3.2. The scheduling priority A nice value is used to control the scheduling priority for the process. Table 9.8. List of nice values for the scheduling priority nice value scheduling priority 19 lowest priority process (nice) 0 very high priority process for user -20 very high priority process for root (not-nice)

# nice -19 top # very nice # nice --20 wodim -v -eject speed=2 dev=0,0 disk.img # very fast Sometimes an extreme nice value does more harm than good to the system. Use this command carefully.

9.3.3. The ps command The ps(1) command on a Debian system support both BSD and SystemV features and helps to identify the process activity statically. Table 9.9. List of ps command styles style typical command feature BSD ps aux display %CPU %MEM System V ps -efH display PPID

For the zombie (defunct) children process, you can kill them by the parent process ID identified in the " PPID " field. The pstree(1) command display a tree of processes.

9.3.4. The top command top(1) on the Debian system has rich features and helps to identify what process is acting funny dynamically. It is an interactive full screen program. You can get its usage help press by pressing the "h"-key and terminate it by pressing the "q"-key.

9.3.5. Listing files opened by a process You can list all files opened by a process with a process ID (PID), e.g. 1, by the following. $ sudo lsof -p 1 PID=1 is usually the init program.

9.3.6. Tracing program activities You can trace program activity with strace(1), ltrace(1), or xtrace(1) for system calls and signals, library calls, or communication between X11 client and server. You can trace system calls of the ls command as the following. $ sudo strace ls

9.3.7. Identification of processes using files or sockets You can also identify processes using files by fuser(1), e.g. for " /var/log/mail.log " by the following. $ sudo fuser -v /var/log/mail.log USER PID ACCESS COMMAND /var/log/mail.log: root 2946 F.... rsyslogd You see that file " /var/log/mail.log " is open for writing by the rsyslogd(8) command. You can also identify processes using sockets by fuser(1), e.g. for " smtp/tcp " by the following. $ sudo fuser -v smtp/tcp USER PID ACCESS COMMAND smtp/tcp: Debian-exim 3379 F.... exim4 Now you know your system runs exim4(8) to handle TCP connections to SMTP port (25).

9.3.8. Repeating a command with a constant interval watch(1) executes a program repeatedly with a constant interval while showing its output in fullscreen. $ watch w This displays who is logged on to the system updated every 2 seconds.

9.3.9. Repeating a command looping over files There are several ways to repeat a command looping over files matching some condition, e.g. matching glob pattern " *.ext ". Shell for-loop method (see Section 12.1.4, “Shell loops”): for x in *.ext; do if [ -f "$x"]; then command "$x" ; fi; done find(1) and xargs(1) combination: find . -type f -maxdepth 1 -name '*.ext' -print0 | xargs -0 -n 1 command find(1) with " -exec " option with a command: find . -type f -maxdepth 1 -name '*.ext' -exec command '{}' \; find(1) with " -exec " option with a short shell script: find . -type f -maxdepth 1 -name '*.ext' -exec sh -c "command '{}' && echo 'successful'" \; The above examples are written to ensure proper handling of funny file names such as ones containing spaces. See Section 10.1.5, “Idioms for the selection of files” for more advance uses of find(1).

9.3.10. Starting a program from GUI For the command-line interface (CLI), the first program with the matching name found in the directories specified in the $PATH environment variable is executed. See Section 1.5.3, “The " $PATH " variable”. For the graphical user interface (GUI) compliant to the freedesktop.org standards, the *.desktop files in the /usr/share/applications/ directory provide necessary attributes for the GUI menu display of each program. See Section 7.2.2, “Freedesktop.org menu”. For example, the chromium.desktop file defines attributes for the "Chromium Web Browser" such as "Name" for the program name, "Exec" for the program execution path and arguments, "Icon" for the icon used, etc. (see the Desktop Entry Specification) as follows: [Desktop Entry] Version=1.0 Name=Chromium Web Browser GenericName=Web Browser Comment=Access the Internet Comment[fr]=Explorer le Web Exec=/usr/bin/chromium %U Terminal=false X-MultipleArgs=false Type=Application Icon=chromium Categories=Network;WebBrowser; MimeType=text/html;text/xml;application/xhtml_xml;x-scheme-handler/http;x-scheme-handler/https; StartupWMClass=Chromium StartupNotify=true This is an oversimplified description. The *.desktop files are scanned as follows. The desktop environment sets $XDG_DATA_HOME and $XDG_DATA_DIR environment variables. For example, under the GNOME 3: $XDG_DATA_HOME is unset. (The default value of $HOME/.local/share is used.)

$XDG_DATA_DIRS is set to /usr/share/gnome:/usr/local/share/:/usr/share/ . So the base directories (see XDG Base Directory Specification) and the applications directories are as follows. $HOME/.local/share/ → $HOME/.local/share/applications/

/usr/share/gnome/ → /usr/share/gnome/applications/

/usr/local/share/ → /usr/local/share/applications/

/usr/share/ → /usr/share/applications/ The *.desktop files are scanned in these applications directories in this order. Tip A user custom GUI menu entry can be created by adding a *.desktop file in the $HOME/.local/share/applications/ directory. Tip Similarly, if a *.desktop file is created in the autostart directory under these base directories, the specified program in the *.desktop file is executed automatically when the desktop environment is started. See Desktop Application Autostart Specification. Tip Similarly, if a *.desktop file is created in the $HOME/Desktop directory and the Desktop environment is configured to support the desktop icon launcher feature, the specified program in it is executed upon clicking the icon. Please note that the actual name of the $HOME/Desktop directory is locale dependent. See xdg-user-dirs-update(1).

9.3.11. Customizing program to be started Some programs start another program automatically. Here are check points for customizing this process. Application configuration menu: GNOME3 desktop: "Settings" → "System" → "Details" → "Default Applications" KDE desktop: "K" → "Control Center" → "KDE Components" → "Component Chooser" Iceweasel browser: "Edit" → "Preferences" → "Applications" mc(1): " /etc/mc/mc.ext "

Environment variables such as " $BROWSER ", " $EDITOR ", " $VISUAL ", and " $PAGER " (see eviron(7))

The update-alternatives(1) system for programs such as " editor ", " view ", " x-www-browser ", " gnome-www-browser ", and " www-browser " (see Section 1.4.7, “Setting a default text editor”)

the " ~/.mailcap " and " /etc/mailcap " file contents which associate MIME type with program (see mailcap(5))

The " ~/.mime.types " and " /etc/mime.types " file contents which associate file name extension with MIME type (see run-mailcap(1)) Tip update-mime(8) updates the " /etc/mailcap " file using " /etc/mailcap.order " file (see mailcap.order(5)). Tip The debianutils package provides sensible-browser(1), sensible-editor(1), and sensible-pager(1) which make sensible decisions on which editor, pager, and web browser to call, respectively. I recommend you to read these shell scripts. Tip In order to run a console application such as mutt under X as your preferred application, you should create an X application as following and set " /usr/local/bin/mutt-term " as your preferred application to be started as described. # cat /usr/local/bin/mutt-term <<EOF #!/bin/sh gnome-terminal -e "mutt \$@" EOF chmod 755 /usr/local/bin/mutt-term

9.3.12. Killing a process Use kill(1) to kill (or send a signal to) a process by the process ID. Use killall(1) or pkill(1) to do the same by the process command name and other attributes. Table 9.10. List of frequently used signals for kill command signal value signal name function 1 HUP restart daemon 15 TERM normal kill 9 KILL kill hard



9.3.13. Scheduling tasks once Run the at(1) command to schedule a one-time job by the following. $ echo 'command -args'| at 3:40 monday

9.3.14. Scheduling tasks regularly Use cron(8) to schedule tasks regularly. See crontab(1) and crontab(5). You can schedule to run processes as a normal user, e.g. foo by creating a crontab(5) file as " /var/spool/cron/crontabs/foo " with " crontab -e " command. Here is an example of a crontab(5) file. # use /bin/sh to run commands, no matter what /etc/passwd says SHELL=/bin/sh # mail any output to paul, no matter whose crontab this is MAILTO=paul # Min Hour DayOfMonth Month DayOfWeek command (Day... are OR'ed) # run at 00:05, every day 5 0 * * * $HOME/bin/daily.job >> $HOME/tmp/out 2>&1 # run at 14:15 on the first of every month -- output mailed to paul 15 14 1 * * $HOME/bin/monthly # run at 22:00 on weekdays(1-5), annoy Joe. % for newline, last % for cc: 0 22 * * 1-5 mail -s "It's 10pm" joe%Joe,%%Where are your kids?%.%% 23 */2 1 2 * echo "run 23 minutes after 0am, 2am, 4am ..., on Feb 1" 5 4 * * sun echo "run at 04:05 every Sunday" # run at 03:40 on the first Monday of each month 40 3 1-7 * * [ "$(date +%a)" == "Mon" ] && command -args Tip For the system not running continuously, install the anacron package to schedule periodic commands at the specified intervals as closely as machine-uptime permits. See anacron(8) and anacrontab(5). Tip For scheduled system maintenance scripts, you can run them periodically from root account by placing such scripts in " /etc/cron.hourly/ ", " /etc/cron.daily/ ", " /etc/cron.weekly/ ", or " /etc/cron.monthly/ ". Execution timings of these scripts can be customized by " /etc/crontab " and " /etc/anacrontab ".