Powered By GitBook
103.1. Work on the command line

103.1 Work on the command line

Weight: 4
Description:Candidates should be able to interact with shells and commands using the command line. The objective assumes the Bash shell.
Key Knowledge Areas:
    Use single shell commands and one line command sequences to perform basic tasks on the command line
    Use and modify the shell environment including defining, referencing and exporting environment variables
    Use and edit command history
    Invoke commands inside and outside the defined path
Terms and Utilities:
    bash
    echo
    env
    export
    pwd
    set
    unset
    man
    uname
    history
    .bash_history
What's A "Terminal?"
It's a program called a terminal emulator. This is a program that opens a window and lets you interact with the shell. There are a bunch of different terminal emulators we can use. Most Linux distributions supply several, such as: gnome-terminal, konsole, xterm, ... , It is also called Console.
What is "The Shell"?
Simply put, the shell is a program that takes commands from the keyboard and gives them to the operating system to perform. In the old days, it was the only user interface available on a Unix-like system such as Linux. Nowadays, we have graphical user interfaces (GUIs) in addition to command line interfaces (CLIs) such as the shell.
What is The "bash"?
On most Linux systems a program called bash acts as the shell program. bash stands for Bourne Again SHell, an enhanced version of the original Unix shell program, sh, written by Steve Bourne
Besides, There are other shell programs that can be installed in a Linux system. These include: ksh, tcsh and zsh.
1
[[email protected] ~]# ls -ls /bin/sh
2
0 lrwxrwxrwx. 1 root root 4 Oct 28 2017 /bin/sh -> bash
Copied!
note: Historically the original /bin/sh Bourne shell would use $ as the normal prompt and # for the root user prompt This made it pretty easy to tell if you were running as superuser or not.
2
[[email protected] ~]# su - user1
3
Last login: Mon Dec 10 11:44:47 EST 2018 on pts/0
5
[[email protected] ~]$ su - root
6
Password:
7
Last login: Wed Dec 12 14:34:32 EST 2018 on pts/0
Copied!
Standard Input, Standard Output and Standard Error
In general, a command (a program):
    Gets data to process from standard input or stdin (default: keyboard).
    Returns processed data to standard output or stdout (default: screen).
    If program execution causes errors, error messages are sent to standard error or stderr (default: screen).

echo

echo is one of the most commonly and widely used built-in command for Linux bash and C shells, that typically used in scripting language and batch files to display a line of text/string on standard output or a file.
The syntax for echo is: echo [option(s)] [string(s)]
example : Input a line of text and display on standard output:
1
[[email protected] ~]# echo Lets start learning Linux
2
Lets start learning Linux
Copied!
The echo command has a couple of options. Normally, echo will append a trailing new line character to the output. Use the-noption to suppress this:
1
[[email protected] ~]# echo -n Lets start learning Linux
2
Lets start learning Linux[[email protected] ~]#
Copied!

Special Characters or Meta Characters

What makes a character special? If it has a meaning beyond its literal meaning, a meta-meaning, then we refer to it as a special character or metacharacters like : | & ; ( ) < > [ ] { } * ! ? ` ' " $ \ / #
pound sign (#)
Everything written after a pound sign (#) is ignored by the shell. This is useful to write a shell comment, but has no influence on the command execution or shell expansion.
1
[[email protected] temp]# ls # ls /etc
2
zip-3.0-11.el7.x86_64.rpm zip.cpio
Copied!
end of line backslash \
Lines ending in a backslash are continued on the next line. The shell does not interpret the newline character and will wait on shell expansion and execution of the command line until a newline without backslash is encountered.
1
[[email protected] ~]# echo first line second line \
2
> 2nd line \
3
> 3rd line
4
first line second line 2nd line 3rd line
Copied!
escaping special characters
The backslash character enables the use of control characters, but without the shell interpreting it, this is called escaping characters.
1
[[email protected] ~]# echo hello | by
2
bash: by: command not found...
3
[[email protected] ~]# echo hello \| by
4
hello | by
5
[[email protected] ~]# echo hello ; by
6
hello
7
bash: by: command not found...
8
[[email protected] ~]# echo hello \; by
9
hello ; by
Copied!
Double quotes " "
Enclosing characters in double quotes (") preserves the literal value of all characters within the quotes, [with the exception of $, `, \, and, when history expansion is enabled, ! .The characters $ and ` retain their special meaning within double quotes].
1
[[email protected] ~]# echo "hello | by"
2
hello | by
3
[[email protected] ~]# echo "hello ; by"
4
hello ; by
Copied!
Lets take a look at other options of echo command:
1
-n do not output the trailing newline
2
-e enable interpretation of backslash escapes
3
-E disable interpretation of backslash escapes (default)
4
--help display this help and exit
5
--version
6
output version information and exit
7
8
If -e is in effect, the following sequences are recognized:
9
\b backspace
10
\\ backslash
11
\n new line
12
\r carriage return
13
\t horizontal tab
14
\v vertical tab
Copied!
Use the-eoption to enable certain backslash escaped characters to have special meaning.
Escape sequence
Function
\a
Alert (bell)
\b
Backspace
\c
Suppress trailing newline (same function as -n option)
\f
Form feed (clear the screen on a video display)
\n
New line
\r
Carriage return
\t
Horizontal tab
\v
vertical tab
Some examples:
1
[[email protected] ~]# echo -e "Lets \vstart \vlearning \vLinux"
2
Lets
3
start
4
learning
5
Linux
6
[[email protected] ~]# echo -e "Lets \tstart \tlearning \tLinux"
7
Lets start learning Linux
Copied!
One of echo command usage is getting variable values with echo $VARIABLENAME command. We will see that.
1
[[email protected] ~]# echo $LD_LIBRARY_PATH
2
Copied!

Control Operators

Certain metacharacters or pairs of metacharacters also serve as control operators: || && & ; ;; | ()
Some of these control operators allow you to create sequences or lists of commands.

Linux command chaining

Sometimes we would want to run multiple commands in succession or simultaneously. This allows us to automate a process that include several commands that may or may not depend on the result of the previous command.
Linux command chaining is the method of combining several different commands such that each of them can execute in succession based on the operator that separate them. The important part of chaining is the operators that we use to combine them. These operators determine how the commands execute.
Lets take a look at some of operators that are used mostly to combine different commands :
Semi-Colon (;) : The succeeding commands will execute regardless of the exit status of the command that precedes it.
1
[[email protected] ~]# ls /root/ ; ls /home/
2
anaconda-ks.cfg mydb.ldif usr
3
htop-2.2.0-1.el7.x86_64.rpm set.txt zip-3.0-11.el7.x86_64.rpm
4
initial-setup-ks.cfg telnet-0.17-64.el7.x86_64.rpm zip.cpio
5
managersou.ldif temp
6
ldapadm pabros payam user1 user2
Copied!
Logical AND (&&) : This command that follows this operator will execute only if the preceding command executes successfully.
1
[[email protected] ~]# true && ls /home/
2
ldapadm pabros payam user1 user2
Copied!
Logical OR (||) : The command that follows will execute only if the preceding command fails.
1
[[email protected] ~]# false || ls /home/
2
ldapadm pabros payam user1 user2
Copied!

Environment Variables

Environment Variables are some special variables that are defined in shell and are needed by programs while execution. They can be system defined or user defined.
System defined variables are those which are set by system and are used by system level programs.
The whole concept of setting and un-setting environment variables revolves around some set of files and few commands and different shells.
an environment variable can be in three types:
1. Local Environment Variable :One defined for the current session. These environment variables last only till the current session, be it remote login session, or local terminal session. These variables are not specified in any configuration files and are created, and removed by using a special set of commands.
2. User Environment Variable : These are the variables which are defined for a particular user and are loaded every time a user logs in using a local terminal session or that user is logged in using remote login session. These variables are typically set in and loaded from some configuration files which are present in user’s home directory.
3. System wide Environment Variables :These are the environment variables which are available system-wide, i.e. for all the users present on that system. These variables are present in system-wide configuration files present in /etc directories and files.These variables are loaded every time system is powered on and logged in either locally or remotely by any user.

env

By default, "env" command lists all the current environment variables.
2
XDG_VTNR=1
3
XDG_SESSION_ID=1
4
HOSTNAME=centos7-1
5
SHELL=/bin/bash
6
TERM=xterm-256color
7
HISTSIZE=1000
8
USER=root
9
LS_COLORS=rs=0:di=38;5;27:ln=38;5;51:mh=44;38;5;15:pi=40;38;5;11:so=38;5;13:do=38;5;5:bd=48;5;232;38;5;11:cd=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=05;48;5;232;38;5;15:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:tw=48;5;10;38;5;16:ow=48;5;10;38;5;21:st=48;5;21;38;5;15:ex=38;5;34:*.tar=38;5;9:*.tgz=38;5;9:*.arc=38;5;9:*.arj=38;5;9:*.taz=38;5;9:*.lha=38;5;9:*.lz4=38;5;9:*.lzh=38;5;9:*.lzma=38;5;9:*.tlz=38;5;9:*.txz=38;5;9:*.tzo=38;5;9:*.t7z=38;5;9:*.zip=38;5;9:*.z=38;5;9:*.Z=38;5;9:*.dz=38;5;9:*.gz=38;5;9:*.lrz=38;5;9:*.lz=38;5;9:*.lzo=38;5;9:*.xz=38;5;9:*.bz2=38;5;9:*.bz=38;5;9:*.tbz=38;5;9:*.tbz2=38;5;9:*.tz=38;5;9:*.deb=38;5;9:*.rpm=38;5;9:*.jar=38;5;9:*.war=38;5;9:*.ear=38;5;9:*.sar=38;5;9:*.rar=38;5;9:*.alz=38;5;9:*.ace=38;5;9:*.zoo=38;5;9:*.cpio=38;5;9:*.7z=38;5;9:*.rz=38;5;9:*.cab=38;5;9:*.jpg=38;5;13:*.jpeg=38;5;13:*.gif=38;5;13:*.bmp=38;5;13:*.pbm=38;5;13:*.pgm=38;5;13:*.ppm=38;5;13:*.tga=38;5;13:*.xbm=38;5;13:*.xpm=38;5;13:*.tif=38;5;13:*.tiff=38;5;13:*.png=38;5;13:*.svg=38;5;13:*.svgz=38;5;13:*.mng=38;5;13:*.pcx=38;5;13:*.mov=38;5;13:*.mpg=38;5;13:*.mpeg=38;5;13:*.m2v=38;5;13:*.mkv=38;5;13:*.webm=38;5;13:*.ogm=38;5;13:*.mp4=38;5;13:*.m4v=38;5;13:*.mp4v=38;5;13:*.vob=38;5;13:*.qt=38;5;13:*.nuv=38;5;13:*.wmv=38;5;13:*.asf=38;5;13:*.rm=38;5;13:*.rmvb=38;5;13:*.flc=38;5;13:*.avi=38;5;13:*.fli=38;5;13:*.flv=38;5;13:*.gl=38;5;13:*.dl=38;5;13:*.xcf=38;5;13:*.xwd=38;5;13:*.yuv=38;5;13:*.cgm=38;5;13:*.emf=38;5;13:*.axv=38;5;13:*.anx=38;5;13:*.ogv=38;5;13:*.ogx=38;5;13:*.aac=38;5;45:*.au=38;5;45:*.flac=38;5;45:*.mid=38;5;45:*.midi=38;5;45:*.mka=38;5;45:*.mp3=38;5;45:*.mpc=38;5;45:*.ogg=38;5;45:*.ra=38;5;45:*.wav=38;5;45:*.axa=38;5;45:*.oga=38;5;45:*.spx=38;5;45:*.xspf=38;5;45:
10
MAIL=/var/spool/mail/root
11
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
12
PWD=/root
13
LANG=en_US.UTF-8
14
HISTCONTROL=ignoredups
15
SHLVL=1
16
XDG_SEAT=seat0
17
HOME=/root
18
LOGNAME=root
19
XDG_DATA_DIRS=/root/.local/share/flatpak/exports/share/:/var/lib/flatpak/exports/share/:/usr/local/share/:/usr/share/
20
LESSOPEN=||/usr/bin/lesspipe.sh %s
21
_=/bin/env
22
OLDPWD=/etc
Copied!
These varibales make working with shell easier. Some of most important ones are:
    HOSTNAME:The name of the your computer.
    SHELL: This describes the shell that will be interpreting any commands you type in. In most cases, this will be bash by default, but other values can be set if you prefer other options.
    TERM: This specifies the type of terminal to emulate when running the shell. Different hardware terminals can be emulated for different operating requirements. We usually won't need to worry about this though.
    USER: The current logged in user.
    LS_COLORS: This defines color codes that are used to optionally add colored output to the ls command. This is used to distinguish different file types and provide more info to the user at a glance.
    MAIL: The path to the current user's mailbox.
    PATH: A list of directories that the system will check when looking for commands. When a user types in a command, the system will check directories in this order for the executable.
1
[[email protected] ~]# echo $PATH
2
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
3
[[email protected] ~]# which firefox
4
/bin/firefox
5
[[email protected] ~]# type firefox
6
firefox is /bin/firefox
7
[[email protected] ~]# whereis firefox
8
firefox: /usr/bin/firefox /usr/lib64/firefox /etc/firefox /usr/share/man/man1/firefox.1.gz
Copied!
For running other scripts or commands we can add them to path, or use full path or relative path (. and ..)
PATH=$PATH:/tmp/mybin
    PWD: The current working directory.
We use pwd command to see that:
2
/root
3
[[email protected] ~]# cd /etc/
4
5
/etc
Copied!
    LANG: The current language and localization settings, including character encoding.
    HOME: The current user's home directory.
    _: The most recent previously executed command.
    OLDPWD: The previous working directory. This is kept by the shell in order to switch back to your previous directory by running cd -.
The exit code of the previous command is stored in the shell variable $?. Actually $? is a shell parameter and not a variable, since you cannot assign a value to $?.
[[email protected] ~]# touch my.txt
[[email protected] ~]# echo $?
0
To see the value of a variable use echo $VARIABLENAME :
1
[[email protected] ~]# echo $MAIL
2
/var/spool/mail/root
3
[[email protected] ~]# echo $USER
4
root
5
[[email protected] ~]# echo $PATH
6
/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
Copied!
To set a Local Variable we create a local variable VAR1 and set it to any value( Historically it is recommended to use upper case for variables but you are free to use what ever case you want):
1
[[email protected] ~]# VAR1="Lets Learn Linux"
2
[[email protected] ~]# echo $VAR1
3
Lets Learn Linux
Copied!
By default variables are local, so What will happen to our Variable if we start a new sub shell ?
1
[[email protected] ~]# VAR1="Lets learn Linux"
2
[[email protected] ~]# echo $VAR1
3
Lets learn Linux
5
[[email protected] ~]# echo $VAR1
Copied!
It shows nothing. Why?
Child vs Parent process
Any process can be a parent and child process at the same time. The only exception is the init process, which is always marked with PID ( process ID ) 1. Therefore, init is a parent of all processes running on your Linux system.
Any process created will normally have a parent process from which it was created and will be considered as a child of this parent process. echo $ print a PID for a current shell
1
[[email protected] ~]# echo $
2
24370
4
[[email protected] ~]# echo $
5
24652
7
exit
8
[[email protected] ~]# echo $
9
24370
Copied!
When creating a new child process (a sub shell in our example) an export command simply ensures that any exported variables in the parent process are available in the child process.
We can terminate a shell using the exit command or simply press ctrl+d keys.
( ) : parentheses really put the command in a subshell. try(exit)

export

export command is one of the bash shell builtin commands, marks an environment variable to be exported to child-processes, so that the child inherits them.
1
[[email protected] ~]# VAR2="Linux is Fun"
2
[[email protected] ~]# echo $VAR2
3
Linux is Fun
4
[[email protected] ~]# export VAR2
5
[[email protected] ~]# echo $
6
24328
8
[[email protected] ~]# echo $
9
24722
10
[[email protected] ~]# echo $VAR2
11
Linux is Fun
Copied!
Syntax:export [-fn] [name[=value] ...] or export -p
The export command is fairly simple to use as it has straightforward syntax with only three available command options.
1
-p List of all names that are exported in the current shell
2
-n Remove names from export list
3
-f Names are exported as functions
Copied!
Following our example:
1
[[email protected] ~]# export -p | grep -i var2
2
declare -x VAR2="Linux is Fun"
3
[[email protected] ~]# export -n VAR2
4
[[email protected] ~]# export -p | grep -i var2
Copied!

set

setis a shell built-in that (If no options or arguments are supplied) displays all shell variables, not only the environment ones, and also shell functions, which is what you are seeing at the end of the list.
2
ABRT_DEBUG_LOG=/dev/null
3
BASH=/bin/bash
4
BASHOPTS=checkwinsize:cmdhist:expand_aliases:extglob:extquote:force_fignore:histappend:interactive_comments:login_shell:progcomp:promptvars:sourcepath
5
BASH_ALIASES=()
6
BASH_ARGC=()
7
BASH_ARGV=()
8
BASH_CMDS=()
9
BASH_COMPLETION_COMPAT_DIR=/etc/bash_completion.d
10
BASH_LINENO=()
11
BASH_SOURCE=()
12
BASH_VERSINFO=([0]="4" [1]="2" [2]="46" [3]="2" [4]="release" [5]="x86_64-redhat-linux-gnu")
13
BASH_VERSION='4.2.46(2)-release'
14
COLUMNS=87
15
DIRSTACK=()
16
DISPLAY=:0
17
EUID=0
18
FINAL_LIST=
19
GLUSTER_BARRIER_OPTIONS=#x27;\n {enable},\n {disable}\n'
20
GLUSTER_COMMAND_TREE=#x27;\n{gluster [\n \n {volume [\n {add-brick\n {__VOLNAME}\n },\n {barrier\n {__VOLNAME\n [ \n {enable},\n {disable}\n ]\n }\n },\n {clear-locks\n {__VOLNAME}\n },\n {create},\n {delete\n {__VOLNAME}\n },\n {geo-replication\n [ \n {__VOLNAME [\n {__SLAVEURL [\n {create [\n {push-pem\n {force}\n },\n {force}\n ]\n },\n {start {force} },\n {status {detail} },\n {config},\n {pause {force} },\n {resume {force} },\n {stop {force} },\n {delete {force} }\n ]\n },\n {status}\n ]\n },\n {status}\n ]\n },\n {heal\n {__VOLNAME}\n },\n {help},\n {info\n {__VOLNAME}\n },\n {list},\n {log\n {__VOLNAME}\n },\n {profile\n {__VOLNAME\n [ \n {start},\n {info [\n {peek},\n {incremental\n {peek}\n },\n {cumulative},\n {clear},\n ]\n },\n {stop}\n ]\n }\n },\n {quota\n {__VOLNAME\n [ \n {enable},\n {disable},\n {list},\n {remove},\n {default-soft-limit},\n {limit-usage},\n {alert-time},\n {soft-timeout},\n {hard-timeout}\n ]\n }\n },\n {rebalance\n {__VOLNAME}\n },\n {remove-brick\n {__VOLNAME}\n },\n {replace-brick\n {__VOLNAME}\n },\n {reset\n {__VOLNAME\n [ ]\n }\n },\n {set\n {__VOLNAME\n [ ]\n }\n },\n {start\n {__VOLNAME\n {force}\n }\n },\n {statedump\n {__VOLNAME}\n },\n {status\n {__VOLNAME}\n },\n {stop\n {__VOLNAME\n {force}\n }\n },\n {sync\n {__HOSTNAME}\n },\n {top\n {__VOLNAME\n [ \n {open\n [ ]\n },\n {read\n [ ]\n },\n {write\n [ ]\n },\n {opendir\n [ ]\n },\n {readdir\n [ ]\n },\n {clear\n [ ]\n },\n {read-perf\n [ ]\n },\n {write-perf\n [ ]\n }\n ]\n }\n }\n ]\n }\n ,\n {peer [\n {probe\n {__HOSTNAME}\n },\n {detach\n {__HOSTNAME\n {force}\n }\n },\n {status}\n ]\n },\n {pool\n {list}\n },\n {help}\n ]\n}'
21
GLUSTER_GEO_REPLICATION_OPTIONS=#x27;\n {__VOLNAME [\n {__SLAVEURL [\n {create [\n {push-pem\n {force}\n },\n {force}\n ]\n },\n {start {force} },\n {status {detail} },\n {config},\n {pause {force} },\n {resume {force} },\n {stop {force} },\n {delete {force} }\n ]\n },\n {status}\n ]\n },\n {status}\n'
22
GLUSTER_GEO_REPLICATION_SUBOPTIONS=#x27;\n'
23
GLUSTER_PROFILE_OPTIONS=#x27;\n {start},\n {info [\n {peek},\n {incremental\n {peek}\n },\n {cumulative},\n {clear},\n ]\n },\n {stop}\n'
24
GLUSTER_QUOTA_OPTIONS=#x27;\n {enable},\n {disable},\n {list},\n {remove},\n {default-soft-limit},\n {limit-usage},\n {alert-time},\n {soft-timeout},\n {hard-timeout}\n'
25
GLUSTER_TOP_OPTIONS=#x27;\n {open\n [ ]\n },\n {read\n [ ]\n },\n {write\n [ ]\n },\n {opendir\n [ ]\n },\n {readdir\n [ ]\n },\n {clear\n [ ]\n },\n {read-perf\n [ ]\n },\n {write-perf\n [ ]\n }\n'
26
GLUSTER_TOP_SUBOPTIONS1=#x27;\n {nfs},\n {brick},\n {list-cnt}\n'
27
GLUSTER_TOP_SUBOPTIONS2=#x27;\n {bs\n {__SIZE\n {count}\n }\n },\n {brick},\n {list-cnt}\n'
28
GLUSTER_VOLUME_OPTIONS=#x27;\n {volume [\n {add-brick\n {__VOLNAME}\n },\n {barrier\n {__VOLNAME\n [ \n {enable},\n {disable}\n ]\n }\n },\n {clear-locks\n {__VOLNAME}\n },\n {create},\n {delete\n {__VOLNAME}\n },\n {geo-replication\n [ \n {__VOLNAME [\n {__SLAVEURL [\n {create [\n {push-pem\n {force}\n },\n {force}\n ]\n },\n {start {force} },\n {status {detail} },\n {config},\n {pause {force} },\n {resume {force} },\n {stop {force} },\n {delete {force} }\n ]\n },\n {status}\n ]\n },\n {status}\n ]\n },\n {heal\n {__VOLNAME}\n },\n {help},\n {info\n {__VOLNAME}\n },\n {list},\n {log\n {__VOLNAME}\n },\n {profile\n {__VOLNAME\n [ \n {start},\n {info [\n {peek},\n {incremental\n {peek}\n },\n {cumulative},\n {clear},\n ]\n },\n {stop}\n ]\n }\n },\n {quota\n {__VOLNAME\n [ \n {enable},\n {disable},\n {list},\n {remove},\n {default-soft-limit},\n {limit-usage},\n {alert-time},\n {soft-timeout},\n {hard-timeout}\n ]\n }\n },\n {rebalance\n {__VOLNAME}\n },\n {remove-brick\n {__VOLNAME}\n },\n {replace-brick\n {__VOLNAME}\n },\n {reset\n {__VOLNAME\n [ ]\n }\n },\n {set\n {__VOLNAME\n [ ]\n }\n },\n {start\n {__VOLNAME\n {force}\n }\n },\n {statedump\n {__VOLNAME}\n },\n {status\n {__VOLNAME}\n },\n {stop\n {__VOLNAME\n {force}\n }\n },\n {sync\n {__HOSTNAME}\n },\n {top\n {__VOLNAME\n [ \n {open\n [ ]\n },\n {read\n [ ]\n },\n {write\n [ ]\n },\n {opendir\n [ ]\n },\n {readdir\n [ ]\n },\n {clear\n [ ]\n },\n {read-perf\n [ ]\n },\n {write-perf\n [ ]\n }\n ]\n }\n }\n ]\n }\n'
29
GROUPS=()
30
HISTCONTROL=ignoredups
31
HISTFILE=/root/.bash_history
32
HISTFILESIZE=1000
33
HISTSIZE=1000
34
HOME=/root
35
HOSTNAME=centos7-1
36
HOSTTYPE=x86_64
37
ID=0
38
IFS=#x27; \t\n'
39
LANG=en_US.UTF-8
40
LESSOPEN='||/usr/bin/lesspipe.sh %s'
41
LINES=23
42
LIST=
43
LOGNAME=root
44
LPATHDIR=/root/.cache/abrt
45
LS_COLORS='rs=0:di=38;5;27:ln=38;5;51:mh=44;38;5;15:pi=40;38;5;11:so=38;5;13:do=38;5;5:bd=48;5;232;38;5;11:cd=48;5;232;38;5;3:or=48;5;232;38;5;9:mi=05;48;5;232;38;5;15:su=48;5;196;38;5;15:sg=48;5;11;38;5;16:ca=48;5;196;38;5;226:tw=48;5;10;38;5;16:ow=48;5;10;38;5;21:st=48;5;21;38;5;15:ex=38;5;34:*.tar=38;5;9:*.tgz=38;5;9:*.arc=38;5;9:*.arj=38;5;9:*.taz=38;5;9:*.lha=38;5;9:*.lz4=38;5;9:*.lzh=38;5;9:*.lzma=38;5;9:*.tlz=38;5;9:*.txz=38;5;9:*.tzo=38;5;9:*.t7z=38;5;9:*.zip=38;5;9:*.z=38;5;9:*.Z=38;5;9:*.dz=38;5;9:*.gz=38;5;9:*.lrz=38;5;9:*.lz=38;5;9:*.lzo=38;5;9:*.xz=38;5;9:*.bz2=38;5;9:*.bz=38;5;9:*.tbz=38;5;9:*.tbz2=38;5;9:*.tz=38;5;9:*.deb=38;5;9:*.rpm=38;5;9:*.jar=38;5;9:*.war=38;5;9:*.ear=38;5;9:*.sar=38;5;9:*.rar=38;5;9:*.alz=38;5;9:*.ace=38;5;9:*.zoo=38;5;9:*.cpio=38;5;9:*.7z=38;5;9:*.rz=38;5;9:*.cab=38;5;9:*.jpg=38;5;13:*.jpeg=38;5;13:*.gif=38;5;13:*.bmp=38;5;13:*.pbm=38;5;13:*.pgm=38;5;13:*.ppm=38;5;13:*.tga=38;5;13:*.xbm=38;5;13:*.xpm=38;5;13:*.tif=38;5;13:*.tiff=38;5;13:*.png=38;5;13:*.svg=38;5;13:*.svgz=38;5;13:*.mng=38;5;13:*.pcx=38;5;13:*.mov=38;5;13:*.mpg=38;5;13:*.mpeg=38;5;13:*.m2v=38;5;13:*.mkv=38;5;13:*.webm=38;5;13:*.ogm=38;5;13:*.mp4=38;5;13:*.m4v=38;5;13:*.mp4v=38;5;13:*.vob=38;5;13:*.qt=38;5;13:*.nuv=38;5;13:*.wmv=38;5;13:*.asf=38;5;13:*.rm=38;5;13:*.rmvb=38;5;13:*.flc=38;5;13:*.avi=38;5;13:*.fli=38;5;13:*.flv=38;5;13:*.gl=38;5;13:*.dl=38;5;13:*.xcf=38;5;13:*.xwd=38;5;13:*.yuv=38;5;13:*.cgm=38;5;13:*.emf=38;5;13:*.axv=38;5;13:*.anx=38;5;13:*.ogv=38;5;13:*.ogx=38;5;13:*.aac=38;5;45:*.au=38;5;45:*.flac=38;5;45:*.mid=38;5;45:*.midi=38;5;45:*.mka=38;5;45:*.mp3=38;5;45:*.mpc=38;5;45:*.ogg=38;5;45:*.ra=38;5;45:*.wav=38;5;45:*.axa=38;5;45:*.oga=38;5;45:*.spx=38;5;45:*.xspf=38;5;45:'
46
MACHTYPE=x86_64-redhat-linux-gnu
47
MAIL=/var/spool/mail/root
48
MAILCHECK=60
49
OPTERR=1
50
OPTIND=1
51
OSTYPE=linux-gnu
52
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin
53
PIPESTATUS=([0]="0")
54
PPID=23050
55
PROMPT_COMMAND='printf "\033]0;%[email protected]%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
56
PS1='[\[email protected]\h \W]\$ '
57
PS2='> '
58
PS4='+ '
59
PWD=/root
60
SHELL=/bin/bash
61
SHELLOPTS=braceexpand:emacs:hashall:histexpand:history:interactive-comments:monitor
62
SHLVL=1
63
SINCE=1544460722
64
SINCEFILE=/root/.cache/abrt/lastnotification
65
TERM=xterm-256color
66
TMPPATH=/root/.cache/abrt/lastnotification.QPDZ45se
67
TOP=0
68
UID=0
69
USER=root
70
XAUTHORITY=/root/.xauthTthXrM
71
XDG_DATA_DIRS=/root/.local/share/flatpak/exports/share/:/var/lib/flatpak/exports/share/:/usr/local/share/:/usr/share/
72
XDG_SEAT=seat0
73
XDG_SESSION_ID=1
74
XDG_VTNR=1
75
_=PATH
76
_backup_glob='@(#*#|*@(~|[email protected](bak|orig|rej|swp|dpkg*|[email protected](orig|new|save))))'
77
_xspecs=([freeamp]="!*[email protected](mp3|ogg|pls|m3u)" [cdiff]="!*[email protected](dif?(f)|?(d)patch)?([email protected]([gx]z|bz2|lzma))" [bibtex]="!*.aux" [rgview]="*[email protected](o|so|so.!(conf|*/*)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [oowriter]="!*[email protected](sxw|stw|sxg|sgl|doc?([mx])|dot?([mx])|rtf|txt|htm|html|?(f)odt|ott|odm)" [chromium-browser]="!*[email protected](?([xX]|[sS])[hH][tT][mM]?([lL]))" [tex]="!*[email protected](?(la)tex|texi|dtx|ins|ltx|dbj)" [zathura]="!*[email protected](cb[rz7t]|djv?(u)|?(e)ps|pdf)" [netscape]="!*[email protected](?([xX]|[sS])[hH][tT][mM]?([lL]))" [acroread]="!*.[pf]df" [makeinfo]="!*.texi*" [kwrite]="*[email protected](o|so|so.!(conf|*/*)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [gview]="*[email protected](o|so|so.!(conf|*/*)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [qiv]="!*[email protected](gif|jp?(e)g|tif?(f)|png|p[bgp]m|bmp|x[bp]m|rle|rgb|pcx|fits|pm|svg)" [lrunzip]="!*.lrz" [bzcat]="!*.?(t)bz?(2)" [amaya]="!*[email protected](?([xX]|[sS])[hH][tT][mM]?([lL]))" [pdftex]="!*[email protected](?(la)tex|texi|dtx|ins|ltx|dbj)" [hbpp]="!*[email protected]([Pp][Rr][Gg]|[Cc][Ll][Pp])" [rpm2cpio]="!*.[rs]pm" [view]="*[email protected](o|so|so.!(conf|*/*)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [unxz]="!*[email protected](?(t)xz|tlz|lzma)" [ly2dvi]="!*.ly" [mozilla]="!*[email protected](?([xX]|[sS])[hH][tT][mM]?([lL]))" [modplugplay]="!*[email protected](669|abc|am[fs]|d[bs]m|dmf|far|it|mdl|m[eo]d|mid?(i)|mt[2m]|okta|p[st]m|s[3t]m|ult|umx|wav|xm)" [lzgrep]="!*[email protected](tlz|lzma)" [pyflakes]="!*.py" [dillo]="!*[email protected](?([xX]|[sS])[hH][tT][mM]?([lL]))" [aaxine]="!*@([email protected](mp?(e)g|MP?(E)G|wma|avi|AVI|asf|vob|VOB|bin|dat|divx|DIVX|vcd|ps|pes|fli|flv|FLV|fxm|FXM|viv|rm|ram|yuv|mov|MOV|qt|QT|wmv|mp[234]|MP[234]|m4[pv]|M4[PV]|mkv|MKV|og[gmv]|OG[GMV]|t[ps]|T[PS]|m2t?(s)|M2T?(S)|wav|WAV|flac|FLAC|asx|ASX|mng|MNG|srt|m[eo]d|M[EO]D|s[3t]m|S[3T]M|it|IT|xm|XM)|+([0-9])[email protected](vdr|VDR))?(.part)" [dvipdfmx]="!*.dvi" [advi]="!*.dvi" [ggv]="!*[email protected](@(?(e)ps|?(E)PS|pdf|PDF)?(.gz|.GZ|.bz2|.BZ2|.Z))" [lzmore]="!*[email protected](tlz|lzma)" [lzless]="!*[email protected](tlz|lzma)" [kdvi]="!*[email protected](dvi|DVI)?([email protected](gz|Z|bz2))" [poedit]="!*.po" [firefox]="!*[email protected](?([xX]|[sS])[hH][tT][mM]?([lL]))" [gv]="!*[email protected](@(?(e)ps|?(E)PS|pdf|PDF)?(.gz|.GZ|.bz2|.BZ2|.Z))" [madplay]="!*.mp3" [lbzcat]="!*.?(t)bz?(2)" [lilypond]="!*.ly" [gtranslator]="!*.po" [jadetex]="!*[email protected](?(la)tex|texi|dtx|ins|ltx|dbj)" [sxemacs]="*[email protected](o|so|so.!(conf|*/*)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [epdfview]="!*.pdf" [gpdf]="!*.[pf]df" [kghostview]="!*[email protected](@(?(e)ps|?(E)PS|pdf|PDF)?(.gz|.GZ|.bz2|.BZ2|.Z))" [pbzcat]="!*.?(t)bz?(2)" [texi2dvi]="!*[email protected](?(la)tex|texi|dtx|ins|ltx|dbj)" [ps2pdf12]="!*[email protected](?(e)ps|pdf)" [ee]="!*[email protected](gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx)" [lzcat]="!*[email protected](tlz|lzma)" [lbunzip2]="!*.?(t)bz?(2)" [ps2pdf13]="!*[email protected](?(e)ps|pdf)" [vim]="*[email protected](o|so|so.!(conf|*/*)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [ps2pdf14]="!*[email protected](?(e)ps|pdf)" [dvips]="!*.dvi" [lzfgrep]="!*[email protected](tlz|lzma)" [hbrun]="!*.[Hh][Rr][Bb]" [kbabel]="!*.po" [rview]="*[email protected](o|so|so.!(conf|*/*)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [kaffeine]="!*@([email protected](mp?(e)g|MP?(E)G|wma|avi|AVI|asf|vob|VOB|bin|dat|divx|DIVX|vcd|ps|pes|fli|flv|FLV|fxm|FXM|viv|rm|ram|yuv|mov|MOV|qt|QT|wmv|mp[234]|MP[234]|m4[pv]|M4[PV]|mkv|MKV|og[gmv]|OG[GMV]|t[ps]|T[PS]|m2t?(s)|M2T?(S)|wav|WAV|flac|FLAC|asx|ASX|mng|MNG|srt|m[eo]d|M[EO]D|s[3t]m|S[3T]M|it|IT|xm|XM|iso|ISO)|+([0-9])[email protected](vdr|VDR))?(.part)" [xv]="!*[email protected](gif|jp?(e)g|tif?(f)|png|p[bgp]m|bmp|x[bp]m|rle|rgb|pcx|fits|pm|?(e)ps)" [rgvim]="*[email protected](o|so|so.!(conf|*/*)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [dvitype]="!*.dvi" [oodraw]="!*[email protected](sxd|std|sda|sdd|?(f)odg|otg)" [elinks]="!*[email protected](?([xX]|[sS])[hH][tT][mM]?([lL]))" [playmidi]="!*[email protected](mid?(i)|cmf)" [realplay]="!*[email protected](rm?(j)|ra?(m)|smi?(l))" [xine]="!*@([email protected](mp?(e)g|MP?(E)G|wma|avi|AVI|asf|vob|VOB|bin|dat|divx|DIVX|vcd|ps|pes|fli|flv|FLV|fxm|FXM|viv|rm|ram|yuv|mov|MOV|qt|QT|wmv|mp[234]|MP[234]|m4[pv]|M4[PV]|mkv|MKV|og[gmv]|OG[GMV]|t[ps]|T[PS]|m2t?(s)|M2T?(S)|wav|WAV|flac|FLAC|asx|ASX|mng|MNG|srt|m[eo]d|M[EO]D|s[3t]m|S[3T]M|it|IT|xm|XM)|+([0-9])[email protected](vdr|VDR))?(.part)" [xpdf]="!*.[pf]df" [gqmpeg]="!*[email protected](mp3|ogg|pls|m3u)" [lzegrep]="!*[email protected](tlz|lzma)" [aviplay]="!*[email protected](avi|asf|wmv)" [latex]="!*[email protected](?(la)tex|texi|dtx|ins|ltx|dbj)" [rvim]="*[email protected](o|so|so.!(conf|*/*)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [bunzip2]="!*.?(t)bz?(2)" [ogg123]="!*[email protected](ogg|m3u|flac|spx)" [ps2pdfwr]="!*[email protected](?(e)ps|pdf)" [znew]="*.Z" [harbour]="!*[email protected]([Pp][Rr][Gg]|[Cc][Ll][Pp])" [lokalize]="!*.po" [kate]="*[email protected](o|so|so.!(conf|*/*)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [xemacs]="*[email protected](o|so|so.!(conf|*/*)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [dragon]="!*@([email protected](mp?(e)g|MP?(E)G|wma|avi|AVI|asf|vob|VOB|bin|dat|divx|DIVX|vcd|ps|pes|fli|flv|FLV|fxm|FXM|viv|rm|ram|yuv|mov|MOV|qt|QT|wmv|mp[234]|MP[234]|m4[pv]|M4[PV]|mkv|MKV|og[gmv]|OG[GMV]|t[ps]|T[PS]|m2t?(s)|M2T?(S)|wav|WAV|flac|FLAC|asx|ASX|mng|MNG|srt|m[eo]d|M[EO]D|s[3t]m|S[3T]M|it|IT|xm|XM|iso|ISO)|+([0-9])[email protected](vdr|VDR))?(.part)" [unlzma]="!*[email protected](tlz|lzma)" [pdflatex]="!*[email protected](?(la)tex|texi|dtx|ins|ltx|dbj)" [vi]="*[email protected](o|so|so.!(conf|*/*)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [mozilla-firefox]="!*[email protected](?([xX]|[sS])[hH][tT][mM]?([lL]))" [ooimpress]="!*[email protected](sxi|sti|pps?(x)|ppt?([mx])|pot?([mx])|?(f)odp|otp)" [gvim]="*[email protected](o|so|so.!(conf|*/*)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [uncompress]="!*.Z" [kid3-qt]="!*[email protected](mp[234c]|og[ag]|@(fl|a)ac|m4[abp]|spx|tta|w?(a)v|wma|aif?(f)|asf|ape)" [xanim]="!*[email protected](mpg|mpeg|avi|mov|qt)" [unpigz]="!*[email protected](Z|[gGd]z|t[ag]z)" [portecle]="[email protected](*[email protected](ks|jks|jceks|p12|pfx|bks|ubr|gkr|cer|crt|cert|p7b|pkipath|pem|p10|csr|crl)|cacerts)" [oocalc]="!*[email protected](sxc|stc|xls?([bmx])|xlw|xlt?([mx])|[ct]sv|?(f)ods|ots)" [emacs]="*[email protected](o|so|so.!(conf|*/*)|a|[rs]pm|gif|jp?(e)g|mp3|mp?(e)g|avi|asf|ogg|class)" [fbxine]="!*@([email protected](mp?(e)g|MP?(E)G|wma|avi|AVI|asf|vob|VOB|bin|dat|divx|DIVX|vcd|ps|pes|fli|flv|FLV|fxm|FXM|viv|rm|ram|yuv|mov|MOV|qt|QT|wmv|mp[234]|MP[234]|m4[pv]|M4[PV]|mkv|MKV|og[gmv]|OG[GMV]|t[ps]|T[PS]|m2t?(s)|M2T?(S)|wav|WAV|flac|FLAC|asx|ASX|mng|MNG|srt|m[eo]d|M[EO]D|s[3t]m|S[3T]M|it|IT|xm|XM)|+([0-9])[email protected](vdr|VDR))?(.part)" [lynx]="!*[email protected](?([xX]|[sS])[hH][tT][mM]?([lL]))" [ps2pdf]="!*[email protected](?(e)ps|pdf)" [kpdf]="!*[email protected](?(e)ps|pdf)" [oomath]="!*[email protected](sxm|smf|mml|odf)" [compress]="*.Z" [iceweasel]="!*[email protected](?([xX]|[sS])[hH][tT][mM]?([lL]))" [mpg321]="!*.mp3" [mpg123]="!*.mp3" [zcat]="!*[email protected](Z|[gGd]z|t[ag]z)" [unzip]="!*[email protected](zip|[ejsw]ar|exe|pk3|wsz|zargo|xpi|s[tx][cdiw]|sx[gm]|o[dt][tspgfc]|od[bm]|oxt|epub|apk|do[ct][xm]|p[op]t[mx]|xl[st][xm])" [pbunzip2]="!*.?(t)bz?(2)" [kid3]="!*[email protected](mp[234c]|og[ag]|@(fl|a)ac|m4[abp]|spx|tta|w?(a)v|wma|aif?(f)|asf|ape)" [pdfjadetex]="!*[email protected](?(la)tex|texi|dtx|ins|ltx|dbj)" [dvipdf]="!*.dvi" [gharbour]="!*[email protected]([Pp][Rr][Gg]|[Cc][Ll][Pp])" [modplug123]="!*[email protected](669|abc|am[fs]|d[bs]m|dmf|far|it|mdl|m[eo]d|mid?(i)|mt[2m]|okta|p[st]m|s[3t]m|ult|umx|wav|xm)" [dvipdfm]="!*.dvi" [oobase]="!*.odb" [texi2html]="!*.texi*" [zipinfo]="!*[email protected](zip|[ejsw]ar|exe|pk3|wsz|zargo|xpi|s[tx][cdiw]|sx[gm]|o[dt][tspgfc]|od[bm]|oxt|epub|apk|do[ct][xm]|p[op]t[mx]|xl[st][xm])" [epiphany]="!*[email protected](?([xX]|[sS])[hH][tT][mM]?([lL]))" [gunzip]="!*[email protected](Z|[gGd]z|t[ag]z)" [google-chrome]="!*[email protected](?([xX]|[sS])[hH][tT][mM]?([lL]))" [okular]="!*[email protected](okular|@(?(e|x)ps|?(E|X)PS|[pf]df|[PF]DF|dvi|DVI|cb[rz]|CB[RZ]|djv?(u)|DJV?(U)|dvi|DVI|gif|jp?(e)g|miff|tif?(f)|pn[gm]|p[bgp]m|bmp|xpm|ico|xwd|tga|pcx|GIF|JP?(E)G|MIFF|TIF?(F)|PN[GM]|P[BGP]M|BMP|XPM|ICO|XWD|TGA|PCX|epub|EPUB|odt|ODT|fb?(2)|FB?(2)|mobi|MOBI|g3|G3|chm|CHM)?(.?(gz|GZ|bz2|BZ2)))" [slitex]="!*[email protected](?(la)tex|texi|dtx|ins|ltx|dbj)" [galeon]="!*[email protected](?([xX]|[sS])[hH][tT][mM]?([lL]))" [bzme]="!*[email protected](zip|z|gz|tgz)" [xfig]="!*.fig" [xzcat]="!*[email protected](?(t)xz|tlz|lzma)" [timidity]="!*[email protected](mid?(i)|rmi|rcp|[gr]36|g18|mod|xm|it|x3m|s[3t]m|kar)" [dviselect]="!*.dvi" [xdvi]="!*[email protected](dvi|DVI)?([email protected](gz|Z|bz2))" )
78
colors=/root/.dircolors
79
flatpak_dirs=/root/.local/share/flatpak/exports/share/:/var/lib/flatpak/exports/share/
80
__HOSTNAME ()
81
{
82
local zero=0;
83
local ret=0;
84
local cur_word="$2";
85
if [ "$1" == "X" ]; then
86
return;
87
else
88
if [ "$1" == "match" ]; then
89
return 0;
90
else
91
if [ "$1" == "complete" ]; then
92
COMPREPLY=($(compgen -A hostname -- $cur_word));
93
fi;
94
fi;
95
fi;
96
return 0
97
}
98
...
99
<output has been truncated>
Copied!
set vs env
Long story short: set can see shell-local variables, env cannot.
As we have mentioned, shells can have variables of 2 types: locals, which are only accessible from the current shell, and (exported) environment variables, which are passed on to every executed program.
Since set is a built-in shell command, it also sees sees shell-local variables (including shell functions). env on the other hand is an independent executable; it only sees the variables that the shell passes to it, or environment variables
In bash like in any Bourne-like shell, set is the command to set options (shell configuration settings like -f, -C, -o noclobber...) and positional parameters ($1, $2...).
1
set [--abefhkmnptuvxBCEHPT] [-o option-name] [argument …]
2
set [+abefhkmnptuvxBCEHPT] [+o option-name] [argument …]
Copied!
Use - and + signs for enabling and disbaling options.Tryhelp set | less .
To see the current shell options use echo $- :
1
[[email protected] ~]# echo $-
2
himuBH
Copied!
For example -u treat unset variables as an error when substituting:
1
2
himBH
3
[email protected]:~# echo $VAR1
4
6
7
himuBH
8
[email protected]:~# echo $VAR1
9
-su: VAR1: unbound variable
10
11
12
himBH
Copied!
We can use set -o without any option to get the current state of shell options :
1
[[email protected] ~]# set -o
2
allexport off
3
braceexpand on
4
emacs on
5
errexit off
6
errtrace off
7
functrace off
8
hashall on
9
histexpand on
10
history on
11
ignoreeof off
12
interactive-comments on
13
keyword off
14
monitor on
15
noclobber off
16
noexec off
17
noglob off
18
nolog off
19
notify off
20
nounset off
21
onecmd off
22
physical off
23
pipefail off
24
posix off
25
privileged off
26
verbose off
27
vi off
28
xtrace off
Copied!
set +o turns off specified option and set -o turns it on .For example lets disable and enable History Storing with -o option:
1
[[email protected] ~]# set +o history
2
[[email protected] ~]# set -o | grep history
3
history off
4
[[email protected] ~]# set -o history
5
[[email protected] ~]# set -o | grep history
6
history on
Copied!
One of important options you might be asked for in the exam is noclobber, The noclobber option prevents you from overwriting existing files with the > operator (Discussed in next courses).
set is not for setting variables. Do not make mistake!
1
[[email protected] ~]# set VAR4="My Forth Variable"
2
[[email protected] ~]# echo $VAR4
3
Copied!
Set has lots of options which are used to change bash behaviour.

unset

unset command is used to unset any local environment variable temporarily:
1
[[email protected] ~]# VAR5="Linux Linux Linux"
2
[[email protected] ~]# echo $VAR5
3
Linux Linux Linux
4
[[email protected] ~]# unset VAR5
5
[[email protected] ~]# echo $VAR5
6
bash: VAR5: unbound variable
7
[[email protected] ~]# unset PATH
9
bash: ls: No such file or directory
Copied!
So set is not set, but unset is unset.
We can also use env VARNAME=VALUE and env -u VARNAME to set and unset a variable.

Understanding Bash History

History of all commands which are executed by all users are stored.History is maintained both in ram and in a file.bash_history. History which is maintained in ram, manipulated with the commandhistoryand environment variables. It is important to note that the history contained in ram is only written after a user logs out of his or her session.

history

history shows the current content of Bash's history list in memory for the current session.
1
[[email protected] ~]# history
2
1 dhclient -r
3
2 dhclient
4
3 seastatus
5
4 sestatus
6
5 vim /etc/sysconfig/selinux
7
6 setenforce 0
8
7 sestatus
9
8 reboot
10
9 cd /var/lib/ldap/
11
10 ls
12
11 ls -la
13
12 ls -lrth
14
13 ping 8.8.8.8
15
14 dhclient -r
16
15 shcli
17
16 dhclient
18
17 ping 8.8.8.8
19
18 sestatus
20
19 yum install openldap openldap-servers openldap-clients.x86_64
21
20 systemctl status slapd.service
22
<output has been trancuated>
Copied!
How many lines are stored in RAM version of History list? It is defined by HISTSIZE variable.
    HISTSIZE : This variable contains the maximum number of lines that be contained in the in-ram version of history.
1
[[email protected] ~]# env | grep -i histsize
2
HISTSIZE=1000
Copied!
and that would be 1000 lines! to see just 5 lines for example usehistory 5 .
Repeat previous command quickly(3 methods)
    1.
    Use the up arrow to view the previous command and press enter to execute it.
    2.
    Type !! and press enter from the command line.(or !!number )
    3.
    Press Control+P will display the previous command, press enter to execute it
Search the history(3 methods)
    1.
    Control+R: Press Control+R and type the keyword.
    2.
    !string Refers to the most recent command starting with string.
    3.
    !?string? Refers to the most recent command containing string (the ending ? is optional).
Clear all the previous history : Use history -c option.

~/.bash_history

When user closes shell , Bash will save its history list to the disk by appending the contained entries to his/her ~/.bash_history hidden file. ~/.bash_history is controlled by some variables:
    HISTFILE This variable contains the location of the history file. When bash is logged out of, the contents of the history command will be written to this file.
    HISTFILESIZE The variable contains the maximum number of lines that may be in the history file. When bash writes to the history file, the oldest commands that go over this maximum number will be deleted.
    it acts the same as HISTSIZE.
    HISTCONTROL This variable contains instructions for what should be ignored when added to the history file. has four settings:
1
Setting Name Setting Effect
2
Ignorespace When this setting is used, any line that begins with one or more spaces will not be added to the history.
3
Ignoredups When this setting is used lines that match the previous entry in the history are not saved.
4
Ignoreboth When this setting is used it implies the conditions of both ignoredups and ignorespace.
5
Not Defined If HISTCONTROL is not defined no conditions will be applied before the line is entered into the history
Copied!
To see the .bash_history hidden file we should use ls with -a switch:
1
[[email protected] ~]# ls -la | grep .bash_history
2
-rw-------. 1 root root 9779 Dec 9 14:29 .bash_history
Copied!
What about other users?
1
[[email protected] ~]# find /home/ -iname .bash_history
2
/home/payam/.bash_history
3
/home/ldapadm/.bash_history
4
/home/user1/.bash_history
5
/home/user2/.bash_history
Copied!
As an instance lets find out what user1 has done:
1
[[email protected] ~]# cat /home/user1/.bash_history
2
ls
3
exit
Copied!
He/she has done nothing:). .bash_history by default keeps 500 or 1000 of command which has been used.So we can go back to some thing we have done long time ago. history -c does not clear that and it remains after user log off, so if you don't like it you should remove it.

uname

uname command without any switch will print system information :
1
2
Linux
Copied!
Its syntax is like uname [OPTION] ... .For example-a, --allPrints all information:
1
[[email protected] ~]# uname -a
2
Linux centos7-1 3.10.0-693.el7.x86_64 #1 SMP Tue Aug 22 21:09:27 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux
Copied!
If -a (--all) is specified, the information is printed in the following order of individual options:
1
-s, --kernel-name Print the kernel name.
2
-n, --nodename Print the network node hostname.
3
-r, --kernel-release Print the kernel release.
4
-v, --kernel-version Print the kernel version.
5
-m, --machine Print the machine hardware name.
6
-p, --processor Print the processor type, or "unknown".
7
-i, --hardware-platform Print the hardware platform, or "unknown".
8
-o, --operating-system Print the operating system.
9
--help Display a help message, and exit.
10
--version Display version information, and exit.
Copied!
Processor information (-p) and Hardware-Platform(-i) are omitted if they are unknown.

man

In Unix-like operating systems, a man page (in full manual page) is a documentation for a terminal-based program/tool/utility (commonly known as a command). It contains:
    the name of the command
    syntax for using it
    a description
    options available
    author
    copyright
    related commands and ... .
To read a manual page for a Unix command, a user can type:
1
man <command_name>
Copied!
For example try man man :
By default, man typically uses a terminal pager program such as more or less to display its output.
The manual is generally split into eight or nine numbered sections, organized as follows :
    1.
    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), e.g. man(7), groff(7)
    8.
    System administration commands (usually only for root)
    9.
    Kernel routines [Non standard]
To make man display manual page from specific sections use man [section-num] [command/tool name] :
1
man 1 echo
Copied!
man will search for the desired manual pages within the index database caches. So there is no need to remember section numbers for manual entries .

mandb

mandb is used to initialise or manually update index database caches that are usually maintained by man. The caches contain information relevant to the current state of the manual page system and the information stored within them is used by the man-db utilities to enhance their speed and functionality.
the cache consistency check can be slow on systems with many manual pages installed, so mandb is not performed by default, and system administrators may wish to run mandb every week or so to keep the database caches fresh.
1
2
Purging old database entries in /usr/share/man...
3
mandb: warning: /usr/share/man/man8/fsck.fat.8.manpage-fix.gz: ignoring bogus filename
4
Processing manual pages under /usr/share/man...
5
Purging old database entries in /usr/share/man/hu...
6
Processing manual pages under /usr/share/man/hu...
7
Purging old database entries in /usr/share/man/de...
8
Processing manual pages under /usr/share/man/de...
9
Purging old database entries in /usr/share/man/ja...
10
11
...
12
13
0 man subdirectories contained newer manual pages.
14
0 manual pages were added.
15
0 stray cats were added.
16
0 old database entries were purged.
Copied!
Most useful man command options:
-f, --whatisDisplay a short description from the manual page
1
[[email protected] ~]# man -f ls
2
ls (1) - list directory contents
3
ls (1p) - list directory contents
Copied!
-w, --where, --location Don't actually display the manual pages, but do print of the source off files
1
[[email protected] ~]# man -w ls
2
/usr/share/man/man1/ls.1.gz
Copied!
-k, --apropos Equivalent to apropos. Search the short manual page descriptions for keywords and display any matches.
1
[[email protected] ~]# man -k echo
2
echo (1) - display a line of text
3
echo (1p) - write arguments to standard output
4
fcping (8) - Fibre Channel Ping (ELS ECHO) tool
5
l2ping (1) - Send L2CAP echo request and receive answer
6
lessecho (1) - expand metacharacters
7
pam_echo (8) - PAM module for printing text messages
8
ping (8) - send ICMP ECHO_REQUEST to network hosts
9
ping6 (8) - send ICMP ECHO_REQUEST to network hosts
Copied!

apropos

apropos command is used to search and display a short man page description of a command/program as follows.
1
[[email protected] ~]# apropos echo
2
echo (1) - display a line of text
3
echo (1p) - write arguments to standard output
4
fcping (8) - Fibre Channel Ping (ELS ECHO) tool
5
l2ping (1) - Send L2CAP echo request and receive answer
6
lessecho (1) - expand metacharacters
7
pam_echo (8) - PAM module for printing text messages
8
ping (8) - send ICMP ECHO_REQUEST to network hosts
9
ping6 (8) - send ICMP ECHO_REQUEST to network hosts
Copied!
That is all!
.
.
.
sources:
.
Last modified 1yr ago