[el7_blog]
/dev/urandom

Red Hat Certified System Administrator

Download CentOS Linux ISO images

[Executing Commands]
The purpose of the Linux shell is that it provides an environment in which commands can be executed. The shell takes care of interpreting the command that a user has entered correctly. To do this, the shell makes a difference between three kinds of commands:

  • Aliases
  • Internal Commands
  • External Commands


An alias is a command that a user can define as needed. Some aliases are provided by default; type alias on the command line to get an overview. To define an alias, use alias newcommand='oldcommand', as in the default alias alias ll='ls -l --color=auto'. Aliases are executed before anything else.


# alias
alias cp='cp -i'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l.='ls -d .* --color=auto'
alias ll='ls -l --color=auto'
alias ls='ls --color=auto'
alias mv='mv -i'
alias rm='rm -i'
alias which='alias | /usr/bin/which --tty-only --read-alias --show-dot --show-tilde'


An internal command is a command that is a part of the shell itself. It is available when the shell is loaded and can be executed from memory without any lookup from disk. An external command is a command that exists as an executable file on disk of the computer. Because it has to be read from disk, it is a bit slower. When a user executes a command, the shell first looks to determine whether it is an internal command; if it is not, it looks for an executable file with a name that matches the command on disk. To find out whether a command is a bash internal, or an executable file on disk, you can use the type command.

To look up external commands, the $PATH variable is used. This variable defines a list of directories that is searched for a matching filename when a user enters a command. To find out which exact command the shell will be using, you can use the which command. For instance, type which ls to find out where the shell will get the ls command from.

Internal Command - A command that is a part of the shell and does not exist as a file on disk.

External Command - A command that exists as a file on disk.

You should notice that for security reasons that the current directory is not in the $PATH variable and that Linux does not look in the current directory to see whether a specific command is available from that directory. That is why you need to start a command that is in the current directory but nowhere in the $PATH by including ./ in front of it. The dot stands for the current directory, and by running it as ./, you’re telling bash to look for the command in the current directory.

The $PATH variable can be set for specific users, but in general, most users will be using the same PATH variable. The only exception to this is the user root, who needs access to specific administration commands.

[I/O Redirection]


If you run a command, that command would expect input from the keyboard, and it would normally send its output to the monitor of your computer without making a difference between normal output and errors. Some commands, however, are started at the background and not from a current terminal session, so these commands do not have a monitor or console session to send their output to, and they do not listen to keyboard input to accept their standard input. That is where redirection comes in handy.

Programs started from the command line have no idea what they are reading from or writing to. They just read from File Descriptor 0 if they want to read from standard input, and they write to File Descriptor 1 to display output and to File Descriptor 2 if they have error messages to be output. By default, these are connected to the keyboard and the screen. If you use redirection symbols such as <, >, and |, the shell connects the file descriptors to files or other commands.


In I/O redirection, files can be used to replace the default STDIN, STDOUT, and STDERR. You can also redirect to device files. A device file on Linux is a file that is used to access specific hardware. Your hard disk for instance can be referred to as /dev/sda, the console of your server is known as /dev/console or /dev/tty1, and if you want to discard a commands output, you can redirect to /dev/null. Notice that to access most device files you need to be root.

[Using Pipes]
Where an I/O redirector is used to use alternatives for keyboard and computer monitor, a pipe| can be used to catch the output of one command and use that as input for a second command. If a user runs the command ls, for instance, the output of the command is shown onscreen. If the user uses ls | less, the commands ls and less are started in parallel. The standard output of the ls command is connected to the standard input of less. Everything that ls writes to the standard output will become available for read from standard input in less. The result is that the output of ls is shown in a pager, where the user can browse up and down through the results easily.