User Tools

Site Tools


linux:rhcsa:chap3

Chapter 03: Fundamental Command Line Skills

Preamble

The course material explains some pretty basic stuff like cd, pwd, ls and the like. So I will probably not cover every subchapter.

Shells

The default shell is bash.
Other shells can easily installed with yum.

other Shells

name Description
bash The default Bourne-Again shell.
dash A simpler shell with fewer features than bash, but faster.
tcsh An enhanced version of the Unix C shell.
zsh A sophisticated shell, similar to the korn shell.

The default shell of a specific user can be changed in /etc/passwd.

Terminal Consoles

By default, six command line consoles are available on RHEL systems.
If a GUI is installed it takes /dev/tty1.

These settings, including the x tty can be changed in:

  • /etc/init/start-ttys.conf

Active consoles are defined as device files /dev/tty1 through /dev/tty6.

Changing ttys

Usually you can access the consoles with ALT-F1 - F6. However, on RHEL Systems with a GUI Alt-F2 is used to start the Run Application tool; therefore, you'll need to press CTRL-ALT-F2 to move to that second virtual console.

Graphical Consoles

If a Desktop Environment like GNOME or KDE is installed you usually have some graphical terminals as well.
The upside of graphical environments are features like tabs, windows, copy and paste etc.

Differences Between Regular and Administrative Users

Regular user:

[user@host ~]$

Administrative User:

[root@host ~]#

Difference:

#

Text Streams and Command Redirection

Linux uses three basic data streams. stdin, stdout and stderr. You can redirect these streams to or from a file.

stdin

# database < datafile

Standard input can come from the left side of a command as well. For example, if you need to srcoll through the boot messages, you can combine the dmesg and *less commands with a pipe:

# dmesg | less

The output from dmesg is redirected as standard input to less.

stdout

# ls > filelist

To append the output to a file use:

# ls >> filelist
#
# Or to be sure:
# ls >\> filelist

stderr

# program 2> err-list

Standard Command Line Tools

File and Directory concepts

Environment PATHs

(~) skull@dc:$ echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/bin:/bin:/usr/bin:/usr/local/sbin:/usr/sbin:/sbin:/data/skull/bin:/data/skull/scripts

(~) root@dc:# echo $PATH
/usr/lib64/qt-3.3/bin:/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin:/root/bin

File Creation Commands

ln

ln creates a link in the file system. There are two kinds of links: soft links and hard links.

The difference:

  • Hard links include a copy of the file. As long as the hard link is made within the same partition, the inode numbers are identical. That means if you delete the original, the link is removed as well.
  • Soft links only create a redirect. That means, if you delete the original, the link is there and just points to no valid file any more.

To create a hard link:

# ln /etc/samba/smb.conf ~/smb.conf

To create a soft link:

# ln -s /etc/samba/smb.conf ~/.smb.conf

File Searches

find

Example:

# find / -name named.conf

This search can take some time, because the parameter '/' tells find to start search in the root directory.
To specify another directory just use:

# find /usr -name named.conf

If you don't know the name of the file you can use wildards.

Wildcards:
Wildcard Description
* Any. That means any alphanumeric character.
? One. One single alphanumeric character.
[] Range. A Range of options. For example, the ls ab[123] command would return the following filenames: ab1, ab2, ab3.

locate

For a faster file search you should use locate. It is installed on common RHEL System. If not:

# yum install mlocate

Usage:

# locate filename.txt

Locate uses a database which gets updated once a day. To update the database manually use:

# /etc/cron.daily/mlocate.cron

Or alternatively:

# updatedb

The Management of Text Files

Most files in Linux are text files. To actually look up the filetype use the file command.

(~) root@dc:# file /etc/samba/smb.conf
/etc/samba/smb.conf: UTF-8 Unicode English text

Commands to Process Text Streams

cat

Prints the whole file.

less and more

less and more display the content of a file on the screen and separates it into pages.

Commands
Command Description
space One page forward.
pgup and pgdown Navigate through the pages.
/something Searches for 'something'. Navigate through the results with n and N like in vi.
q Quit.

One of the advantages of less over more is that less can actually read compressed files in .tar.gz archives.

Local Online Documentation

A Networking Primer

Network Configuration and Troubleshooting

linux/rhcsa/chap3.txt · Last modified: 2013/03/01 16:06 by skull@darktemple.ch