> For the complete documentation index, see [llms.txt](https://predator-os.gitbook.io/predator-os-beginner-guide-book/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://predator-os.gitbook.io/predator-os-beginner-guide-book/chapter-6.md).

# Chapter 6

![](/files/dBqSie509BW7Q0xbc2vS)

### Chapter 6 <a href="#toc171119896" id="toc171119896"></a>

### Linux Fundamental <a href="#toc171119897" id="toc171119897"></a>

This chapter takes look at the most common directories in the **Linux file tree.** It also shows that on Unix everything is a fil&#x65;**.**

### filesystem hierarchy standard <a href="#toc171119898" id="toc171119898"></a>

Many Linux distributions partially follow the **Filesystem Hierarchy Standard.** The **FHS** may help make more Uni&#x78;**/**&#x4C;inux file system trees conform better in the futur&#x65;**.** The **FHS** is available online at **<http://www.pathname.com/fhs/>** where we rea&#x64;**:** **“**&#x54;he filesystem hierarchy standard has been designed to be used by Unix distribution developer&#x73;**,** package developer&#x73;**,** and system implementer&#x73;**.** Howeve&#x72;**,** it is primarily intended to be a reference and is not a tutorial on how to manage a Unix filesystem or directory hierarch&#x79;**.”**

### The root directory / <a href="#toc171119899" id="toc171119899"></a>

All Linux systems have a directory structure that starts at the **root directory.** The root directory is represented by a **forward slash,** like thi&#x73;**:** **/.** Everything that exists on your Linux system can be found below this root director&#x79;**.** Le&#x74;**’**&#x73; take a brief look at the contents of the root director&#x79;**.**

\[use&#x72;**@**&#x50;redato&#x72;**-**&#x70;c]**$** ls **/**

*bin dev home media mnt proc sbin srv tftpboot usr boot etc lib misc opt root selinux sys tmp var*

### Binary directories <a href="#toc171119900" id="toc171119900"></a>

**Binaries** are files that contain compiled source code **(**&#x6F;r machine cod&#x65;**).** Binaries can be **executed** on the compute&#x72;**.** Sometimes binaries are called **executables.**

### /bin <a href="#toc171119901" id="toc171119901"></a>

The **/bin** directory contains **binaries** for use by all user&#x73;**.** According to the FHS the **/bin** directory should contain **/bin/cat** and **/bin/date** **(**&#x61;mong other&#x73;**).** you see common Uni&#x78;**/**&#x4C;inux commands like ca&#x74;**,** c&#x70;**,** cpi&#x6F;**,** dat&#x65;**,** d&#x64;**,** ech&#x6F;**,** gre&#x70;**,** and so o&#x6E;**.** Many of these will be covered in this boo&#x6B;**.**

use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$** ls **/**&#x62;in

archdetect egrep mt setupcon autopartition false m&#x74;**-**&#x67;nu sh bash fgconsole mv s&#x68;**.**&#x64;istrib bunzip2 fgrep nano sleep bzcat fuser nc stralign bzcmp fusermount n&#x63;**.**&#x74;raditional stty bzdiff ge&#x74;**\_**&#x6D;ountoptions netcat su bzegrep grep netstat sync bzexe gunzip ntf&#x73;**-**&#x33;g sysfs bzfgrep gzexe ntf&#x73;**-**&#x33;&#x67;**.**&#x70;robe tailf bzgrep gzip parte&#x64;**\_**&#x64;evices tar bzip2 hostname parte&#x64;**\_**&#x73;erver tempfile bzip2recover h&#x77;**-**&#x64;etect partman touch bzless ip partma&#x6E;**-**&#x63;ommit true bzmore kb&#x64;**\_**&#x6D;ode perfor&#x6D;**\_**&#x72;ecipe ulockmgr cat kill pidof umount **...**

### Other /bin directories <a href="#toc171119902" id="toc171119902"></a>

You can find a **/bin subdirectory** in many other directorie&#x73;**.** A user named **serena** could put her own programs in **/home/serena/bin.**

Some application&#x73;**,** often when installed directly from source will put themselves in **/opt.** A **samba server** installation can use **/opt/samba/bin** to store its binarie&#x73;**.**

### /sbin <a href="#toc171119903" id="toc171119903"></a>

**/sbin** contains binaries to configure the operating syste&#x6D;**.** Many of the **system binaries** require **root** privilege to perform certain task&#x73;**.**

Below a screenshot containing **system binaries** to change the ip addres&#x73;**,** partition a disk and create an ext4 file syste&#x6D;**.**

use&#x72;**@** predato&#x72;**-**&#x70;&#x63;**:\~$** ls **-**&#x6C; **/**&#x73;bi&#x6E;**/**&#x69;fconfig **/**&#x73;bi&#x6E;**/**&#x66;disk **/**&#x73;bi&#x6E;**/**&#x6D;kf&#x73;**.**&#x65;xt4

**-**&#x72;wx&#x72;**-**&#x78;&#x72;**-**&#x78; 1 root root 97172 201&#x31;**-**&#x30;&#x32;**-**&#x30;2 0&#x39;**:**&#x35;6 **/**&#x73;bi&#x6E;**/**&#x66;disk

**-**&#x72;wx&#x72;**-**&#x78;&#x72;**-**&#x78; 1 root root 65708 201&#x30;**-**&#x30;&#x37;**-**&#x30;2 0&#x39;**:**&#x32;7 **/**&#x73;bi&#x6E;**/**&#x69;fconfig **-**&#x72;wx&#x72;**-**&#x78;&#x72;**-**&#x78; 5 root root 55140 201&#x30;**-**&#x30;&#x38;**-**&#x31;8 1&#x38;**:**&#x30;1 **/**&#x73;bi&#x6E;**/**&#x6D;kf&#x73;**.**&#x65;xt4

### /lib <a href="#toc171119904" id="toc171119904"></a>

Binaries found in **/bin** and **/sbin** often use **shared libraries** located in **/lib.** Below is a screenshot of the partial contents of **/lib.**

use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$** ls **/**&#x6C;i&#x62;**/**&#x6C;ib&#x63;**\***

**/**&#x6C;i&#x62;**/**&#x6C;ib&#x63;**-**&#x32;**.**&#x35;**.**&#x73;o **/**&#x6C;i&#x62;**/**&#x6C;ibcfon&#x74;**.**&#x73;&#x6F;**.**&#x30;**.**&#x30;**.**&#x30; **/**&#x6C;i&#x62;**/**&#x6C;ibco&#x6D;**\_**&#x65;r&#x72;**.**&#x73;&#x6F;**.**&#x32;**.**&#x31;

**/**&#x6C;i&#x62;**/**&#x6C;ibca&#x70;**.**&#x73;&#x6F;**.**&#x31; **/**&#x6C;i&#x62;**/**&#x6C;ibcid&#x6E;**-**&#x32;**.**&#x35;**.**&#x73;o **/**&#x6C;i&#x62;**/**&#x6C;ibconsol&#x65;**.**&#x73;&#x6F;**.**&#x30;

**/**&#x6C;i&#x62;**/**&#x6C;ibca&#x70;**.**&#x73;&#x6F;**.**&#x31;**.**&#x31;0 **/**&#x6C;i&#x62;**/**&#x6C;ibcid&#x6E;**.**&#x73;&#x6F;**.**&#x31; **/**&#x6C;i&#x62;**/**&#x6C;ibconsol&#x65;**.**&#x73;&#x6F;**.**&#x30;**.**&#x30;**.**&#x30; **/**&#x6C;i&#x62;**/**&#x6C;ibcfon&#x74;**.**&#x73;&#x6F;**.**&#x30; **/**&#x6C;i&#x62;**/**&#x6C;ibco&#x6D;**\_**&#x65;r&#x72;**.**&#x73;&#x6F;**.**&#x32; **/**&#x6C;i&#x62;**/**&#x6C;ibcryp&#x74;**-**&#x32;**.**&#x35;**.**&#x73;o

### /lib/modules <a href="#toc171119905" id="toc171119905"></a>

Typicall&#x79;**,** the **Linux kernel** loads kernel modules from **/lib/modules/$kernelversion/.** This directory is discussed in detail in the Linux kernel chapte&#x72;**.**

### /lib32 and /lib64 <a href="#toc171119906" id="toc171119906"></a>

We currently are in a transition between **32-bit** and **64-bit** system&#x73;**.** Therefor&#x65;**,** you may encounter directories named **/lib32** and **/lib64** which clarify the register size used during compilation time of the librarie&#x73;**.** A 6&#x34;**-**&#x62;it computer may have some 3&#x32;**-**&#x62;it binaries and libraries for compatibility with legacy application&#x73;**.** This screenshot uses the **file** utility to demonstrate the differenc&#x65;**.**

use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$** file **/**&#x6C;ib3&#x32;**/**&#x6C;ib&#x63;**-**&#x32;**.**&#x35;**.**&#x73;o

**/**&#x6C;ib3&#x32;**/**&#x6C;ib&#x63;**-**&#x32;**.**&#x35;**.**&#x73;&#x6F;**:** ELF 3&#x32;**-**&#x62;it LSB shared objec&#x74;**,** Intel 8038&#x36;**,** **\\** version 1 **(**&#x53;YS&#x56;**),** for GN&#x55;**/**&#x4C;inux &#x32;**.**&#x36;**.**&#x30;**,** stripped use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$** file **/**&#x6C;ib6&#x34;**/**&#x6C;ibca&#x70;**.**&#x73;&#x6F;**.**&#x31;**.**&#x31;0

**/**&#x6C;ib6&#x34;**/**&#x6C;ibca&#x70;**.**&#x73;&#x6F;**.**&#x31;**.**&#x31;&#x30;**:** ELF 6&#x34;**-**&#x62;it LSB shared objec&#x74;**,** AMD x8&#x36;**-**&#x36;&#x34;**,** **\\** version 1 **(**&#x53;YS&#x56;**),** stripped

The ELF **(Executable and Linkable Format)** is used in almost every Uni&#x78;**-**&#x6C;ike operating system since **System V.**

### /opt <a href="#toc171119907" id="toc171119907"></a>

The purpose of **/opt** is to store **optional** softwar&#x65;**.** In many cases this is software from outside the distribution repositor&#x79;**.** You may find an empty **/opt** directory on many system&#x73;**.**

A large package can install all its files in **/bin,** **/lib,** **/etc** subdirectories within **/opt/ $packagename/.** If for example the package is called w&#x70;**,** then it installs in **/opt/wp,** putting binaries in **/opt/wp/bin** and manpages in **/opt/wp/man.**

### configuration directories <a href="#toc171119908" id="toc171119908"></a>

### /boot <a href="#toc171119909" id="toc171119909"></a>

The **/boot** directory contains all files needed to boot the compute&#x72;**.** These files do&#x6E;**’**&#x74; change very ofte&#x6E;**.** On Linux systems you typically find the **/boot/grub** directory her&#x65;**.** **/boot/grub** contains **/boot/grub/grub.cfg** **(**&#x6F;lder systems may still have **/boot/grub/grub.conf)** which defines the boot menu that is displayed before the kernel start&#x73;**.**

### /etc <a href="#toc171119910" id="toc171119910"></a>

All of the machin&#x65;**-**&#x73;pecific **configuration files** should be located in **/etc.** Historically **/etc** stood for **etcetera,** today people often use the **Editable Text Configuration** backrony&#x6D;**.**

Many times the name of a configuration files is the same as the applicatio&#x6E;**,** daemo&#x6E;**,** or protocol with **.conf** added as the extensio&#x6E;**.**

use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$** ls **/**&#x65;t&#x63;**/\*.**&#x63;onf

**/**&#x65;t&#x63;**/**&#x61;dduse&#x72;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x6C;&#x64;**.**&#x73;&#x6F;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x73;crollkeepe&#x72;**.**&#x63;onf

**/**&#x65;t&#x63;**/**&#x62;rltt&#x79;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x6C;ft&#x70;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x73;ysct&#x6C;**.**&#x63;onf

**/**&#x65;t&#x63;**/**&#x63;certificate&#x73;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x6C;iba&#x6F;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x73;yslo&#x67;**.**&#x63;onf

**/**&#x65;t&#x63;**/**&#x63;v&#x73;**-**&#x63;ro&#x6E;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x6C;ogrotat&#x65;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x75;c&#x66;**.**&#x63;onf

**/**&#x65;t&#x63;**/**&#x64;dclien&#x74;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x6C;trac&#x65;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x75;nicon&#x66;**.**&#x63;onf

**/**&#x65;t&#x63;**/**&#x64;ebcon&#x66;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x6D;ke2f&#x73;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x75;pdated&#x62;**.**&#x63;onf

**/**&#x65;t&#x63;**/**&#x64;eluse&#x72;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x6E;etscsi&#x64;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x75;splas&#x68;**.**&#x63;onf

**/**&#x65;t&#x63;**/**&#x66;dmoun&#x74;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x6E;sswitc&#x68;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x75;swsus&#x70;**.**&#x63;onf

**/**&#x65;t&#x63;**/**&#x68;dpar&#x6D;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x70;a&#x6D;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x76;n&#x63;**.**&#x63;onf

**/**&#x65;t&#x63;**/**&#x68;os&#x74;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x70;nm2pp&#x61;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x77;odi&#x6D;**.**&#x63;onf

**/**&#x65;t&#x63;**/**&#x69;net&#x64;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x70;ovra&#x79;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x77;vdia&#x6C;**.**&#x63;onf

**/**&#x65;t&#x63;**/**&#x6B;erne&#x6C;**-**&#x69;m&#x67;**.**&#x63;onf **/**&#x65;t&#x63;**/**&#x72;esol&#x76;**.**&#x63;onf use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$**

There is much more to be found in **/etc.**

### /etc/init.d/ <a href="#toc171119911" id="toc171119911"></a>

A lot of Uni&#x78;**/**&#x4C;inux distributions have an **/etc/init.d** directory that contains scripts to start and stop **daemons.** This directory could disappear as Linux migrates to systems that replace the old **init** way of starting all **daemons.**

### /etc/X11/ <a href="#toc171119912" id="toc171119912"></a>

The graphical display **(**&#x61;ka **X Window System** or just **X)** is driven by software from the &#x58;**.**&#x6F;rg foundatio&#x6E;**.** The configuration file for your graphical display is **/etc/X11/xorg.conf.** **/etc/skel/**

The **skeleton** directory **/etc/skel** is copied to the home directory of a newly created use&#x72;**.** It usually contains hidden files like a **.bashrc** scrip&#x74;**.**

### /etc/sysconfig/ <a href="#toc171119913" id="toc171119913"></a>

This director&#x79;**;** which is not mentioned in the FH&#x53;**,** contains a lot of Red Hat Enterprise Linux configuration file&#x73;**.** We will discuss some of them in greater detai&#x6C;**.**

**user\@Predator-pc:\~$** ls **/**&#x65;t&#x63;**/**&#x73;ysconfi&#x67;**/**

apmd firstboot irda network saslauthd apmscripts grub irqbalance networking selinux authconfig hidd keyboard ntpd spamassassin autofs httpd kudzu openi&#x62;**.**&#x63;onf squid bluetooth hwconf l&#x6D;**\_**&#x73;ensors pand syslog clock i18n mouse pcmcia sy&#x73;**-**&#x63;onfi&#x67;**-**&#x73;ec console init mous&#x65;**.**&#x42; pgsql sysconfi&#x67;**-**&#x75;sers crond installinfo named prelink syslogviewer

desktop ipmi netdump rawdevices tux diskdump iptables netdum&#x70;**\_**&#x69;&#x64;**\_**&#x64;sa rhn vncservers dund iptable&#x73;**-**&#x63;fg netdum&#x70;**\_**&#x69;&#x64;**\_**&#x64;s&#x61;**.**&#x70; samba xinetd **user\@Predator-pc:\~$**

The file **/etc/sysconfig/firstboot** tells the Red Hat Setup Agent not to run at boot tim&#x65;**.** If you want to run the Red Hat Setup Agent at the next reboo&#x74;**,** then simply remove this fil&#x65;**,** and run **chkconfig --level 5 firstboot on.** The Red Hat Setup Agent allows you to install the latest update&#x73;**,** create a user accoun&#x74;**,** join the Red Hat Network and mor&#x65;**.** It will then create the **/**&#x65;t&#x63;**/**&#x73;ysconfi&#x67;**/**&#x66;irstboot file agai&#x6E;**.**

user\@Predator-pc:\~$ cat /etc/sysconfig/firstboot RUN\_FIRSTBOOT=NO

The **/etc/sysconfig/harddisks** file contains some parameters to tune the hard disk&#x73;**.** The file explains itsel&#x66;**.**

You can see hardware detected by **kudzu** in **/etc/sysconfig/hwconf.** Kudzu is software from Red Hat for automatic discovery and configuration of hardwar&#x65;**.** The keyboard type and keymap table are set in the **/etc/sysconfig/keyboard** fil&#x65;**.** For more console keyboard informatio&#x6E;**,** check the manual pages of **keymaps(5),** **dumpkeys(1),** **loadkeys(1)** and the directory **/lib/kbd/keymaps/.**

| roo&#x74;**@**&#x50;redato&#x72;**-**&#x70;&#x63;**:/**&#x65;t&#x63;**/**&#x73;ysconfi&#x67;**#** cat keyboard |                                                                                                                  |   |
| -------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------- | - |
|                                                                                                                | <p>KEYBOARDTYPE=<strong>“</strong>pc<strong>”</strong></p><p>KEYTABLE=<strong>“</strong>us<strong>”</strong></p> |   |

We will discuss networking files in this directory in the networking chapte&#x72;**.** **data** directories

### /home <a href="#toc171119914" id="toc171119914"></a>

Users can store personal or project data under **/home.** It is common **(**&#x62;ut not mandatory by the fh&#x73;**)** practice to name the users home directory after the user name in the format **/home/ $USERNAME.** For exampl&#x65;**:**

Besides giving every user **(**&#x6F;r every project or grou&#x70;**)** a location to store personal file&#x73;**,** the home directory of a user also serves as a location to store the user profil&#x65;**.** A typical Unix user profile contains many hidden files **(**&#x66;iles whose file name starts with a do&#x74;**).** The hidden files of the Unix user profiles contain settings specific for that use&#x72;**.**

use&#x72;**@Predator-pc::\~$** ls **-**&#x64; **/**&#x68;om&#x65;**/**&#x75;se&#x72;**/.\***

**/**&#x68;om&#x65;**/**&#x75;se&#x72;**/.** **/**&#x68;om&#x65;**/**&#x75;se&#x72;**/.**&#x62;as&#x68;**\_**&#x70;rofile **/**&#x68;om&#x65;**/**&#x75;se&#x72;**/.**&#x73;sh

**/**&#x68;om&#x65;**/**&#x75;se&#x72;**/..** **/**&#x68;om&#x65;**/**&#x75;se&#x72;**/.**&#x62;ashrc **/**&#x68;om&#x65;**/**&#x75;se&#x72;**/.**&#x76;iminfo

**/**&#x68;om&#x65;**/**&#x75;se&#x72;**/.**&#x62;as&#x68;**\_**&#x68;istory **/**&#x68;om&#x65;**/**&#x75;se&#x72;**/.**&#x6C;esshst

### /root <a href="#toc171119915" id="toc171119915"></a>

On many systems **/root** is the default location for personal data and profile of the **root user.** If it does not exist by defaul&#x74;**,** then some administrators create i&#x74;**.**

### /srv <a href="#toc171119916" id="toc171119916"></a>

You may use **/srv** for data that is **served by your system.** The FHS allows locating cv&#x73;**,** rsyn&#x63;**,** ftp and www data in this locatio&#x6E;**.** The FHS also approves administrative naming in **/** sr&#x76;**,** like **/**&#x73;r&#x76;**/**&#x70;roject5&#x35;**/**&#x66;tp and **/**&#x73;r&#x76;**/**&#x73;ale&#x73;**/**&#x77;w&#x77;**.**

On Sun Solaris **(**&#x6F;r Oracle Solari&#x73;**)** **/export** is used for this purpos&#x65;**.**

### /media <a href="#toc171119917" id="toc171119917"></a>

The **/media** directory serves as a mount point for **removable media devices** such as CDRO&#x4D;**’**&#x73;**,** digital camera&#x73;**,** and various us&#x62;**-**&#x61;ttached device&#x73;**.** Since **/media** is rather new in the Unix worl&#x64;**,** you could very well encounter systems running without this director&#x79;**.** Solaris 9 does not have i&#x74;**,** Solaris 10 doe&#x73;**.** Most Linux distributions today mount all removable media in **/media.**

user\@predator:\~$ ls /media/ cdrom cdrom0 usbdisk

### /mnt <a href="#toc171119918" id="toc171119918"></a>

The **/mnt** directory should be empty and should only be used for temporary mount points **(**&#x61;ccording to the FH&#x53;**).**

Unix and Linux administrators used to create many directories her&#x65;**,** like **/**&#x6D;n&#x74;**/**&#x73;omethin&#x67;**/.** You likely will encounter many systems with more than one directory created an&#x64;**/**&#x6F;r mounted inside **/mnt** to be used for various local and remote filesystem&#x73;**.**

### /tmp <a href="#toc171119919" id="toc171119919"></a>

Applications and users should use **/tmp** to store temporary data when neede&#x64;**.** Data stored in **/tmp** may use either disk space or RA&#x4D;**.** Both of which are managed by the operating syste&#x6D;**.** Never use **/tmp** to store data that is important or which you wish to archiv&#x65;**.**

### in memory directories <a href="#toc171119920" id="toc171119920"></a>

### /dev <a href="#toc171119921" id="toc171119921"></a>

Device files in **/dev** appear to be ordinary files but are not actually located on the hard dis&#x6B;**.** The **/dev** directory is populated with files as the kernel is recognising hardwar&#x65;**.**

**common physical devices**

Common hardware such as hard disk devices are represented by device files in **/dev.** Below a screenshot of SATA device files on a laptop and then IDE attached drives on a deskto&#x70;**.** **(**&#x54;he detailed meaning of these devices will be discussed late&#x72;**.)**

**#**

**#** SATA or SCSI or USB

**#**

use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$** ls **/**&#x64;e&#x76;**/**&#x73;&#x64;**\*** **/**&#x64;e&#x76;**/**&#x73;da **/**&#x64;e&#x76;**/**&#x73;da1 **/**&#x64;e&#x76;**/**&#x73;da2 **/**&#x64;e&#x76;**/**&#x73;da3 **/**&#x64;e&#x76;**/**&#x73;db **/**&#x64;e&#x76;**/**&#x73;db1 **/**&#x64;e&#x76;**/**&#x73;db2

**#**

**#** IDE or ATAPI

**#**

use&#x72;**@**&#x62;arr&#x79;**:\~$** ls **/**&#x64;e&#x76;**/**&#x68;&#x64;**\***

**/**&#x64;e&#x76;**/**&#x68;da **/**&#x64;e&#x76;**/**&#x68;da1 **/**&#x64;e&#x76;**/**&#x68;da2 **/**&#x64;e&#x76;**/**&#x68;db **/**&#x64;e&#x76;**/**&#x68;db1 **/**&#x64;e&#x76;**/**&#x68;db2 **/**&#x64;e&#x76;**/**&#x68;dc

Besides representing physical hardwar&#x65;**,** some device files are specia&#x6C;**.** These special devices can be very usefu&#x6C;**.**

### /dev/tty and /dev/pts <a href="#toc171119922" id="toc171119922"></a>

For exampl&#x65;**,** **/dev/tty1** represents a terminal or console attached to the syste&#x6D;**.** **(**&#x44;o&#x6E;**’**&#x74; break your head on the exact terminology of **‘**&#x74;ermina&#x6C;**’** or **‘**&#x63;onsol&#x65;**’,** what we mean here is a command line interfac&#x65;**.)** When typing commands in a terminal that is part of a graphical interface like Gnome or KD&#x45;**,** then your terminal will be represented as **/dev/pts/1** **(**&#x31; can be another numbe&#x72;**).**

### /dev/null <a href="#toc171119923" id="toc171119923"></a>

On Linux you will find other special devices such as **/dev/null** which can be considered a black hol&#x65;**;** it has unlimited storag&#x65;**,** but nothing can be retrieved from i&#x74;**.** Technically speakin&#x67;**,** anything written to **/**&#x64;e&#x76;**/**&#x6E;ull will be discarde&#x64;**.** **/**&#x64;e&#x76;**/**&#x6E;ull can be useful to discard unwanted output from command&#x73;**.** ***/**&#x64;e&#x76;**/**&#x6E;ull is not a good location to store your backups **;-)*****.**

### /proc conversation with the kernel <a href="#toc171119924" id="toc171119924"></a>

**/proc** is another special director&#x79;**,** appearing to be ordinary file&#x73;**,** but not taking up disk spac&#x65;**.** It is actually a view of the kerne&#x6C;**,** or bette&#x72;**,** what the kernel manage&#x73;**,** and is a means to interact with it directl&#x79;**.** **/proc** is a proc filesyste&#x6D;**.**

**user\@Predator-pc:\~$** mount **-**&#x74; proc

none on /proc type proc (rw)

When listing the **/**&#x70;roc directory you will see many numbers **(**&#x6F;n any Uni&#x78;**)** and some interesting files **(**&#x6F;n Linu&#x78;**)**

use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$** ls **/**&#x70;roc

1 2339 4724 5418 6587 7201 cmdline mounts

10175 2523 4729 5421 6596 7204 cpuinfo mtrr

10211 2783 4741 5658 6599 7206 crypto net

10239 2975 4873 5661 6638 7214 devices pagetypeinfo

141 29775 4874 5665 6652 7216 diskstats partitions

15045 29792 4878 5927 6719 7218 dma sche&#x64;**\_**&#x64;ebug

1519 2997 4879 6 6736 7223 driver scsi

1548 3 4881 6032 6737 7224 execdomains self

1551 30228 4882 6033 6755 7227 fb slabinfo

1554 3069 5 6145 6762 7260 filesystems stat

1557 31422 5073 6298 6774 7267 fs swaps

1606 3149 5147 6414 6816 7275 ide sys

1. 31507 5203 6418 6991 7282 interrupts sysr&#x71;**-**&#x74;rigger
2. 3189 5206 6419 6993 7298 iomem sysvipc
3. 3193 5228 6420 6996 7319 ioports time&#x72;**\_**&#x6C;ist

18898 3246 5272 6421 7157 7330 irq time&#x72;**\_**&#x73;tats 19799 3248 5291 6422 7163 7345 kallsyms tty

1. 3253 5294 6423 7164 7513 kcore uptime
2. 3372 5356 6424 7171 7525 ke&#x79;**-**&#x75;sers version

1987 4 5370 6425 7175 7529 kmsg versio&#x6E;**\_**&#x73;ignature

1989 42 5379 6426 7188 9964 loadavg vmcore 2 45 5380 6430 7189 acpi locks vmnet

20845 4542 5412 6450 7191 asound meminfo vmstat

221 46 5414 6551 7192 buddyinfo misc zoneinfo

2338 4704 5416 6568 7199 bus modules

Le&#x74;**’**&#x73; investigate the file properties inside **/proc.** Looking at the date and time will display the current date and time showing the files are constantly updated **(**&#x61; view on the kerne&#x6C;**).**

**user\@Predator-pc:\~$** date Mon Jan 29 1&#x38;**:**&#x30;&#x36;**:**&#x33;2 EST 2007 **user\@Predator-pc:\~$** ls **-**&#x61;l **/**&#x70;ro&#x63;**/**&#x63;puinfo

**-**&#x72;**--**&#x72;**--**&#x72;**--** 1 root root 0 Jan 29 1&#x38;**:**&#x30;6 **/**&#x70;ro&#x63;**/**&#x63;puinfo **user\@Predator-pc:\~$** **user\@Predatorpc:\~$** **...**&#x74;ime passe&#x73;**...**

**user\@Predator-pc:\~$** **user\@Predatorpc:\~$** date

Mon Jan 29 1&#x38;**:**&#x31;&#x30;**:**&#x30;0 EST 2007 **user\@Predator-pc:\~$** ls **-**&#x61;l **/**&#x70;ro&#x63;**/**&#x63;puinfo

**-**&#x72;**--**&#x72;**--**&#x72;**--** 1 root root 0 Jan 29 1&#x38;**:**&#x31;0 **/**&#x70;ro&#x63;**/**&#x63;puinfo

Most files in **/**&#x70;roc are 0 byte&#x73;**,** yet they contain dat&#x61;**--**&#x73;ometimes a lot of dat&#x61;**.** You can see this by executing cat on files like **/proc/cpuinfo,** which contains information about the CP&#x55;**.**

**user\@Predator-pc:\~$** file **/**&#x70;ro&#x63;**/**&#x63;puinfo

**/**&#x70;ro&#x63;**/**&#x63;puinf&#x6F;**:** empty

**user\@Predator-pc:\~$** cat **/**&#x70;ro&#x63;**/**&#x63;puinfo processor **:** 0 vendo&#x72;**\_**&#x69;d **:** AuthenticAMD cpu family **:** 15 model

**:** 43

Just for fu&#x6E;**,** here is **/**&#x70;ro&#x63;**/**&#x63;puinfo on a Sun Sunblade 100&#x30;**...**

use&#x72;**@**&#x70;ash&#x61;**:\~$** cat **/**&#x70;ro&#x63;**/**&#x63;puinfo cpu **:** TI UltraSparc III **(**&#x43;heeta&#x68;**)** fpu **:** UltraSparc III integrated FPU promlib **:** Version 3 Revision 2 prom **:** &#x34;**.**&#x32;**.**&#x32; type **:** sun4u ncpus probed **:** 2 ncpus active **:** 2

Cpu0Bogo **:** 49&#x38;**.**&#x36;8

Cpu0ClkTck **:** 000000002cb41780 Cpu1Bogo **:** 49&#x38;**.**&#x36;8

Cpu1ClkTck **:** 000000002cb41780

MMU Type **:** Cheetah Stat&#x65;**:**

CPU&#x30;**:** online

CPU&#x31;**:** online

Most of the files in **/**&#x70;roc are read onl&#x79;**,** some require root privilege&#x73;**,** some files are writabl&#x65;**,** and many files in **/proc/sys** are writabl&#x65;**.** Le&#x74;**’**&#x73; discuss some of the files in **/**&#x70;ro&#x63;**.**

### /proc/interrupts <a href="#toc171119925" id="toc171119925"></a>

On the x86 architectur&#x65;**,** **/proc/interrupts** displays the interrupt&#x73;**.**

**user\@Predator-pc:\~$** cat **/**&#x70;ro&#x63;**/**&#x69;nterrupts

CPU0

&#x30;**:** 13876877 I&#x4F;**-**&#x41;PI&#x43;**-**&#x65;dge timer

&#x31;**:** 15 I&#x4F;**-**&#x41;PI&#x43;**-**&#x65;dge i8042

&#x38;**:** 1 I&#x4F;**-**&#x41;PI&#x43;**-**&#x65;dge rtc

&#x39;**:** 0 I&#x4F;**-**&#x41;PI&#x43;**-**&#x6C;evel acpi

1&#x32;**:** 67 I&#x4F;**-**&#x41;PI&#x43;**-**&#x65;dge i8042

1&#x34;**:** 128 I&#x4F;**-**&#x41;PI&#x43;**-**&#x65;dge ide0

1&#x35;**:** 124320 I&#x4F;**-**&#x41;PI&#x43;**-**&#x65;dge ide1

16&#x39;**:** 111993 I&#x4F;**-**&#x41;PI&#x43;**-**&#x6C;evel ioc0

17&#x37;**:** 2428 I&#x4F;**-**&#x41;PI&#x43;**-**&#x6C;evel eth0

NM&#x49;**:** 0

LO&#x43;**:** 13878037

ER&#x52;**:** 0

MI&#x53;**:** 0

On a machine with two CP&#x55;**’**&#x73;**,** the file looks like thi&#x73;**.**

use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$** cat **/**&#x70;ro&#x63;**/**&#x69;nterrupts

CPU0 CPU1

&#x30;**:** 860013 0 I&#x4F;**-**&#x41;PI&#x43;**-**&#x65;dge timer

&#x31;**:** 4533 0 I&#x4F;**-**&#x41;PI&#x43;**-**&#x65;dge i8042

&#x37;**:** 0 0 I&#x4F;**-**&#x41;PI&#x43;**-**&#x65;dge parport0

&#x38;**:** 6588227 0 I&#x4F;**-**&#x41;PI&#x43;**-**&#x65;dge rtc

1&#x30;**:** 2314 0 I&#x4F;**-**&#x41;PI&#x43;**-**&#x66;asteoi acpi

1&#x32;**:** 133 0 I&#x4F;**-**&#x41;PI&#x43;**-**&#x65;dge i8042

1&#x34;**:** 0 0 I&#x4F;**-**&#x41;PI&#x43;**-**&#x65;dge libata

1&#x35;**:** 72269 0 I&#x4F;**-**&#x41;PI&#x43;**-**&#x65;dge libata

1&#x38;**:** 1 0 I&#x4F;**-**&#x41;PI&#x43;**-**&#x66;asteoi yenta

1&#x39;**:** 115036 0 I&#x4F;**-**&#x41;PI&#x43;**-**&#x66;asteoi eth0

2&#x30;**:** 126871 0 I&#x4F;**-**&#x41;PI&#x43;**-**&#x66;asteoi libat&#x61;**,** ohci1394

2&#x31;**:** 30204 0 I&#x4F;**-**&#x41;PI&#x43;**-**&#x66;asteoi ehc&#x69;**\_**&#x68;c&#x64;**:**&#x75;sb&#x31;**,** uhc&#x69;**\_**&#x68;c&#x64;**:**&#x75;sb2

2&#x32;**:** 1334 0 I&#x4F;**-**&#x41;PI&#x43;**-**&#x66;asteoi saa7133\[0]**,** saa7133\[0]

2&#x34;**:** 234739 0 I&#x4F;**-**&#x41;PI&#x43;**-**&#x66;asteoi nvidia

NM&#x49;**:** 72 42

LO&#x43;**:** 860000 859994

ER&#x52;**:** 0

### /proc/kcore <a href="#toc171119926" id="toc171119926"></a>

The physical memory is represented in **/proc/kcore.** Do not try to cat this file instead use a debugge&#x72;**.** The size of **/**&#x70;ro&#x63;**/**&#x6B;core is the same as your physical memory plus four byte&#x73;**.**

use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$** ls **-**&#x6C;h **/**&#x70;ro&#x63;**/**&#x6B;core

**-**&#x72;**--------** 1 root root &#x32;**.**&#x30;G 200&#x37;**-**&#x30;&#x31;**-**&#x33;0 0&#x38;**:**&#x35;7 **/**&#x70;ro&#x63;**/**&#x6B;core use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$**

### /sys Linux hot plugging <a href="#toc171119927" id="toc171119927"></a>

The **/sys** directory was created for the Linux &#x32;**.**&#x36; kerne&#x6C;**.** Since &#x32;**.**&#x36;**,** Linux uses **sysfs** to support **usb** and **IEEE 1394** **(FireWire)** hot plug device&#x73;**.** See the manual pages of ude&#x76;**(**&#x38;**)** **(**&#x74;he successor of **devfs)** and hotplu&#x67;**(**&#x38;**)** for more info **(**&#x6F;r visit htt&#x70;**://**&#x6C;inuxhotplu&#x67;**.**&#x73;ourceforg&#x65;**.**&#x6E;e&#x74;**/** **).**

Basically the **/sys** directory contains kernel information about hardwar&#x65;**.**

### /usr Unix System Resources <a href="#toc171119928" id="toc171119928"></a>

Although **/usr** is pronounced like user remember that it stands for **Unix System Resources.** The **/usr** hierarchy should contain **shareable read only** dat&#x61;**.** Some people choose to mount **/usr** as read onl&#x79;**.** This can be done from its own partition or from a read only NFS share **(**&#x4E;FS is discussed late&#x72;**).**

### /usr/bin <a href="#toc171119929" id="toc171119929"></a>

The **/usr/bin** directory contains a lot of command&#x73;**.**

use&#x72;**@**&#x64;eb50&#x38;**:\~$** ls

**/**&#x75;s&#x72;**/**&#x62;in | wc **-**&#x6C; 1395

**(**&#x4F;n Solaris the **/bin** directory is a symbolic link to **/usr/bin.)**

### /usr/include <a href="#toc171119930" id="toc171119930"></a>

The **/usr/include** directory contains general use include files for &#x43;**.**

use&#x72;**@**&#x75;bu101&#x30;**:\~$** ls **/**&#x75;s&#x72;**/**&#x69;nclud&#x65;**/**

aali&#x62;**.**&#x68; expa&#x74;**\_**&#x63;onfi&#x67;**.**&#x68; mat&#x68;**.**&#x68; searc&#x68;**.**&#x68; a&#x66;**\_**&#x76;f&#x73;**.**&#x68; expa&#x74;**\_**&#x65;xterna&#x6C;**.**&#x68; mchec&#x6B;**.**&#x68; semaphor&#x65;**.**&#x68; ai&#x6F;**.**&#x68; expa&#x74;**.**&#x68; memor&#x79;**.**&#x68; setjm&#x70;**.** fcnt&#x6C;**.**&#x68; men&#x75;**.**&#x68; sgtt&#x79;**.**&#x68; aliase&#x73;**.** feature&#x73;**.**&#x68; mnten&#x74;**.**&#x68; shado&#x77;**.**&#x68; **...**

h AL

h

### /usr/lib <a href="#toc171119931" id="toc171119931"></a>

The **/usr/lib** directory contains libraries that are not directly executed by users or script&#x73;**.**

use&#x72;**@**&#x64;eb50&#x38;**:\~$** ls **/**&#x75;s&#x72;**/**&#x6C;ib | head **-**&#x37;

4Suite ao apt arj aspell avahi bonobo

### /usr/local <a href="#toc171119932" id="toc171119932"></a>

The **/usr/local** directory can be used by an administrator to install software locall&#x79;**.**

use&#x72;**@**&#x64;eb50&#x38;**:\~$** ls **/**&#x75;s&#x72;**/**&#x6C;oca&#x6C;**/**

bin etc games include lib man sbin share src use&#x72;**@**&#x64;eb50&#x38;**:\~$** du **-**&#x73;h **/**&#x75;s&#x72;**/**&#x6C;oca&#x6C;**/** 128K **/**&#x75;s&#x72;**/**&#x6C;oca&#x6C;**/**

### /usr/share <a href="#toc171119933" id="toc171119933"></a>

The **/usr/share** directory contains architecture independent dat&#x61;**.** As you can se&#x65;**,** this is a fairly large director&#x79;**.**

| use&#x72;**@**&#x64;eb50&#x38;**:\~$** ls **/**&#x75;s&#x72;**/**&#x73;har&#x65;**/** \| wc **-**&#x6C;                                                               |   |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------- | - |
| 263 use&#x72;**@**&#x64;eb50&#x38;**:\~$** du **-**&#x73;h **/**&#x75;s&#x72;**/**&#x73;har&#x65;**/** &#x31;**.**&#x33;G **/**&#x75;s&#x72;**/**&#x73;har&#x65;**/** |   |

This directory typically contains **/usr/share/man** for manual page&#x73;**.**

use&#x72;**@**&#x64;eb50&#x38;**:\~$** ls **/**&#x75;s&#x72;**/**&#x73;har&#x65;**/**&#x6D;an

cs fr hu i&#x74;**.**&#x55;T&#x46;**-**&#x38; man2 man6 p&#x6C;**.**&#x49;SO885&#x39;**-**&#x32; sv de f&#x72;**.**&#x49;SO885&#x39;**-**&#x31; id ja man3 man7 p&#x6C;**.**&#x55;T&#x46;**-**&#x38; tr es f&#x72;**.**&#x55;TF8 it ko man4 man8 p&#x74;**\_**&#x42;R z&#x68;**\_**&#x43;N fi gl i&#x74;**.**&#x49;SO885&#x39;**-**

1 man1 man5 pl ru z&#x68;**\_**&#x54;W

And it contains **/usr/share/games** for all static game data **(**&#x73;o no hig&#x68;**-**&#x73;cores or play log&#x73;**).**

use&#x72;**@**&#x75;bu101&#x30;**:\~$** ls

**/**&#x75;s&#x72;**/**&#x73;har&#x65;**/**&#x67;ame&#x73;**/**

### /usr/src <a href="#toc171119934" id="toc171119934"></a>

The **/usr/src** directory is the recommended location for kernel source file&#x73;**.**

use&#x72;**@**&#x64;eb50&#x38;**:\~$** ls **-**&#x6C; **/**&#x75;s&#x72;**/**&#x73;r&#x63;**/**

### /var variable data <a href="#toc171119935" id="toc171119935"></a>

Files that are unpredictable in size such as lo&#x67;**,** cache and spool file&#x73;**,** should be located in **/var.**

### /var/log <a href="#toc171119936" id="toc171119936"></a>

The **/var/log** directory serves as a central point to contain all log file&#x73;**.**

### set <a href="#toc171119937" id="toc171119937"></a>

You can use the **set** command to display a list of environment variable&#x73;**.** On Debian stable and Debian system&#x73;**,** the set command will also list shell functions after the shell variable&#x73;**.** Use set | more to see the variables the&#x6E;**.**

### unset <a href="#toc171119938" id="toc171119938"></a>

Use the **unset** command to remove a variable from your shell environmen&#x74;**.**

\[use&#x72;**@**&#x52;HEL4b **\~**]**$** MyVar=8472

\[use&#x72;**@**&#x52;HEL4b **\~**]**$** echo **$**&#x4D;yVar

8472

\[use&#x72;**@**&#x52;HEL4b **\~**]**$** unset MyVar

\[use&#x72;**@**&#x52;HEL4b **\~**]**$** echo **$**&#x4D;yVar

\[use&#x72;**@**&#x52;HEL4b **\~**]**$**

### PS1 <a href="#toc171119939" id="toc171119939"></a>

The **$PS1** variable determines your shell promp&#x74;**.** You can use backslash escaped special characters like **\u** for the username or **\w** for the working director&#x79;**.** The **bash** manual has a complete referenc&#x65;**.**

In this example we change the value of **$PS1** a couple of time&#x73;**.**

use&#x72;**@**&#x64;eb50&#x33;**:\~$** PS1=prompt prompt promptPS1=**‘**&#x70;rompt **‘** prompt prompt PS1=**‘>** **‘** **>**

**>** PS1=**‘\\**&#x75;**@\\**&#x68;**$** **‘** use&#x72;**@**&#x64;eb50&#x33;**$**

use&#x72;**@**&#x64;eb50&#x33;**$** PS1=**‘\\**&#x75;**@\\**&#x68;**:\\**&#x57;**$’** use&#x72;**@**&#x64;eb50&#x33;**:\~$**

To avoid unrecoverable mistake&#x73;**,** you can set normal user prompts to green and the root prompt to re&#x64;**.** Add the following to your **.bashrc** for a green user promp&#x74;**:**

**#** color prompt by user RED=**‘\\**\[**\\**&#x30;33\[0&#x31;**;**&#x33;1&#x6D;**\\**]**’**

WHITE=**‘\\**\[**\\**&#x30;33\[0&#x31;**;**&#x30;0&#x6D;**\\**]**’**

GREEN=**‘\\**\[**\\**&#x30;33\[0&#x31;**;**&#x33;2&#x6D;**\\**]**’** BLUE=**‘\\**\[**\\**&#x30;33\[0&#x31;**;**&#x33;4&#x6D;**\\**]**’** export

PS1=**“$**{debia&#x6E;**\_**&#x63;hroo&#x74;**:+($**&#x64;ebia&#x6E;**\_**&#x63;hroo&#x74;**)**}**$**&#x47;REE&#x4E;**\\**&#x75;**$**&#x57;HIT&#x45;**@$**&#x42;LU&#x45;**\\**&#x68;**$**&#x57;HIT&#x45;**\\**&#x77;**\\$** **“**

### $PATH <a href="#toc171119940" id="toc171119940"></a>

The **$PATH** variable is determines where the shell is looking for commands to execute **(**&#x75;nless the command is builtin or aliase&#x64;**).** This variable contains a list of directorie&#x73;**,** separated by colon&#x73;**.**

\[\[use&#x72;**@**&#x52;HEL4b **\~**]**$** echo **$**&#x50;ATH **/**&#x75;s&#x72;**/**&#x6B;erbero&#x73;**/**&#x62;i&#x6E;**:/**&#x75;s&#x72;**/**&#x6C;oca&#x6C;**/**&#x62;i&#x6E;**:/**&#x62;i&#x6E;**:/**&#x75;s&#x72;**/**&#x62;i&#x6E;**:**

The shell will not look in the current directory for commands to execut&#x65;**!** **(**&#x4C;ooking for executables in the current directory provided an easy way to hack P&#x43;**-**&#x44;OS computer&#x73;**).** If you want the shell to look in the current directory then add a **. (dot)** at the end of your **$**&#x50;AT&#x48;**.**

\[use&#x72;**@**&#x52;HEL4b **\~**]**$** PATH=**$**&#x50;AT&#x48;**:.**

\[use&#x72;**@**&#x52;HEL4b **\~**]**$** echo **$**&#x50;ATH **/**&#x75;s&#x72;**/**&#x6B;erbero&#x73;**/**&#x62;i&#x6E;**:/**&#x75;s&#x72;**/**&#x6C;oca&#x6C;**/**&#x62;i&#x6E;**:/**&#x62;i&#x6E;**:/**&#x75;s&#x72;**/**&#x62;i&#x6E;**:.** \[use&#x72;**@**&#x52;HEL4b **\~**]**$**

Your path might be different when using su instead of **su -** because the latter will take on the environment of the target use&#x72;**.** The root user typically has **/sbin** directories added to the **$**&#x50;ATH variabl&#x65;**.**

\[use&#x72;**@**&#x52;HEL3 **\~**]**$** su

Passwor&#x64;**:**

\[roo&#x74;**@**&#x52;HEL3 user]**#** echo **$**&#x50;ATH

**/**&#x75;s&#x72;**/**&#x6C;oca&#x6C;**/**&#x62;i&#x6E;**:/**&#x62;i&#x6E;**:/**&#x75;s&#x72;**/**&#x62;i&#x6E;**:/**&#x75;s&#x72;**/**&#x58;11R&#x36;**/**&#x62;in

\[roo&#x74;**@**&#x52;HEL3 user]**#** exit

\[use&#x72;**@**&#x52;HEL3 **\~**]**$** su Passwor&#x64;**:**

\[roo&#x74;**@**&#x52;HEL3 **\~**]**#** echo **$**&#x50;ATH

**/**&#x75;s&#x72;**/**&#x6C;oca&#x6C;**/**&#x73;bi&#x6E;**:/**&#x75;s&#x72;**/**&#x6C;oca&#x6C;**/**&#x62;i&#x6E;**:/**&#x73;bi&#x6E;**:/**&#x62;i&#x6E;**:/**&#x75;s&#x72;**/**&#x73;bi&#x6E;**:/**&#x75;s&#x72;**/**&#x62;i&#x6E;**:** \[roo&#x74;**@**&#x52;HEL3 **\~**]**#**

### env <a href="#toc171119941" id="toc171119941"></a>

The **env** command without options will display a list of **exported variables.** The difference with **set** with options is that **set** lists all variable&#x73;**,** including those not exported to child shell&#x73;**.**

But **env** can also be used to start a clean shell **(**&#x61; shell without any inherited environmen&#x74;**).** The **env -i** command clears the environment for the subshel&#x6C;**.** Notice in this screenshot that **bash** will set the **$SHELL** variable on startu&#x70;**.**

\[use&#x72;**@**&#x52;HEL4b **\~**]**$** bash **-**&#x63; **‘**&#x65;cho **$**&#x53;HELL **$**&#x48;OME **$**&#x55;SE&#x52;**’**

**/**&#x62;i&#x6E;**/**&#x62;ash **/**&#x68;om&#x65;**/**&#x75;ser user

\[use&#x72;**@**&#x52;HEL4b **\~**]**$** env **-**&#x69; bash **-**&#x63; **‘**&#x65;cho **$**&#x53;HELL **$**&#x48;OME **$**&#x55;SE&#x52;**’**

**/**&#x62;i&#x6E;**/**&#x62;ash

\[use&#x72;**@**&#x52;HEL4b **\~**]**$**

You can use the **env** command to set the **$LANG,** or any othe&#x72;**,** variable for just one instance of **bash** with one comman&#x64;**.** The example below uses this to show the influence of the **$LANG** variable on file globbing **(**&#x73;ee the chapter on file globbin&#x67;**).**

\[use&#x72;**@**&#x52;HEL4b test]**$** env LANG=C bash **-**&#x63; **‘**&#x6C;s File\[&#x61;**-**&#x7A;]**’**

Filea Fileb

\[use&#x72;**@**&#x52;HEL4b test]**$** env LANG=e&#x6E;**\_**&#x55;&#x53;**.**&#x55;T&#x46;**-**&#x38; bash **-**&#x63; **‘**&#x6C;s File\[&#x61;**-**&#x7A;]**’**

Filea FileA Fileb FileB \[use&#x72;**@**&#x52;HEL4b test]**$**

### export <a href="#toc171119942" id="toc171119942"></a>

You can export shell variables to other shells with the **export** comman&#x64;**.** This will export the variable to child shell&#x73;**.**

\[use&#x72;**@**&#x52;HEL4b **\~**]**$** var3=three

\[use&#x72;**@**&#x52;HEL4b **\~**]**$** var4=four

\[use&#x72;**@**&#x52;HEL4b **\~**]**$** export var4 \[use&#x72;**@**&#x52;HEL4b **\~**]**$** echo **$**&#x76;ar3 **$**&#x76;ar4 three four

\[use&#x72;**@**&#x52;HEL4b **\~**]**$** bash

\[use&#x72;**@**&#x52;HEL4b **\~**]**$** echo **$**&#x76;ar3 **$**&#x76;ar4 four

But it will not export to the parent shell **(**&#x70;revious screenshot continue&#x64;**).**

\[use&#x72;**@**&#x52;HEL4b **\~**]**$** export var5=five \[use&#x72;**@**&#x52;HEL4b **\~**]**$** echo **$**&#x76;ar3 **$**&#x76;ar4 **$**&#x76;ar5 four five

\[use&#x72;**@**&#x52;HEL4b **\~**]**$** exit exit

\[use&#x72;**@**&#x52;HEL4b **\~**]**$** echo **$**&#x76;ar3 **$**&#x76;ar4 **$**&#x76;ar5 three four \[use&#x72;**@**&#x52;HEL4b **\~**]**$**

### Licensing <a href="#toc171119943" id="toc171119943"></a>

### About software licenses <a href="#toc171119944" id="toc171119944"></a>

There are two predominant software paradigm&#x73;**:** **Free and Open Source Software** **(**&#x46;OS&#x53;**)** and **proprietary software.** The criteria for differentiation between these two approaches is based on control over the softwar&#x65;**.** With **proprietary software** control tends to lie more with the vendo&#x72;**,** while with **Free and Open Source Software** tends to be more weighted towards the end use&#x72;**.** But even though the paradigms diffe&#x72;**,** they use the same **copyright laws** to reach and enforce their goal&#x73;**.** From a legal perspectiv&#x65;**,** **Free and Open Source Software** can be considered as software to which users generally receive more rights via their license agreement than they would have with a **proprietary software license,** yet the underlying license mechanisms are the sam&#x65;**.**

Legal theory states that the author of FOS&#x53;**,** contrary to the author of **public domain** softwar&#x65;**,** has in no way whatsoever given up his rights on his wor&#x6B;**.** FOSS supports on the rights of the author **(**&#x74;he **copyright)** to impose FOSS license condition&#x73;**.** The FOSS license conditions need to be respected by the user in the same way as proprietary license condition&#x73;**.** Always check your license carefully before you use third party softwar&#x65;**.**

Examples of proprietary software are **AIX** from IB&#x4D;**,** **HP-UX** from HP and **Oracle Database 11g.** You are not authorised to install or use this software without paying a licensing fe&#x65;**.** You are not authorised to distribute copies and you are not authorised to modify the closed source cod&#x65;**.**

### Public domain software and freeware <a href="#toc171119945" id="toc171119945"></a>

Software that is original in the sense that it is an intellectual creation of the author benefits **copyright** protectio&#x6E;**.** No&#x6E;**-**&#x6F;riginal software does not come into consideration for **copyright** protection and ca&#x6E;**,** in principl&#x65;**,** be used freel&#x79;**.** Public domain software is considered as software to which the author has given up all rights and on which nobody is able to enforce any right&#x73;**.** This software can be use&#x64;**,** reproduced or executed freel&#x79;**,** without permission or the payment of a fe&#x65;**.** Public domain software can in certain cases even be presented by third parties as own wor&#x6B;**,** and by modifying the original wor&#x6B;**,** third parties can take certain versions of the public domain software out of the public domain agai&#x6E;**.**

**Freeware** is not public domain software or FOS&#x53;**.** It is proprietary software that you can use without paying a license cos&#x74;**.** Howeve&#x72;**,** the often-strict license terms need to be respecte&#x64;**.**

Examples of freeware are **Adobe Reader,** **Skype** and **Command and Conquer: Tiberian Sun** **(**&#x74;his game was sold as proprietary in 1999 and is since 2011 available as freewar&#x65;**).**

### Free Software or Open Source Software <a href="#toc171119946" id="toc171119946"></a>

Both the **Free Software** **(**&#x74;ranslates to **vrije software** in Dutch and to **Logiciel Libre** in Frenc&#x68;**)** and the **Open-Source Software** movement largely pursue similar goals and endorse similar software license&#x73;**.** But historicall&#x79;**,** there has been some perception of differentiation due to different emphase&#x73;**.** Where the **Free Software** movement focuses on the rights **(**&#x74;he four freedom&#x73;**)** which Free Software provides to its user&#x73;**,** the **Open Source Software** movement points to its Open Source Definition and the advantages of pee&#x72;**-**&#x74;&#x6F;**-**&#x70;eer software developmen&#x74;**.** Recentl&#x79;**,** the term free and open source software or FOSS has arisen as a neutral alternativ&#x65;**.** A lesse&#x72;**-**&#x75;sed variant is fre&#x65;**/**&#x6C;ibr&#x65;**/**&#x6F;pen source software **(**&#x46;LOS&#x53;**),** which uses **libre** to clarify the meaning of free as in **freedom** rather than as in **at no charge.**

Examples of **free software** are **gcc,** **MySQL** and **gimp.**

Detailed information about the **four freedoms** can be found her&#x65;**:**

htt&#x70;**://**&#x77;w&#x77;**.**&#x67;n&#x75;**.**&#x6F;r&#x67;**/**&#x70;hilosoph&#x79;**/**&#x66;re&#x65;**-**&#x73;&#x77;**.**&#x68;tml

The **open-source definition** can be found a&#x74;**:**

htt&#x70;**://**&#x77;w&#x77;**.**&#x6F;pensourc&#x65;**.**&#x6F;r&#x67;**/**&#x64;oc&#x73;**/**&#x6F;sd

The above definition is based on the **Debian Free Software Guidelines** available her&#x65;**:**

htt&#x70;**://**&#x77;w&#x77;**.**&#x64;ebia&#x6E;**.**&#x6F;r&#x67;**/**&#x73;ocia&#x6C;**\_**&#x63;ontrac&#x74;**#**&#x67;uidelines

### GNU General Public License <a href="#toc171119947" id="toc171119947"></a>

More and more software is being released under the **GNU GPL** **(**&#x69;n 2006 Java was released under the GP&#x4C;**).** This license **(**&#x76;2 and v&#x33;**)** is the main license endorsed by the Free Software Foundatio&#x6E;**.** I&#x74;**’**&#x73; main characteristic is the **copyleft** principl&#x65;**.** This means that everyone in the chain of consecutive user&#x73;**;** in return for the right of use that is assigne&#x64;**,** needs to distribute the improvements he makes to the software and his derivative works under the same conditions to other user&#x73;**,** if he chooses to distribute such improvements or derivative work&#x73;**.** In other word&#x73;**;** software which incorporates GNU GPL softwar&#x65;**,** needs to be distributed in turn as GNU GPL software **(**&#x6F;r compatibl&#x65;**,** see belo&#x77;**).** It is not possible to incorporate copyright protected parts of GNU GPL software in a proprietary licensed wor&#x6B;**.** The GPL has been upheld in cour&#x74;**.**

### Using GPLv3 software <a href="#toc171119948" id="toc171119948"></a>

You can use **GPLv3 software** almost without any condition&#x73;**.** If you solely run the softwar&#x65;**,** you even do&#x6E;**’**&#x74; have to accept the terms of the GPLv&#x33;**.** Howeve&#x72;**,** any other use **-** such as modifying or distributing the software **-** implies acceptanc&#x65;**.**

In case you use the software internally **(**&#x69;ncluding over a networ&#x6B;**),** you may modify the software without being obliged to distribute your modificatio&#x6E;**.** You may hire third parties to work on the software exclusively for you and under your direction and contro&#x6C;**.** But if you modify the software and use it otherwise than merely internall&#x79;**,** this will be considered as distributio&#x6E;**.** You must distribute your modifications under GPLv3 **(**&#x74;he copyleft principl&#x65;**).** Several more obligations apply if you distribute GPLv3 softwar&#x65;**.** Check the GPLv3 license carefull&#x79;**.** You create output with GPLv3 softwar&#x65;**:** The GPLv3 does not automatically apply to the outpu&#x74;**.**

### BSD license <a href="#toc171119949" id="toc171119949"></a>

There are several versions of the original Berkeley Distribution Licens&#x65;**.** The most common one is the &#x33;**-**&#x63;lause license **(“**&#x4E;ew BSD Licens&#x65;**”** or **“**&#x4D;odified BSD Licens&#x65;**”).**

This is a permissive free software licens&#x65;**.** The license places minimal restrictions on how the software can be redistribute&#x64;**.** This is in contrast to copyleft licenses such as the GPL&#x76;**.** 3 discussed abov&#x65;**,** which have a copyleft mechanis&#x6D;**.** This difference is of less importance when you merely use the softwar&#x65;**,** but kicks in when you start redistributing verbatim copies of the software or your own modified version&#x73;**.**

### Other licenses <a href="#toc171119950" id="toc171119950"></a>

FOSS or no&#x74;**,** there are many kind of licenses on softwar&#x65;**.** You should read and understand them before using any softwar&#x65;**.**

### Combination of software licenses <a href="#toc171119951" id="toc171119951"></a>

When you use several sources or wishes to redistribute your software under a different licens&#x65;**,** you need to verify whether all licenses are compatibl&#x65;**.** Some FOSS licenses **(**&#x73;uch as BS&#x44;**)** are compatible with proprietary license&#x73;**,** but most are no&#x74;**.** If you detect a license incompatibilit&#x79;**,** you must contact the author to negotiate different license conditions or refrain from using the incompatible softwar&#x65;**.**

### First steps on the command line man pages <a href="#toc171119952" id="toc171119952"></a>

This chapter will explain the use of **man** pages **(**&#x61;lso called **manual pages)** on your Unix or Linux compute&#x72;**.**

You will learn the **man** command together with related commands like **whereis,** **whatis** and **mandb.**

Most Unix files and commands have pretty good man pages to explain their us&#x65;**.** Man pages also come in handy when you are using multiple flavours of Unix or several Linux distributions since options and parameters sometimes var&#x79;**.**

### man $command <a href="#toc171119953" id="toc171119953"></a>

Type **man** followed by a command **(**&#x66;or which you want hel&#x70;**)** and start readin&#x67;**.** Press **q** to quit the manpag&#x65;**.** Some man pages contain examples **(**&#x6E;ear the en&#x64;**).**

use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$** man whois Reformatting whoi&#x73;**(**&#x31;**),** please wai&#x74;**...**

### man $configfile <a href="#toc171119954" id="toc171119954"></a>

Most **configuration files** have their own manua&#x6C;**.**

use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$** man syslo&#x67;**.**&#x63;onf Reformatting syslo&#x67;**.**&#x63;on&#x66;**(**&#x35;**),** please wai&#x74;**...**

### man $daemon <a href="#toc171119955" id="toc171119955"></a>

This is also true for most **daemons** **(**&#x62;ackground program&#x73;**)** on your syste&#x6D;**.**

use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$** man syslogd Reformatting syslog&#x64;**(**&#x38;**),** please wai&#x74;**...**

man -k (apropos) man -k (or apropos) shows a list of man pages containing a strin&#x67;**.**

use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$** man **-**&#x6B; syslog l&#x6D;**-**&#x73;yslo&#x67;**-**&#x73;etup **(**&#x38;**)** **-** configure laptop mode to switch syslo&#x67;**.**&#x63;onf **...** logger **(**&#x31;**)** **-** a shell command interface to the syslo&#x67;**(**&#x33;**)** **...** syslo&#x67;**-**&#x66;acility **(**&#x38;**)** **-** Setup and remove LOCALx facility for sysklogd syslo&#x67;**.**&#x63;onf **(**&#x35;**)** **-** syslog&#x64;**(**&#x38;**)** configuration file syslogd **(**&#x38;**)** **-** Linux system logging utilitie&#x73;**.** syslogdlistfiles **(**&#x38;**)** **-** list system logfiles

### whatis <a href="#toc171119957" id="toc171119957"></a>

To see just the description of a manual pag&#x65;**,** use **whatis** followed by a strin&#x67;**.**

use&#x72;**@**&#x75;81&#x30;**:\~$** whatis route

route **(**&#x38;**)** **-** show **/** manipulate the IP routing table

### whereis <a href="#toc171119958" id="toc171119958"></a>

The location of a manpage can be revealed with **whereis.**

use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$** whereis **-**&#x6D; whois whoi&#x73;**:** **/**&#x75;s&#x72;**/**&#x73;har&#x65;**/**&#x6D;a&#x6E;**/**&#x6D;an&#x31;**/**&#x77;hoi&#x73;**.**&#x31;**.**&#x67;z

This file is directly readable by **man.**

use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$** man **/**&#x75;s&#x72;**/**&#x73;har&#x65;**/**&#x6D;a&#x6E;**/**&#x6D;an&#x31;**/**&#x77;hoi&#x73;**.**&#x31;**.**&#x67;z

### man $section $file <a href="#toc171119959" id="toc171119959"></a>

Therefo&#x72;**,** when referring to the man page of the passwd comman&#x64;**,** you will see it written as **passwd(1);** when referring to the **passwd file,** you will see it written as **passwd(5).** The screenshot explains how to open the man page in the correct sectio&#x6E;**.**

\[use&#x72;**@**&#x52;HEL52 **\~**]**$** man passwd **#** opens the first manual found

\[use&#x72;**@**&#x52;HEL52 **\~**]**$** man 5 passwd **#** opens a page from section 5

### man man <a href="#toc171119960" id="toc171119960"></a>

If you want to know more about **man,** then Read The Fantastic Manual **(**&#x52;TF&#x4D;**).**

*Unfortunatel&#x79;**,** manual pages do not have the answer to everythin&#x67;**...***

use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$** man woman No manual entry for woman

### mandb <a href="#toc171119961" id="toc171119961"></a>

Should you be convinced that a man page exist&#x73;**,** but you ca&#x6E;**’**&#x74; access i&#x74;**,** then try running **mandb** on Debia&#x6E;**/**&#x4D;in&#x74;**.**

roo&#x74;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~#** mandb 0 man subdirectories contained newer manual page&#x73;**.**

0 manual pages were adde&#x64;**.**

0 stray cats were adde&#x64;**.**

0 old database entries were purge&#x64;**.**

Or run **makewhatis** on CentO&#x53;**/**&#x52;edha&#x74;**.**

\[roo&#x74;**@**&#x63;entos65 **\~**]**#** apropos scsi scs&#x69;**:** nothing appropriate

\[roo&#x74;**@**&#x63;entos65 **\~**]**#** makewhatis \[roo&#x74;**@**&#x63;entos65 **\~**]**#** apropos scsi hpsa **(**&#x34;**)** **-** HP Smart Array SCSI driver lsscsi **(**&#x38;**)** **-** list SCSI devices **(**&#x6F;r host&#x73;**)** and their attributes sd **(**&#x34;**)** **-** Driver for SCSI Disk Drives st **(**&#x34;**)** **-** SCSI tape device

### Working with directories <a href="#toc171119962" id="toc171119962"></a>

This module is a brief overview of the most common commands to work with directorie&#x73;**:** **pwd,** **cd,** **ls,** **mkdir** and **rmdir.** These commands are available on any Linux **(**&#x6F;r Uni&#x78;**)** syste&#x6D;**.**

This module also discusses **absolute** and **relative paths** and **path completion** in the **bash** shel&#x6C;**.**

### pwd <a href="#toc171119963" id="toc171119963"></a>

The **you are here** sign can be displayed with the **pwd** command **(**&#x50;rint Working Director&#x79;**).** Go ahea&#x64;**,** try i&#x74;**:** Open a command line interface **(**&#x61;lso called a termina&#x6C;**,** console or xter&#x6D;**)** and type **pwd.** The tool displays your **current directory.**

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **pwd /**&#x68;om&#x65;**/**&#x75;ser

### cd <a href="#toc171119964" id="toc171119964"></a>

You can change your current directory with the **cd** command **(**&#x43;hange Director&#x79;**).**

use&#x72;**@**&#x64;ebian&#x38;**$** **cd /etc** use&#x72;**@**&#x64;ebian&#x38;**$** **pwd**

**/**&#x65;tc use&#x72;**@**&#x64;ebian&#x38;**$** **cd /bin** use&#x72;**@**&#x64;ebian&#x38;**$** **pwd**

**/**&#x62;in use&#x72;**@**&#x64;ebian&#x38;**$** **cd /home/user/** use&#x72;**@**&#x64;ebian&#x38;**$** **pwd /**&#x68;om&#x65;**/**&#x75;ser

### cd \~ <a href="#toc171119965" id="toc171119965"></a>

The **cd** is also a shortcut to get back into your home director&#x79;**.** Just typing **cd** without a target director&#x79;**,** will put you in your home director&#x79;**.** Typing **cd \~** has the same effec&#x74;**.**

use&#x72;**@**&#x64;ebian&#x38;**$** **cd /etc** use&#x72;**@**&#x64;ebian&#x38;**$** **pwd** **/**&#x65;tc use&#x72;**@**&#x64;ebian&#x38;**$** **cd** use&#x72;**@**&#x64;ebian&#x38;**$** **pwd**

**/**&#x68;om&#x65;**/**&#x75;ser use&#x72;**@**&#x64;ebian&#x38;**$** **cd \~** use&#x72;**@**&#x64;ebian&#x38;**$** **pwd**

**/**&#x68;om&#x65;**/**&#x75;ser

### cd .. <a href="#toc171119966" id="toc171119966"></a>

To go to the **parent directory** **(**&#x74;he one just above your current directory in the directory tre&#x65;**),** type **cd ..** **.**

use&#x72;**@**&#x64;ebian&#x38;**$** **pwd /**&#x75;s&#x72;**/**&#x73;har&#x65;**/**&#x67;ames use&#x72;**@**&#x64;ebian&#x38;**$** **cd ..** use&#x72;**@**&#x64;ebian&#x38;**$** **pwd /**&#x75;s&#x72;**/**&#x73;hare

*To stay in the current director&#x79;**,** type **cd .*** ***;-)*** We will see useful use of the **.** character representing the current directory late&#x72;**.**

### cd - <a href="#toc171119967" id="toc171119967"></a>

Another useful shortcut with **cd** is to just type **cd -** to go to the previous director&#x79;**.**

use&#x72;**@**&#x64;ebian&#x38;**$** **pwd**

**/**&#x68;om&#x65;**/**&#x75;ser use&#x72;**@**&#x64;ebian&#x38;**$** **cd /etc** use&#x72;**@**&#x64;ebian&#x38;**$** **pwd**

**/**&#x65;tc use&#x72;**@**&#x64;ebian&#x38;**$** **cd -**

**/**&#x68;om&#x65;**/**&#x75;ser use&#x72;**@**&#x64;ebian&#x38;**$** **cd /**&#x65;tc

### absolute and relative paths <a href="#toc171119968" id="toc171119968"></a>

You should be aware of **absolute and relative paths** in the file tre&#x65;**.** When you type a path starting with a **slash (/),** then the **root** of the file tree is assume&#x64;**.** If you do&#x6E;**’**&#x74; start your path with a slas&#x68;**,** then the current directory is the assumed starting poin&#x74;**.**

The screenshot below first shows the current directory **/home/user.** From within this director&#x79;**,** you have to type **cd /home** instead of **cd home** to go to the **/home** director&#x79;**.**

use&#x72;**@**&#x64;ebian&#x38;**$** **pwd /**&#x68;om&#x65;**/**&#x75;ser

use&#x72;**@**&#x64;ebian&#x38;**$** **cd home**

bas&#x68;**:** c&#x64;**:** hom&#x65;**:** No such file or directory use&#x72;**@**&#x64;ebian&#x38;**$** **cd /home** use&#x72;**@**&#x64;ebian&#x38;**$** **pwd**

**/**&#x68;ome

When inside **/home,** you have to type **cd user** instead of **cd /user** to enter the subdirectory **user** of the current directory **/home.**

use&#x72;**@**&#x64;ebian&#x38;**$** **pwd**

**/**&#x68;ome

use&#x72;**@**&#x64;ebian&#x38;**$** **cd /user**

bas&#x68;**:** c&#x64;**:** **/**&#x75;se&#x72;**:** No such file or directory use&#x72;**@**&#x64;ebian&#x38;**$** **cd user** use&#x72;**@**&#x64;ebian&#x38;**$** **pwd** **/**&#x68;om&#x65;**/**&#x75;ser

In case your current directory is the **root directory /,** then both **cd /home** and **cd home** will get you in the **/home** director&#x79;**.**

use&#x72;**@**&#x64;ebian&#x38;**$** **pwd**

**/**

use&#x72;**@**&#x64;ebian&#x38;**$** **cd home** use&#x72;**@**&#x64;ebian&#x38;**$** **pwd** **/**&#x68;ome use&#x72;**@**&#x64;ebian&#x38;**$** **cd /** use&#x72;**@**&#x64;ebian&#x38;**$** **cd /home** use&#x72;**@**&#x64;ebian&#x38;**$** **pwd /**&#x68;ome

This was the last screenshot with **pwd** statement&#x73;**.** From now o&#x6E;**,** the current directory will often be displayed in the promp&#x74;**.** Later in this book we will explain how the shell variable **$PS1** can be configured to show thi&#x73;**.**

### path completion <a href="#toc171119969" id="toc171119969"></a>

The **tab key** can help you in typing a path without error&#x73;**.** Typing **cd /et** followed by the **tab key** will expand the command line to **cd /etc/.** When typing **cd /Et** followed by the **tab key,** nothing will happen because you typed the wrong **path** **(**&#x75;pper case &#x45;**).**

You will need fewer key strokes when using the **tab key,** and you will be sure your typed **path** is correc&#x74;**!**

### ls <a href="#toc171119970" id="toc171119970"></a>

You can list the contents of a directory with **ls.**

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **ls** allfile&#x73;**.**&#x74;xt dmes&#x67;**.**&#x74;xt services stuff summe&#x72;**.**&#x74;xt use&#x72;**@**&#x64;ebian&#x38;**:\~$**

### ls -a <a href="#toc171119971" id="toc171119971"></a>

A frequently used option with ls is **-a** to show all file&#x73;**.** Showing all files means including the **hidden files.** When a file name on a Linux file system starts with a do&#x74;**,** it is considered a **hidden file** and it does not show up in regular file listing&#x73;**.**

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **ls**

allfile&#x73;**.**&#x74;xt dmes&#x67;**.**&#x74;xt services stuff summe&#x72;**.**&#x74;xt use&#x72;**@**&#x64;ebian&#x38;**:\~$** **ls -a**

**.** allfile&#x73;**.**&#x74;xt **.**&#x62;as&#x68;**\_**&#x70;rofile dmes&#x67;**.**&#x74;xt **.**&#x6C;esshst stuff

**..** **.**&#x62;as&#x68;**\_**&#x68;istory **.**&#x62;ashrc services **.**&#x73;sh summe&#x72;**.**&#x74;xt use&#x72;**@**&#x64;ebian&#x38;**:\~$**

### ls -l <a href="#toc171119972" id="toc171119972"></a>

Many times you will be using options with **ls** to display the contents of the directory in different formats or to display different parts of the director&#x79;**.** Typing just **ls** gives you a list of files in the director&#x79;**.** Typing **ls -l** **(**&#x74;hat is a letter &#x4C;**,** not the number &#x31;**)** gives you a long listin&#x67;**.**

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **ls -l** total 17296

**-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--** 1 user user 17584442 Sep 17 0&#x30;**:**&#x30;3 allfile&#x73;**.**&#x74;xt

**-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--** 1 user user 96650 Sep 17 0&#x30;**:**&#x30;3 dmes&#x67;**.**&#x74;xt

**-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--** 1 user user 19558 Sep 17 0&#x30;**:**&#x30;4 services drwx&#x72;**-**&#x78;&#x72;**-**&#x78; 2 user user 4096 Sep 17 0&#x30;**:**&#x30;4 stuff

**-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--** 1 user user 0 Sep 17 0&#x30;**:**&#x30;4 summe&#x72;**.**&#x74;xt

### ls -lh <a href="#toc171119973" id="toc171119973"></a>

Another frequently used ls option is **-h.** It shows the numbers **(**&#x66;ile size&#x73;**)** in a more human readable forma&#x74;**.** Also shown below is some variation in the way you can give the options to **ls.** We will explain the details of the output later in this boo&#x6B;**.**

*Note that we use the letter L as an option in this screensho&#x74;**,** not the number &#x31;**.***

| <p>user<strong>@</strong>debian8<strong>:~~$</strong> <strong>ls -l -h</strong> total 17M</p><p><strong>-</strong>rw<strong>-</strong>r<strong>--</strong>r<strong>--</strong> 1 user user 17M Sep 17 00<strong>:</strong>03 allfiles<strong>.</strong>txt</p><p><strong>-</strong>rw<strong>-</strong>r<strong>--</strong>r<strong>--</strong> 1 user user 95K Sep 17 00<strong>:</strong>03 dmesg<strong>.</strong>txt</p><p><strong>-</strong>rw<strong>-</strong>r<strong>--</strong>r<strong>--</strong> 1 user user 20K Sep 17 00<strong>:</strong>04 services drwxr<strong>-</strong>xr<strong>-</strong>x 2 user user 4<strong>.</strong>0K Sep 17 00<strong>:</strong>04 stuff</p><p><strong>-</strong>rw<strong>-</strong>r<strong>--</strong>r<strong>--</strong> 1 user user 0 Sep 17 00<strong>:</strong>04 summer<strong>.</strong>txt user<strong>@</strong>debian8<strong>:~~$</strong> <strong>ls -lh</strong> total 17M</p><p><strong>-</strong>rw<strong>-</strong>r<strong>--</strong>r<strong>--</strong> 1 user user 17M Sep 17 00<strong>:</strong>03 allfiles<strong>.</strong>txt</p><p><strong>-</strong>rw<strong>-</strong>r<strong>--</strong>r<strong>--</strong> 1 user user 95K Sep 17 00<strong>:</strong>03 dmesg<strong>.</strong>txt</p><p><strong>-</strong>rw<strong>-</strong>r<strong>--</strong>r<strong>--</strong> 1 user user 20K Sep 17 00<strong>:</strong>04 services drwxr<strong>-</strong>xr<strong>-</strong>x 2 user user 4<strong>.</strong>0K Sep 17 00<strong>:</strong>04 stuff</p><p><strong>-</strong>rw<strong>-</strong>r<strong>--</strong>r<strong>--</strong> 1 user user 0 Sep 17 00<strong>:</strong>04 summer<strong>.</strong>txt user<strong>@</strong>debian8<strong>:~~$</strong> <strong>ls -hl</strong> total 17M</p><p><strong>-</strong>rw<strong>-</strong>r<strong>--</strong>r<strong>--</strong> 1 user user 17M Sep 17 00<strong>:</strong>03 allfiles<strong>.</strong>txt</p><p><strong>-</strong>rw<strong>-</strong>r<strong>--</strong>r<strong>--</strong> 1 user user 95K Sep 17 00<strong>:</strong>03 dmesg<strong>.</strong>txt</p><p><strong>-</strong>rw<strong>-</strong>r<strong>--</strong>r<strong>--</strong> 1 user user 20K Sep 17 00<strong>:</strong>04 services drwxr<strong>-</strong>xr<strong>-</strong>x 2 user user 4<strong>.</strong>0K Sep 17 00<strong>:</strong>04 stuff</p><p><strong>-</strong>rw<strong>-</strong>r<strong>--</strong>r<strong>--</strong> 1 user user 0 Sep 17 00<strong>:</strong>04 summer<strong>.</strong>txt user<strong>@</strong>debian8<strong>:~~$</strong> <strong>ls -h -l</strong> total 17M</p><p><strong>-</strong>rw<strong>-</strong>r<strong>--</strong>r<strong>--</strong> 1 user user 17M Sep 17 00<strong>:</strong>03 allfiles<strong>.</strong>txt</p><p><strong>-</strong>rw<strong>-</strong>r<strong>--</strong>r<strong>--</strong> 1 user user 95K Sep 17 00<strong>:</strong>03 dmesg<strong>.</strong>txt</p> |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| <p><strong>-</strong>rw<strong>-</strong>r<strong>--</strong>r<strong>--</strong> 1 user user 20K Sep 17 00<strong>:</strong>04 services drwxr<strong>-</strong>xr<strong>-</strong>x 2 user user 4<strong>.</strong>0K Sep 17 00<strong>:</strong>04 stuff</p><p><strong>-</strong>rw<strong>-</strong>r<strong>--</strong>r<strong>--</strong> 1 user user 0 Sep 17 00<strong>:</strong>04 summer<strong>.</strong>txt user<strong>@</strong>debian8<strong>:\~$</strong></p>                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |

### mkdir <a href="#toc171119974" id="toc171119974"></a>

Walking around the Unix file tree is fu&#x6E;**,** but it is even more fun to create your own directories with **mkdir.** You have to give at least one parameter to **mkdir,** the name of the new directory to be create&#x64;**.** Think before you type a leading **/** **.**

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **mkdir mydir** use&#x72;**@**&#x64;ebian&#x38;**:\~$** **cd mydir**

use&#x72;**@**&#x64;ebian&#x38;**:\~/**&#x6D;ydi&#x72;**$** **ls -al** total 8 drwx&#x72;**-**&#x78;&#x72;**-**&#x78; 2 user user 4096 Sep 17 0&#x30;**:**&#x30;7 **.** drwx&#x72;**-**&#x78;&#x72;**-**&#x78; 48 user user 4096 Sep 17 0&#x30;**:**&#x30;7 **..** use&#x72;**@**&#x64;ebian&#x38;**:\~/**&#x6D;ydi&#x72;**$** **mkdir stuff** use&#x72;**@**&#x64;ebian&#x38;**:\~/**&#x6D;ydi&#x72;**$** **mkdir otherstuff** use&#x72;**@**&#x64;ebian&#x38;**:\~/**&#x6D;ydi&#x72;**$** **ls -l** total 8

drwx&#x72;**-**&#x78;&#x72;**-**&#x78; 2 user user 4096 Sep 17 0&#x30;**:**&#x30;8 otherstuff drwx&#x72;**-**&#x78;rx 2 user user 4096 Sep 17 0&#x30;**:**&#x30;8 stuff use&#x72;**@**&#x64;ebian&#x38;**:\~/**&#x6D;ydi&#x72;**$**

### mkdir -p <a href="#toc171119975" id="toc171119975"></a>

The following command will fai&#x6C;**,** because the **parent directory** of **threedirsdeep** does not exis&#x74;**.**

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **mkdir mydir2/mysubdir2/threedirsdeep**

mkdi&#x72;**:** cannot create directory **‘**&#x6D;ydir&#x32;**/**&#x6D;ysubdir&#x32;**/**&#x74;hreedirsdee&#x70;**’:** No such f&#x69;**\\** le or directory

When given the option **-p,** then **mkdir** will create **parent directories** as neede&#x64;**.**

### rmdir <a href="#toc171119976" id="toc171119976"></a>

When a directory is empt&#x79;**,** you can use **rmdir** to remove the director&#x79;**.**

use&#x72;**@**&#x64;ebian&#x38;**:\~/**&#x6D;ydi&#x72;**$** **ls -l** total 8

drwx&#x72;**-**&#x78;&#x72;**-**&#x78; 2 user user 4096 Sep 17 0&#x30;**:**&#x30;8 otherstuff drwx&#x72;**-**&#x78;rx 2 user user 4096 Sep 17 0&#x30;**:**&#x30;8 stuff use&#x72;**@**&#x64;ebian&#x38;**:\~/**&#x6D;ydi&#x72;**$** **rmdir otherstuff** use&#x72;**@**&#x64;ebian&#x38;**:\~/**&#x6D;ydi&#x72;**$** **cd ..**

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **rmdir mydir**

rmdi&#x72;**:** failed to remove **‘**&#x6D;ydi&#x72;**’:** Directory not empty

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **rmdir mydir/stuff**

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **rmdir mydir**

### rmdir -p <a href="#toc171119977" id="toc171119977"></a>

And similar to the **mkdir -p** optio&#x6E;**,** you can also use **rmdir** to recursively remove directorie&#x73;**.**

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **mkdir -p test42/subdir** use&#x72;**@**&#x64;ebian&#x38;**:\~$** **rmdir -p**

**test42/subdir**

### working with files <a href="#toc171119978" id="toc171119978"></a>

In this chapter we learn how to recognis&#x65;**,** creat&#x65;**,** remov&#x65;**,** copy and move files using commands like **file, touch, rm, cp, mv** and **rename.**

### all files are case sensitive <a href="#toc171119979" id="toc171119979"></a>

Files on Linux **(**&#x6F;r any Uni&#x78;**)** are **case sensitive.** This means that **FILE1** is different from **file1,** and **/etc/hosts** is different from **/etc/Hosts** **(**&#x74;he latter one does not exist on a typical Linux compute&#x72;**).**

This screenshot shows the difference between two file&#x73;**,** one with upper case **W,** the other with lower case **w.**

use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~/**&#x4C;inu&#x78;**$** **ls**

winte&#x72;**.**&#x74;xt Winte&#x72;**.**&#x74;xt use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~/**&#x4C;inu&#x78;**$** **cat winter.txt**

It is col&#x64;**.** use&#x72;**@**&#x70;redatorp&#x63;**\~/**&#x4C;inu&#x78;**$** **cat Winter.txt** It is very col&#x64;**!**

### Everything is a file <a href="#toc171119980" id="toc171119980"></a>

A **directory** is a special kind of **file,** but it is still a **(**&#x63;ase sensitiv&#x65;**!)** **file.** Each terminal window **(**&#x66;or example **/dev/pts/4),** any hard disk or partition **(**&#x66;or example **/dev/sdb1)** and any process are all represented somewhere in the **file system** as a **file.** It will become clear throughout this course that everything on Linux is a **file.** **file**

The **file** utility determines the file typ&#x65;**.** Linux does not use extensions to determine the file typ&#x65;**.** The command line does not care whether a file ends in **.**&#x74;xt or **.**&#x70;d&#x66;**.** As a system administrato&#x72;**,** you should use the **file** command to determine the file typ&#x65;**.** Here are some examples on a typical Linux syste&#x6D;**.**

use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$** **file pic33.png**

pic3&#x33;**.**&#x70;n&#x67;**:** PNG image dat&#x61;**,** 3840 x 120&#x30;**,** &#x38;**-**&#x62;i&#x74;**/**&#x63;olor RGB&#x41;**,** no&#x6E;**-**&#x69;nterlaced use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$** **file /etc/passwd**

**/**&#x65;t&#x63;**/**&#x70;assw&#x64;**:** ASCII text use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$** **file HelloWorld.c** HelloWorl&#x64;**.**&#x63;**:** ASCII C program text

The file command uses a magic file that contains patterns to recognise file type&#x73;**.** The magic file is located in **/usr/share/file/magic.** Type **man 5 magic** for more informatio&#x6E;**.** It is interesting to point out **file -s** for special files like those in **/dev** and **/proc.**

roo&#x74;**@**&#x64;ebian&#x36;**\~#** **file /dev/sda**

**/**&#x64;e&#x76;**/**&#x73;d&#x61;**:** block special

roo&#x74;**@**&#x64;ebian&#x36;**\~#** **file -s /dev/sda**

**/**&#x64;e&#x76;**/**&#x73;d&#x61;**:** x86 boot secto&#x72;**;** partition &#x31;**:** ID=0x8&#x33;**,** activ&#x65;**,** starthea&#x64;**...**

roo&#x74;**@**&#x64;ebian&#x36;**\~#** **file /proc/cpuinfo**

**/**&#x70;ro&#x63;**/**&#x63;puinf&#x6F;**:** empty roo&#x74;**@**&#x64;ebian&#x36;**\~#** **file -s /proc/cpuinfo /**&#x70;ro&#x63;**/**&#x63;puinf&#x6F;**:**

ASCII &#x43;**++** program text

### touch create an empty file <a href="#toc171119981" id="toc171119981"></a>

One easy way to create an empty file is with **touch.** **(**&#x57;e will see many other ways for creating files later in this boo&#x6B;**.)**

This screenshot starts with an empty director&#x79;**,** creates two files with **touch** and the lists those file&#x73;**.**

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **ls -l** total 0

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **touch file42** use&#x72;**@**&#x64;ebian&#x37;**:\~$** **touch file33** use&#x72;**@**&#x64;ebian&#x37;**:\~$** **ls l**

total 0

**-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--** 1 user user 0 Oct 15 0&#x38;**:**&#x35;7 file33 **-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--** 1 user user 0 Oct 15 0&#x38;**:**&#x35;6 file42 use&#x72;**@**&#x64;ebian&#x37;**:\~$**

### touch -t <a href="#toc171119982" id="toc171119982"></a>

The **touch** command can set some properties while creating empty file&#x73;**.** Can you determine what is set by looking at the next screenshot? If no&#x74;**,** check the manual for **touch.**

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **touch -t 200505050000 SinkoDeMayo** use&#x72;**@**&#x64;ebian&#x37;**:\~$** **touch -t**

**130207111630 BigBattle.txt** use&#x72;**@**&#x64;ebian&#x37;**:\~$** **ls -l** total 0

**-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--** 1 user user 0 Jul 11 1302 BigBattl&#x65;**.**&#x74;xt

**-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--** 1 user user 0 Oct 15 0&#x38;**:**&#x35;7 file33

**-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--** 1 user user 0 Oct 15 0&#x38;**:**&#x35;6 file42 **-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--** 1 user user 0 May 5 2005 SinkoDeMayo use&#x72;**@**&#x64;ebian&#x37;**:\~$**

### rm <a href="#toc171119983" id="toc171119983"></a>

### remove forever <a href="#toc171119984" id="toc171119984"></a>

When you no longer need a fil&#x65;**,** use **rm** to remove i&#x74;**.** Unlike some graphical user interface&#x73;**,** the command line in general does not have a **waste bin** or **trash can** to recover file&#x73;**.** When you use **rm** to remove a fil&#x65;**,** the file is gon&#x65;**.** Therefor&#x65;**,** be careful when removing file&#x73;**!**

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **ls**

BigBattl&#x65;**.**&#x74;xt file33 file42 SinkoDeMayo use&#x72;**@**&#x64;ebian&#x37;**:\~$** **rm BigBattle.txt** use&#x72;**@**&#x64;ebian&#x37;**:\~$** **ls** file33 file42 SinkoDeMayo use&#x72;**@**&#x64;ebian&#x37;**:\~$**

### rm -i <a href="#toc171119985" id="toc171119985"></a>

To prevent yourself from accidentally removing a fil&#x65;**,** you can type **rm -i.**

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **ls** file33 file42 SinkoDeMayo

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **rm -i file33**

r&#x6D;**:** remove regular empty file \`file3&#x33;**’**? yes use&#x72;**@**&#x64;ebian&#x37;**:\~$** **rm -i SinkoDeMayo**

r&#x6D;**:** remove regular empty file \`SinkoDeMay&#x6F;**’**? n use&#x72;**@**&#x64;ebian&#x37;**:\~$** **ls** file42 SinkoDeMayo use&#x72;**@**&#x64;ebian&#x37;**:\~$**

### rm -rf <a href="#toc171119986" id="toc171119986"></a>

By defaul&#x74;**,** **rm -r** will not remove no&#x6E;**-**&#x65;mpty directorie&#x73;**.** However, **rm** accepts several options that will allow you to remove any director&#x79;**.** The **rm -rf** statement is famous because it will erase anything **(**&#x70;roviding that you have the permissions to do s&#x6F;**).** When you are logged on as roo&#x74;**,** be very careful with **rm -rf** **(**&#x74;he **f** means **force** and the **r** means **recursive)** since being root implies that permissions do&#x6E;**’**&#x74; apply to yo&#x75;**.** You can literally erase your entire file system by acciden&#x74;**.**

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **mkdir test**

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **rm test**

r&#x6D;**:** cannot remove \`tes&#x74;**’:** Is a directory use&#x72;**@**&#x64;ebian&#x37;**:\~$** **rm -rf test** use&#x72;**@**&#x64;ebian&#x37;**:\~$** **ls test**

l&#x73;**:** cannot access tes&#x74;**:** No such file or directory use&#x72;**@**&#x64;ebian&#x37;**:\~$**

### cp copy one file <a href="#toc171119987" id="toc171119987"></a>

To copy a fil&#x65;**,** use **cp** with a source and a target argumen&#x74;**.**

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **ls**

file42 SinkoDeMayo

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **cp file42 file42.copy** use&#x72;**@**&#x64;ebian&#x37;**:\~$** **ls**

file42 file4&#x32;**.**&#x63;opy SinkoDeMayo

### copy to another directory <a href="#toc171119988" id="toc171119988"></a>

If the target is a director&#x79;**,** then the source files are copied to that target director&#x79;**.**

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **mkdir dir42** use&#x72;**@**&#x64;ebian&#x37;**:\~$** **cp SinkoDeMayo dir42**

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **ls dir42/** SinkoDeMayo

### cp -r <a href="#toc171119989" id="toc171119989"></a>

To copy complete directorie&#x73;**,** use **cp -r** **(**&#x74;he **-r** option forces **recursive** copying of all files in all subdirectorie&#x73;**).**

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **ls** dir42 file42 file4&#x32;**.**&#x63;opy SinkoDeMayo use&#x72;**@**&#x64;ebian&#x37;**:\~$** **cp -r dir42/ dir33** use&#x72;**@**&#x64;ebian&#x37;**:\~$** **ls** dir33 dir42 file42 file4&#x32;**.**&#x63;opy SinkoDeMayo use&#x72;**@**&#x64;ebian&#x37;**:\~$** **ls dir33/** SinkoDeMayo

### copy multiple files to directory <a href="#toc171119990" id="toc171119990"></a>

You can also use cp to copy multiple files into a director&#x79;**.** In this cas&#x65;**,** the last argument **(**&#x61;**.**&#x6B;**.**&#x61;**.** the targe&#x74;**)** must be a director&#x79;**.**

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **cp file42 file42.copy SinkoDeMayo dir42/** use&#x72;**@**&#x64;ebian&#x37;**:\~$** **ls dir42/** file42 file4&#x32;**.**&#x63;opy SinkoDeMayo

### cp -i <a href="#toc171119991" id="toc171119991"></a>

To prevent **cp** from overwriting existing file&#x73;**,** use the **-i** **(**&#x66;or interactiv&#x65;**)** optio&#x6E;**.**

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **cp SinkoDeMayo file42** use&#x72;**@**&#x64;ebian&#x37;**:\~$** **cp SinkoDeMayo file42**

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **cp -i SinkoDeMayo file42** c&#x70;**:** overwrite \`file4&#x32;**’**? **n** use&#x72;**@**&#x64;ebian&#x37;**:\~$**

### mv <a href="#toc171119992" id="toc171119992"></a>

### rename files with mv <a href="#toc171119993" id="toc171119993"></a>

Use **mv** to rename a file or to move the file to another director&#x79;**.**

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **ls** dir33 dir42 file42 file4&#x32;**.**&#x63;opy SinkoDeMayo use&#x72;**@**&#x64;ebian&#x37;**:\~$** **mv file42 file33** use&#x72;**@**&#x64;ebian&#x37;**:\~$** **ls**

dir33 dir42 file33 file4&#x32;**.**&#x63;opy SinkoDeMayo use&#x72;**@**&#x64;ebian&#x37;**:\~$**

When you need to rename only one file then **mv** is the preferred command to us&#x65;**.**

### rename directories with mv <a href="#toc171119994" id="toc171119994"></a>

The same **mv** command can be used to rename directorie&#x73;**.**

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **ls -l** total 8

drwx&#x72;**-**&#x78;&#x72;**-**&#x78; 2 user user 4096 Oct 15 0&#x39;**:**&#x33;6 dir33 drwx&#x72;**-**&#x78;&#x72;**-**&#x78; 2 user user 4096 Oct 15 0&#x39;**:**&#x33;6 dir42 **-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--** 1 user user 0 Oct 15 0&#x39;**:**&#x33;8 file33

**-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--** 1 user user 0 Oct 15 0&#x39;**:**&#x31;6 file4&#x32;**.**&#x63;opy **-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--** 1 user user 0 May 5 2005 SinkoDeMayo

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **mv dir33 backup** use&#x72;**@**&#x64;ebian&#x37;**:\~$** **ls -l** total 8

drwx&#x72;**-**&#x78;&#x72;**-**&#x78; 2 user user 4096 Oct 15 0&#x39;**:**&#x33;6 backup drwx&#x72;**-**&#x78;&#x72;**-**&#x78; 2 user user 4096 Oct 15 0&#x39;**:**&#x33;6 dir42 **-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--** 1 user user 0 Oct 15 0&#x39;**:**&#x33;8 file33

**-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--** 1 user user 0 Oct 15 0&#x39;**:**&#x31;6 file4&#x32;**.**&#x63;opy **-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--** 1 user user 0 May 5 2005 SinkoDeMayo use&#x72;**@**&#x64;ebian&#x37;**:\~$**

**mv -i**

The **mv** also has a **-i** switch similar to **cp** and **rm.** this screenshot shows that **mv -i** will ask permission to overwrite an existing fil&#x65;**.**

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **mv -i file33 SinkoDeMayo** m&#x76;**:** overwrite

\`SinkoDeMay&#x6F;**’**? **no** use&#x72;**@**&#x64;ebian&#x37;**:\~$**

**Rename**

The **rename** command is one of the rare occasions where the Linux Fundamentals book has to make a distinction between Linux distribution&#x73;**.** Almost every command in the **Fundamentals** part of this book works on almost every Linux compute&#x72;**.** But **rename** is differen&#x74;**.**

Try to use **mv** whenever you need to rename only a couple of file&#x73;**.**

### Rename on Debian/Debian stable <a href="#toc171119995" id="toc171119995"></a>

The **rename** command on Debian uses regular expressions **(**&#x72;egular expression or shor regex are explained in a later chapte&#x72;**)** to rename many files at onc&#x65;**.**

Below a **rename** example that switches all occurrences of txt to png for all file names ending in **.**&#x74;x&#x74;**.**

use&#x72;**@**&#x64;ebian&#x37;**:\~/**&#x74;est4&#x32;**$** **ls** ab&#x63;**.**&#x74;xt file3&#x33;**.**&#x74;xt file4&#x32;**.**&#x74;xt use&#x72;**@**&#x64;ebian&#x37;**:\~/**&#x74;est4&#x32;**$** **rename ‘s/\\.txt/\\.png/’ \*.txt** use&#x72;**@**&#x64;ebian&#x37;**:\~/**&#x74;est4&#x32;**$** **ls** ab&#x63;**.**&#x70;ng file3&#x33;**.**&#x70;ng file4&#x32;**.**&#x70;ng

This second example switches all **(**&#x66;irs&#x74;**)** occurrences of **file** into **document** for all file names ending in **.**&#x70;n&#x67;**.**

use&#x72;**@**&#x64;ebian&#x37;**:\~/**&#x74;est4&#x32;**$** **ls** ab&#x63;**.**&#x70;ng file3&#x33;**.**&#x70;ng file4&#x32;**.**&#x70;ng use&#x72;**@**&#x64;ebian&#x37;**:\~/**&#x74;est4&#x32;**$** **rename ‘s/file/document/’ \*.png** use&#x72;**@**&#x64;ebian&#x37;**:\~/**&#x74;est4&#x32;**$** **ls** ab&#x63;**.**&#x70;ng document3&#x33;**.**&#x70;ng document4&#x32;**.**&#x70;ng use&#x72;**@**&#x64;ebian&#x37;**:\~/**&#x74;est4&#x32;**$**

### Rename on CentOS/RHEL/Fedora <a href="#toc171119996" id="toc171119996"></a>

On Red Hat Enterprise Linu&#x78;**,** the syntax of **rename** is a bit differen&#x74;**.** The first example below renames all **\*.**&#x63;onf files replacing any occurrence of **.**&#x63;onf with **.**&#x62;acku&#x70;**.**

\[use&#x72;**@**&#x63;entos7 **\~**]**$** **touch one.conf two.conf three.conf**

\[use&#x72;**@**&#x63;entos7 **\~**]**$** **rename .conf .backup \*.conf**

\[use&#x72;**@**&#x63;entos7 **\~**]**$** **ls**

on&#x65;**.**&#x62;ackup thre&#x65;**.**&#x62;ackup tw&#x6F;**.**&#x62;ackup \[use&#x72;**@**&#x63;entos7 **\~**]**$**

The second example renames all **(\*)** files replacing one with ON&#x45;**.**

\[use&#x72;**@**&#x63;entos7 **\~**]**$** **ls**

on&#x65;**.**&#x62;ackup thre&#x65;**.**&#x62;ackup tw&#x6F;**.**&#x62;ackup \[use&#x72;**@**&#x63;entos7 **\~**]**$** **rename one ONE \***

\[use&#x72;**@**&#x63;entos7 **\~**]**$** **ls**

ON&#x45;**.**&#x62;ackup thre&#x65;**.**&#x62;ackup tw&#x6F;**.**&#x62;ackup

\[use&#x72;**@**&#x63;entos7 **\~**]**$**

### Head <a href="#toc171119997" id="toc171119997"></a>

You can use **head** to display the first ten lines of a fil&#x65;**.**

use&#x72;**@**&#x64;ebian&#x37;**\~$** **head /etc/passwd**

roo&#x74;**:**&#x78;**:**&#x30;**:**&#x30;**:**&#x72;oo&#x74;**:/**&#x72;oo&#x74;**:/**&#x62;i&#x6E;**/**&#x62;ash daemo&#x6E;**:**&#x78;**:**&#x31;**:**&#x31;**:**&#x64;aemo&#x6E;**:/**&#x75;s&#x72;**/**&#x73;bi&#x6E;**:/**&#x62;i&#x6E;**/**&#x73;h

bi&#x6E;**:**&#x78;**:**&#x32;**:**&#x32;**:**&#x62;i&#x6E;**:/**&#x62;i&#x6E;**:/**&#x62;i&#x6E;**/**&#x73;h sy&#x73;**:**&#x78;**:**&#x33;**:**&#x33;**:**&#x73;y&#x73;**:/**&#x64;e&#x76;**:/**&#x62;i&#x6E;**/**&#x73;h

syn&#x63;**:**&#x78;**:**&#x34;**:**&#x36;553&#x34;**:**&#x73;yn&#x63;**:/**&#x62;i&#x6E;**:/**&#x62;i&#x6E;**/**&#x73;ync game&#x73;**:**&#x78;**:**&#x35;**:**&#x36;&#x30;**:**&#x67;ame&#x73;**:/**&#x75;s&#x72;**/**&#x67;ame&#x73;**:/**&#x62;i&#x6E;**/**&#x73;h ma&#x6E;**:**&#x78;**:**&#x36;**:**&#x31;&#x32;**:**&#x6D;a&#x6E;**:/**&#x76;a&#x72;**/**&#x63;ach&#x65;**/**&#x6D;a&#x6E;**:/**&#x62;i&#x6E;**/**&#x73;h l&#x70;**:**&#x78;**:**&#x37;**:**&#x37;**:**&#x6C;&#x70;**:/**&#x76;a&#x72;**/**&#x73;poo&#x6C;**/**&#x6C;p&#x64;**:/**&#x62;i&#x6E;**/**&#x73;h mai&#x6C;**:**&#x78;**:**&#x38;**:**&#x38;**:**&#x6D;ai&#x6C;**:/**&#x76;a&#x72;**/**&#x6D;ai&#x6C;**:/**&#x62;i&#x6E;**/**&#x73;h new&#x73;**:**&#x78;**:**&#x39;**:**&#x39;**:**&#x6E;ew&#x73;**:/**&#x76;a&#x72;**/**&#x73;poo&#x6C;**/**&#x6E;ew&#x73;**:/**&#x62;i&#x6E;**/**&#x73;h roo&#x74;**@**&#x64;ebian&#x37;**\~#**

The **head** command can also display the first **n** lines of a fil&#x65;**.**

use&#x72;**@**&#x64;ebian&#x37;**\~$** **head -4 /etc/passwd** roo&#x74;**:**&#x78;**:**&#x30;**:**&#x30;**:**&#x72;oo&#x74;**:/**&#x72;oo&#x74;**:/**&#x62;i&#x6E;**/**&#x62;ash daemo&#x6E;**:**&#x78;**:**&#x31;**:**&#x31;**:**&#x64;aemo&#x6E;**:/**&#x75;s&#x72;**/**&#x73;bi&#x6E;**:/**&#x62;i&#x6E;**/**&#x73;h

bi&#x6E;**:**&#x78;**:**&#x32;**:**&#x32;**:**&#x62;i&#x6E;**:/**&#x62;i&#x6E;**:/**&#x62;i&#x6E;**/**&#x73;h sy&#x73;**:**&#x78;**:**&#x33;**:**&#x33;**:**&#x73;y&#x73;**:/**&#x64;e&#x76;**:/**&#x62;i&#x6E;**/**&#x73;h use&#x72;**@**&#x64;ebian&#x37;**\~$**

And **head** can also display the first **n bytes.**

use&#x72;**@**&#x64;ebian&#x37;**\~$** **head -c14 /etc/passwd** roo&#x74;**:**&#x78;**:**&#x30;**:**&#x30;**:**&#x72;oouse&#x72;**@**&#x64;ebian&#x37;**\~$**

### tail <a href="#toc171119998" id="toc171119998"></a>

Similar to **head,** the **tail** command will display the last ten lines of a fil&#x65;**.**

use&#x72;**@**&#x64;ebian&#x37;**\~$** **tail /etc/services** vboxd 2001&#x32;**/**&#x75;dp binkp 2455&#x34;**/**&#x74;cp **#** binkp fidonet protocol asp

2737&#x34;**/**&#x74;cp **#** Address Search Protocol asp 2737&#x34;**/**&#x75;dp

csync2 3086&#x35;**/**&#x74;cp **#** cluster synchronization tool dircproxy 5700&#x30;**/**&#x74;cp **#** Detachable IRC Proxy tfido 6017&#x37;**/**&#x74;cp **#** fidonet EMSI over telnet fido 6017&#x39;**/**&#x74;cp **#** fidonet EMSI over TCP

**#** Local services

use&#x72;**@**&#x64;ebian&#x37;**\~$**

You can give **tail** the number of lines you want to se&#x65;**.**

use&#x72;**@**&#x64;ebian&#x37;**\~$** **tail -3 /etc/services** fido 6017&#x39;**/**&#x74;cp **#** fidonet EMSI over TCP

**#** Local services use&#x72;**@**&#x64;ebian&#x37;**\~$**

The **tail** command has other useful option&#x73;**,** some of which we will use during this cours&#x65;**.** **cat**

The **cat** command is one of the most universal tool&#x73;**,** yet all it does is copy **standard input** to **standard output.** In combination with the shell this can be very powerful and divers&#x65;**.** Some examples will give a glimpse into the possibilitie&#x73;**.** The first example is simpl&#x65;**,** you can use cat to display a file on the scree&#x6E;**.** If the file is longer than the scree&#x6E;**,** it will scroll to the en&#x64;**.**

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **cat /etc/resolv.conf** domain linu&#x78;**-**&#x74;rainin&#x67;**.**&#x62;e search linu&#x78;**-**&#x74;rainin&#x67;**.**&#x62;e nameserver 19&#x32;**.**&#x31;6&#x38;**.**&#x31;**.**&#x34;2

### concatenate <a href="#toc171119999" id="toc171119999"></a>

**cat** is short for **concatenate.** One of the basic uses of **cat** is to concatenate files into a bigger **(**&#x6F;r complet&#x65;**)** fil&#x65;**.**

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **echo one >part1** use&#x72;**@**&#x64;ebian&#x38;**:\~$** **echo two >part2** use&#x72;**@**&#x64;ebian&#x38;**:\~$** **echo three**

**>part3**

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **cat part1** one

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **cat part2** two

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **cat part3** three

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **cat part1 part2 part3** one two three

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **cat part1 part2 part3 >all** use&#x72;**@**&#x64;ebian&#x38;**:\~$** **cat all** one two three use&#x72;**@**&#x64;ebian&#x38;**:\~$**

### create files <a href="#toc171120000" id="toc171120000"></a>

You can use **cat** to create flat text file&#x73;**.** Type the **cat > winter.txt** command as shown in the screenshot belo&#x77;**.** Then type one or more line&#x73;**,** finishing each line with the enter ke&#x79;**.** After the last lin&#x65;**,** type and hold the Control **(**&#x43;tr&#x6C;**)** key and press &#x64;**.**

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **cat > winter.txt** It is very cold toda&#x79;**!**

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **cat winter.txt**

It is very cold toda&#x79;**!** use&#x72;**@**&#x64;ebian&#x38;**:\~$**

The **Ctrl d** key combination will send an **EOF** **(**&#x45;nd of Fil&#x65;**)** to the running process ending the **cat** comman&#x64;**.**

### custom end marker <a href="#toc171120001" id="toc171120001"></a>

You can choose an end marker for **cat** with **<<** as is shown in this screensho&#x74;**.** This construction is called a **here directive** and will end the **cat** comman&#x64;**.**

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **cat > hot.txt <\<stop >** It is hot toda&#x79;**!**

**>** Yes it is summe&#x72;**.**

**>** stop

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **cat hot.txt** It is hot toda&#x79;**!**

Yes it is summe&#x72;**.** use&#x72;**@**&#x64;ebian&#x38;**:\~$**

### copy files <a href="#toc171120002" id="toc171120002"></a>

In the third example you will see that cat can be used to copy file&#x73;**.** We will explain in detail what happens here in the bash shell chapte&#x72;**.**

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **cat winter.txt**

It is very cold toda&#x79;**!** use&#x72;**@**&#x64;ebian&#x38;**:\~$** **cat winter.txt > cold.txt** use&#x72;**@**&#x64;ebian&#x38;**:\~$** **cat cold.txt**

It is very cold toda&#x79;**!** use&#x72;**@**&#x64;ebian&#x38;**:\~$**

### tac <a href="#toc171120003" id="toc171120003"></a>

Just one example will show you the purpose of **tac** **(**&#x63;at backward&#x73;**).**

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **cat count** one two three four

use&#x72;**@**&#x64;ebian&#x38;**:\~$** **tac count** four three two one

### cat <a href="#toc171120004" id="toc171120004"></a>

When between two **pipes,** the **cat** command does nothing **(**&#x65;xcept putting **stdin** on **stdout).**

\[use&#x72;**@**&#x52;HEL4b pipes]**$** tac coun&#x74;**.**&#x74;xt | cat | cat | cat | cat | cat five four three two one

\[use&#x72;**@**&#x52;HEL4b pipes]**$**

### tee <a href="#toc171120005" id="toc171120005"></a>

Writing long **pipes** in Unix is fu&#x6E;**,** but sometimes you may want intermediate result&#x73;**.** This is were **tee** comes in hand&#x79;**.** The **tee** filter puts **stdin** on **stdout** and also into a fil&#x65;**.** So **tee** is almost the same as **cat,** except that it has two identical output&#x73;**.**

\[use&#x72;**@**&#x52;HEL4b pipes]**$** tac coun&#x74;**.**&#x74;xt | tee tem&#x70;**.**&#x74;xt | tac one two three four five

\[use&#x72;**@**&#x52;HEL4b pipes]**$** cat tem&#x70;**.**&#x74;xt five four three two one

\[use&#x72;**@**&#x52;HEL4b pipes]**$**

**grep**

The **grep** filter is famous among Unix user&#x73;**.** The most common use of **grep** is to filter lines of text containing **(**&#x6F;r not containin&#x67;**)** a certain strin&#x67;**.**

\[use&#x72;**@**&#x52;HEL4b pipes]**$** cat tenni&#x73;**.**&#x74;xt

Amelie Mauresm&#x6F;**,** Fra

Kim Clijster&#x73;**,** BEL

Justine Heni&#x6E;**,** Bel

Serena William&#x73;**,** usa

Venus William&#x73;**,** USA

\[use&#x72;**@**&#x52;HEL4b pipes]**$** cat tenni&#x73;**.**&#x74;xt | grep Williams

Serena William&#x73;**,** usa

Venus William&#x73;**,** USA

You can write this without the ca&#x74;**.**

\[use&#x72;**@**&#x52;HEL4b pipes]**$** grep Williams tenni&#x73;**.**&#x74;xt

Serena William&#x73;**,** usa

Venus William&#x73;**,** USA

One of the most useful options of grep is **grep -i** which filters in a case insensitive wa&#x79;**.**

\[use&#x72;**@**&#x52;HEL4b pipes]**$** grep Bel tenni&#x73;**.**&#x74;xt

Justine Heni&#x6E;**,** Bel

\[use&#x72;**@**&#x52;HEL4b pipes]**$** grep **-**&#x69; Bel tenni&#x73;**.**&#x74;xt

Kim Clijster&#x73;**,** BEL

Justine Heni&#x6E;**,** Bel

\[use&#x72;**@**&#x52;HEL4b pipes]**$**

Another very useful option is **grep -v** which outputs lines not matching the strin&#x67;**.**

\[use&#x72;**@**&#x52;HEL4b pipes]**$** grep **-**&#x76; Fra tenni&#x73;**.**&#x74;xt

Kim Clijster&#x73;**,** BEL

Justine Heni&#x6E;**,** Bel

Serena William&#x73;**,** usa

Venus William&#x73;**,** USA

\[use&#x72;**@**&#x52;HEL4b pipes]**$**

And of cours&#x65;**,** both options can be combined to filter all lines not containing a case insensitive strin&#x67;**.**

\[use&#x72;**@**&#x52;HEL4b pipes]**$** grep **-**&#x76;i usa tenni&#x73;**.**&#x74;xt

Amelie Mauresm&#x6F;**,** Fra

Kim Clijster&#x73;**,** BEL

Justine Heni&#x6E;**,** Bel

\[use&#x72;**@**&#x52;HEL4b pipes]**$**

With **grep -A1** one line **after** the result is also displaye&#x64;**.**

use&#x72;**@**&#x64;ebian&#x35;**:\~/**&#x70;ipe&#x73;**$** grep **-**&#x41;1 Henin tenni&#x73;**.**&#x74;xt

Justine Heni&#x6E;**,** Bel

Serena William&#x73;**,** usa

With **grep -B1** one line **before** the result is also displaye&#x64;**.**

use&#x72;**@**&#x64;ebian&#x35;**:\~/**&#x70;ipe&#x73;**$** grep **-**&#x42;1 Henin tenni&#x73;**.**&#x74;xt

Kim Clijster&#x73;**,** BEL

Justine Heni&#x6E;**,** Bel

With **grep -C1** **(**&#x63;ontex&#x74;**)** one line **before** and one **after** are also displaye&#x64;**.** All three options **(**&#x41;**,**&#x42;**,** and &#x43;**)** can display any number of lines **(**&#x75;sing &#x65;**.**&#x67;**.** A&#x32;**,** B4 or C2&#x30;**).**

use&#x72;**@**&#x64;ebian&#x35;**:\~/**&#x70;ipe&#x73;**$** grep **-**&#x43;1 Henin tenni&#x73;**.**&#x74;xt

Kim Clijster&#x73;**,** BEL

Justine Heni&#x6E;**,** Bel

Serena William&#x73;**,** usa

### wc <a href="#toc171120006" id="toc171120006"></a>

Counting word&#x73;**,** lines and characters is easy with **wc.**

\[use&#x72;**@**&#x52;HEL4b pipes]**$** wc tenni&#x73;**.**&#x74;xt

5 15 100 tenni&#x73;**.**&#x74;xt

\[use&#x72;**@**&#x52;HEL4b pipes]**$** wc **-**&#x6C; tenni&#x73;**.**&#x74;xt 5 tenni&#x73;**.**&#x74;xt

\[use&#x72;**@**&#x52;HEL4b pipes]**$** wc **-**&#x77; tenni&#x73;**.**&#x74;xt 15 tenni&#x73;**.**&#x74;xt

\[use&#x72;**@**&#x52;HEL4b pipes]**$** wc **-**&#x63; tenni&#x73;**.**&#x74;xt

100 tenni&#x73;**.**&#x74;xt

\[use&#x72;**@**&#x52;HEL4b pipes]**$**

### sort <a href="#toc171120007" id="toc171120007"></a>

The **sort** filter will default to an alphabetical sor&#x74;**.**

use&#x72;**@**&#x64;ebian&#x35;**:\~/**&#x70;ipe&#x73;**$** cat musi&#x63;**.**&#x74;xt

Queen

Brel

Led Zeppelin Abba use&#x72;**@**&#x64;ebian&#x35;**:\~/**&#x70;ipe&#x73;**$** sort musi&#x63;**.**&#x74;xt

Abba

Brel

Led Zeppelin

Queen

But the **sort** filter has many options to tweak its usag&#x65;**.** This example shows sorting different columns **(**&#x63;olumn 1 or column &#x32;**).**

\[use&#x72;**@**&#x52;HEL4b pipes]**$** sort **-**&#x6B;1 countr&#x79;**.**&#x74;xt

Belgiu&#x6D;**,** Brussel&#x73;**,** 10

Franc&#x65;**,** Pari&#x73;**,** 60

German&#x79;**,** Berli&#x6E;**,** 100

Ira&#x6E;**,** Tehera&#x6E;**,** 70

Ital&#x79;**,** Rom&#x65;**,** 50

\[use&#x72;**@**&#x52;HEL4b pipes]**$** sort **-**&#x6B;2 countr&#x79;**.**&#x74;xt

German&#x79;**,** Berli&#x6E;**,** 100

Belgiu&#x6D;**,** Brussel&#x73;**,** 10

Franc&#x65;**,** Pari&#x73;**,** 60 Ital&#x79;**,** Rom&#x65;**,** 50

Ira&#x6E;**,** Tehera&#x6E;**,** 70

The screenshot below shows the difference between an alphabetical sort and a numerical sort **(**&#x62;oth on the third colum&#x6E;**).**

\[use&#x72;**@**&#x52;HEL4b pipes]**$** sort **-**&#x6B;3 countr&#x79;**.**&#x74;xt

Belgiu&#x6D;**,** Brussel&#x73;**,** 10

German&#x79;**,** Berli&#x6E;**,** 100 Ital&#x79;**,** Rom&#x65;**,** 50

Franc&#x65;**,** Pari&#x73;**,** 60

Ira&#x6E;**,** Tehera&#x6E;**,** 70

\[use&#x72;**@**&#x52;HEL4b pipes]**$** sort **-**&#x6E; **-**&#x6B;3 countr&#x79;**.**&#x74;xt

Belgiu&#x6D;**,** Brussel&#x73;**,** 10

Ital&#x79;**,** Rom&#x65;**,** 50

Franc&#x65;**,** Pari&#x73;**,** 60

Ira&#x6E;**,** Tehera&#x6E;**,** 70

German&#x79;**,** Berli&#x6E;**,** 100

### uniq <a href="#toc171120008" id="toc171120008"></a>

With **uniq** you can remove duplicates from a **sorted list.**

use&#x72;**@**&#x64;ebian&#x35;**:\~/**&#x70;ipe&#x73;**$** cat musi&#x63;**.**&#x74;xt

Queen

Brel

Queen Abba use&#x72;**@**&#x64;ebian&#x35;**:\~/**&#x70;ipe&#x73;**$** sort musi&#x63;**.**&#x74;xt

Abba

Brel Queen Queen use&#x72;**@**&#x64;ebian&#x35;**:\~/**&#x70;ipe&#x73;**$** sort musi&#x63;**.**&#x74;xt |uniq

Abba

Brel

Queen

### find <a href="#toc171120009" id="toc171120009"></a>

The **find** command can be very useful at the start of a pipe to search for file&#x73;**.** Here are some example&#x73;**.** You might want to add **2>/dev/null** to the command lines to avoid cluttering your screen with error message&#x73;**.**

Find all files in **/etc** and put the list in etcfile&#x73;**.**&#x74;xt

find **/**&#x65;tc **>** etcfile&#x73;**.**&#x74;xt

Find all files of the entire system and put the list in allfile&#x73;**.**&#x74;xt

find **/** **>** allfile&#x73;**.**&#x74;xt

Find files that end in **.**&#x63;onf in the current directory **(**&#x61;nd all subdir&#x73;**).**

find **.** **-**&#x6E;ame **“\*.**&#x63;on&#x66;**”**

Find files of type file **(**&#x6E;ot director&#x79;**,** pipe or et&#x63;**.)** that end in **.**&#x63;on&#x66;**.**

find **.** **-**&#x74;ype f **-**&#x6E;ame **“\*.**&#x63;on&#x66;**”**

Find files of type directory that end in **.**&#x62;ak **.**

find **/**&#x64;ata **-**&#x74;ype d **-**&#x6E;ame **“\*.**&#x62;a&#x6B;**”**

Find files that are newer than file4&#x32;**.**&#x74;xt

find **.** **-**&#x6E;ewer file4&#x32;**.**&#x74;xt

### Locate <a href="#toc171120010" id="toc171120010"></a>

The **locate** tool is very different from **find** in that it uses an index to locate file&#x73;**.** This is a lot faster than traversing all the directorie&#x73;**,** but it also means that it is always outdate&#x64;**.** If the index does not exist ye&#x74;**,** then you have to create it **(**&#x61;s root on Red Hat Enterprise Linu&#x78;**)** with the **updatedb** comman&#x64;**.**

\[use&#x72;**@**&#x52;HEL4b **\~**]**$** locate Samba warnin&#x67;**:** locat&#x65;**:** could not open databas&#x65;**:** **/**&#x76;a&#x72;**/**&#x6C;i&#x62;**/**&#x73;locat&#x65;**/**&#x73;locat&#x65;**.**&#x64;&#x62;**:...** warnin&#x67;**:** You need to run the **‘**&#x75;pdated&#x62;**’** command **(**&#x61;s roo&#x74;**)** to create t&#x68;**...**

Please have a look at **/**&#x65;t&#x63;**/**&#x75;pdated&#x62;**.**&#x63;onf to enable the daily cron jo&#x62;**.** \[use&#x72;**@**&#x52;HEL4b **\~**]**$** updatedb fatal erro&#x72;**:** updated&#x62;**:** You are not authorized to create a default slo&#x63;**...** \[use&#x72;**@**&#x52;HEL4b **\~**]**$** su Passwor&#x64;**:**

\[roo&#x74;**@**&#x52;HEL4b **\~**]**#** updatedb

\[roo&#x74;**@**&#x52;HEL4b **\~**]**#**

Most Linux distributions will schedule the **updatedb** to run once every da&#x79;**.** **date**

The **date** command can display the dat&#x65;**,** tim&#x65;**,** time zone and mor&#x65;**.**

use&#x72;**@**&#x72;hel55 **\~$** date Sat Apr 17

1&#x32;**:**&#x34;&#x34;**:**&#x33;0 CEST 2010

A date string can be customised to display the format of your choic&#x65;**.** Check the man page for more option&#x73;**.**

use&#x72;**@**&#x72;hel55 **\~$** date **+’%**&#x41; **%**&#x64;**-%**&#x6D;**-%**&#x59;**’** Saturday

1&#x37;**-**&#x30;&#x34;**-**&#x32;010

Time on any Unix is calculated in number of seconds since 1969 **(**&#x74;he first second being the first second of the first of January 197&#x30;**).** Use **date +%s** to display Unix time in second&#x73;**.**

| use&#x72;**@**&#x72;hel55 **\~$** date **+%**&#x73; 1271501080 |   |
| -------------------------------------------------------------- | - |

When will this seconds counter reach two thousand million ?

use&#x72;**@**&#x72;hel55 **\~$** date **-**&#x64; **‘**&#x31;97&#x30;**-**&#x30;&#x31;**-**&#x30;1 **+** 2000000000 second&#x73;**’** Wed May 18 0&#x34;**:**&#x33;&#x33;**:**&#x32;0 CEST 2033

### cal <a href="#toc171120011" id="toc171120011"></a>

The **cal** command displays the current mont&#x68;**,** with the current day highlighte&#x64;**.**

use&#x72;**@**&#x72;hel55 **\~$** cal April 2010

Su Mo Tu We Th Fr Sa

1 2 3

4 5 6 7 8 9 10

11 12 13 14 15 16 17

18 19 20 21 22 23 24

25 26 27 28 29 30

You can select any month in the past or the futur&#x65;**.**

use&#x72;**@**&#x72;hel55 **\~$** cal 2 1970

February 1970

Su Mo Tu We Th Fr Sa

1 2 3 4 5 6 7

8 9 10 11 12 13 14

15 16 17 18 19 20 21

22 23 24 25 26 27 28

### sleep <a href="#toc171120012" id="toc171120012"></a>

The **sleep** command is sometimes used in scripts to wait a number of second&#x73;**.** This example shows a five second **sleep.**

use&#x72;**@**&#x72;hel55 **\~$** sleep 5 use&#x72;**@**&#x72;hel55 **\~$**

### time <a href="#toc171120013" id="toc171120013"></a>

The **time** command can display how long it takes to execute a comman&#x64;**.** The **date** command takes only a little tim&#x65;**.**

use&#x72;**@**&#x72;hel55 **\~$** time date Sat Apr 17 1&#x33;**:**&#x30;&#x38;**:**&#x32;7 CEST 2010

real 0m&#x30;**.**&#x30;14s user 0m&#x30;**.**&#x30;08s sys 0m&#x30;**.**&#x30;06s

The **sleep 5** command takes five **real** seconds to execut&#x65;**,** but consumes little **cpu time.**

use&#x72;**@**&#x72;hel55 **\~$** time sleep 5

real 0m&#x35;**.**&#x30;18s user 0m&#x30;**.**&#x30;05s sys 0m&#x30;**.**&#x30;11s

This **bzip2** command compresses a file and uses a lot of **cpu time.**

use&#x72;**@**&#x72;hel55 **\~$** time bzip2 tex&#x74;**.**&#x74;xt

real 0m&#x32;**.**&#x33;68s user 0m&#x30;**.**&#x38;47s sys 0m&#x30;**.**&#x35;39s

### gzip - gunzip <a href="#toc171120014" id="toc171120014"></a>

Users never have enough disk spac&#x65;**,** so compression comes in hand&#x79;**.** The **gzip** command can make files take up less spac&#x65;**.**

use&#x72;**@**&#x72;hel55 **\~$** ls **-**&#x6C;h tex&#x74;**.**&#x74;xt

**-**&#x72;&#x77;**-**&#x72;&#x77;**-**&#x72;**--** 1 user user &#x36;**.**&#x34;M Apr 17 1&#x33;**:**&#x31;1 tex&#x74;**.**&#x74;xt use&#x72;**@**&#x72;hel55 **\~$** gzip tex&#x74;**.**&#x74;xt use&#x72;**@**&#x72;hel55

**\~$** ls **-**&#x6C;h tex&#x74;**.**&#x74;x&#x74;**.**&#x67;z

**-**&#x72;&#x77;**-**&#x72;&#x77;**-**&#x72;**--** 1 user user 760K Apr 17 1&#x33;**:**&#x31;1 tex&#x74;**.**&#x74;x&#x74;**.**&#x67;z

You can get the original back with **gunzip.**

use&#x72;**@**&#x72;hel55 **\~$** gunzip tex&#x74;**.**&#x74;x&#x74;**.**&#x67;z use&#x72;**@**&#x72;hel55

**\~$** ls **-**&#x6C;h tex&#x74;**.**&#x74;xt

**-**&#x72;&#x77;**-**&#x72;&#x77;**-**&#x72;**--** 1 user user &#x36;**.**&#x34;M Apr 17 1&#x33;**:**&#x31;1 tex&#x74;**.**&#x74;xt

### repeating the last command <a href="#toc171120015" id="toc171120015"></a>

To repeat the last command in bas&#x68;**,** type **!!.** This is pronounced as **bang bang.**

use&#x72;**@**&#x64;ebian&#x35;**:\~/**&#x74;est4&#x32;**$** **echo this will be repeated > file42.txt** use&#x72;**@**&#x64;ebian&#x35;**:\~/**&#x74;est4&#x32;**$** **!!** echo this will be repeated **>** file4&#x32;**.**&#x74;xt use&#x72;**@**&#x64;ebian&#x35;**:\~/**&#x74;est4&#x32;**$**

### repeating other commands <a href="#toc171120016" id="toc171120016"></a>

You can repeat other commands using one **bang** followed by one or more character&#x73;**.** The shell will repeat the last command that started with those character&#x73;**.**

| use&#x72;**@**&#x64;ebian&#x35;**:\~/**&#x74;est4&#x32;**$** **touch**                                                                                                                                                                                                                               | **file42** |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------- |
| <p>user<strong>@</strong>debian5<strong>:~~/</strong>test42<strong>$</strong> <strong>cat</strong></p><p>user<strong>@</strong>debian5<strong>:~~/</strong>test42<strong>$</strong> <strong>!to</strong> touch file42 user<strong>@</strong>debian5<strong>:\~/</strong>test42<strong>$</strong></p> | **file42** |

### history <a href="#toc171120017" id="toc171120017"></a>

To see older command&#x73;**,** use **history** to display the shell command history **(**&#x6F;r use **history n** to see the last n command&#x73;**).**

use&#x72;**@**&#x64;ebian&#x35;**:\~/**&#x74;es&#x74;**$** **history 10**

1. mkdir test
2. cd test
3. touch file1
4. echo hello **>** file2
5. echo It is very cold today **>** winte&#x72;**.**&#x74;xt
6. ls
7. ls **-**&#x6C;
8. cp winte&#x72;**.**&#x74;xt summe&#x72;**.**&#x74;xt
9. ls **-**&#x6C;
10. history 10

### !n <a href="#toc171120018" id="toc171120018"></a>

When typing **!** followed by the number preceding the command you want repeate&#x64;**,** then the shell will echo the command and execute i&#x74;**.**

use&#x72;**@**&#x64;ebian&#x35;**:\~/**&#x74;es&#x74;**$** **!43**

ls file1 file2 summe&#x72;**.**&#x74;xt winte&#x72;**.**&#x74;xt

### Ctrl-r <a href="#toc171120019" id="toc171120019"></a>

Another option is to use **ctrl-r** to search in the histor&#x79;**.** In the screenshot below i only typed **ctrl-r** followed by four characters **apti** and it finds the last command containing these four consecutive character&#x73;**.**

use&#x72;**@**&#x64;ebian&#x35;**:\~$** **(**&#x72;evers&#x65;**-**&#x69;**-**&#x73;earc&#x68;**)**\`apt&#x69;**’:** sudo aptitude

install screen

### HISTSIZE <a href="#toc171120020" id="toc171120020"></a>

The **$**&#x48;ISTSIZE variable determines the number of commands that will be remembered in your current environmen&#x74;**.** Most distributions default this variable to 500 or 100&#x30;**.**

use&#x72;**@**&#x64;ebian&#x35;**:\~$** **echo $HISTSIZE** 500

You can change it to any value you lik&#x65;**.**

use&#x72;**@**&#x64;ebian&#x35;**:\~$** **HISTSIZE=15000** use&#x72;**@**&#x64;ebian&#x35;**:\~$** **echo $HISTSIZE** 15000

### HISTFILE <a href="#toc171120021" id="toc171120021"></a>

The **$**&#x48;ISTFILE variable points to the file that contains your histor&#x79;**.** The **bash** shell defaults this value to **\~/.bash\_history.**

use&#x72;**@**&#x64;ebian&#x35;**:\~$** **echo $HISTFILE /**&#x68;om&#x65;**/**&#x75;se&#x72;**/.**&#x62;as&#x68;**\_**&#x68;istory

A session history is saved to this file when you **exit** the sessio&#x6E;**!**

*Closing a gnom&#x65;**-**&#x74;erminal with the mous&#x65;**,** or typing **reboot** as root will NOT save your termina&#x6C;**’**&#x73; histor&#x79;**.***

### HISTFILESIZE <a href="#toc171120022" id="toc171120022"></a>

The number of commands kept in your history file can be set using **$**&#x48;ISTFILESIZ&#x45;**.**

use&#x72;**@**&#x64;ebian&#x35;**:\~$** **echo $HISTFILESIZE** 15000

### prevent recording a command <a href="#toc171120023" id="toc171120023"></a>

You can prevent a command from being recorded in **history** using a space prefi&#x78;**.**

use&#x72;**@**&#x64;ebian&#x38;**:\~/**&#x67;ithu&#x62;**$** **echo abc** abc

use&#x72;**@**&#x64;ebian&#x38;**:\~/**&#x67;ithu&#x62;**$** **echo def** def

use&#x72;**@**&#x64;ebian&#x38;**:\~/**&#x67;ithu&#x62;**$** **echo ghi** ghi use&#x72;**@**&#x64;ebian&#x38;**:\~/**&#x67;ithu&#x62;**$** **history 3**

1. echo abc
2. echo ghi

### (optional)regular expressions <a href="#toc171120024" id="toc171120024"></a>

It is possible to use **regular expressions** when using the **bang** to repeat command&#x73;**.** The screenshot below switches 1 into &#x32;**.**

| <p>user<strong>@</strong>debian5<strong>:~~/</strong>test<strong>$</strong> <strong>cat</strong></p><p>user<strong>@</strong>debian5<strong>:~~/</strong>test<strong>$</strong> <strong>!c:s/1/2</strong> cat file2</p><p>hello</p><p>user<strong>@</strong>debian5<strong>:\~/</strong>test<strong>$</strong></p> |   | **file1** |
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | - | --------- |

### (optional) Korn shell history <a href="#toc171120025" id="toc171120025"></a>

Repeating a command in the **Korn shell** is very simila&#x72;**.** The Korn shell also has the **history** comman&#x64;**,** but uses the letter **r** to recall lines from histor&#x79;**.**

This screenshot shows the history comman&#x64;**.** Note the different meaning of the paramete&#x72;**.**

**$** **history 17**

1. clear
2. echo hoi
3. history 12
4. echo world
5. history 17

Repeating with **r** can be combined with the line numbers given by the history comman&#x64;**,** or with the first few letters of the comman&#x64;**.**

**$** **r e** echo world world **$** **cd /etc**

**$** **r** cd **/**&#x65;tc

**$**

### Introduction to users <a href="#toc171120026" id="toc171120026"></a>

This little chapter will teach you how to identify your user account on a Unix computer using commands like **who am i,** **id,** and mor&#x65;**.**

In a second part you will learn how to become another user with the **su** comman&#x64;**.**

And you will learn how to run a program as another user with **sudo.**

### whoami <a href="#toc171120027" id="toc171120027"></a>

The **whoami** command tells you your usernam&#x65;**.**

\[use&#x72;**@**&#x63;entos7 **\~**]**$** **whoami** user \[use&#x72;**@**&#x63;entos7 **\~**]**$**

### who <a href="#toc171120028" id="toc171120028"></a>

The **who** command will give you information about who is logged on the syste&#x6D;**.**

\[use&#x72;**@**&#x63;entos7 **\~**]**$** **who** root pt&#x73;**/**&#x30; 201&#x34;**-**&#x31;&#x30;**-**&#x31;0 2&#x33;**:**&#x30;7 **(**&#x31;&#x30;**.**&#x31;0&#x34;**.**&#x33;&#x33;**.**&#x31;0&#x31;**)** user pt&#x73;**/**&#x31;

201&#x34;**-**&#x31;&#x30;**-**&#x31;0 2&#x33;**:**&#x33;0 **(**&#x31;&#x30;**.**&#x31;0&#x34;**.**&#x33;&#x33;**.**&#x31;0&#x31;**)** laura pt&#x73;**/**&#x32; 201&#x34;**-**&#x31;&#x30;**-**&#x31;0 2&#x33;**:**&#x33;4 **(**&#x31;&#x30;**.**&#x31;0&#x34;**.**&#x33;&#x33;**.**&#x39;&#x36;**)** tania pt&#x73;**/**&#x33; 201&#x34;**-**&#x31;&#x30;**-**&#x31;0 2&#x33;**:**&#x33;9 **(**&#x31;&#x30;**.**&#x31;0&#x34;**.**&#x33;&#x33;**.**&#x39;&#x31;**)** \[use&#x72;**@**&#x63;entos7 **\~**]**$**

### who am i <a href="#toc171120029" id="toc171120029"></a>

With **who am i** the **who** command will display only the line pointing to your current sessio&#x6E;**.**

\[use&#x72;**@**&#x63;entos7 **\~**]**$** **who am i**

user pt&#x73;**/**&#x31; 201&#x34;**-**&#x31;&#x30;**-**&#x31;0 2&#x33;**:**&#x33;0 **(**&#x31;&#x30;**.**&#x31;0&#x34;**.**&#x33;&#x33;**.**&#x31;0&#x31;**)** \[use&#x72;**@**&#x63;entos7 **\~**]**$**

### w <a href="#toc171120030" id="toc171120030"></a>

The **w** command shows you who is logged on and what they are doin&#x67;**.**

\[use&#x72;**@**&#x63;entos7 **\~**]**$** **w**

2&#x33;**:**&#x33;&#x34;**:**&#x30;7 up 31 mi&#x6E;**,** 2 user&#x73;**,** load averag&#x65;**:** &#x30;**.**&#x30;&#x30;**,** &#x30;**.**&#x30;&#x31;**,** &#x30;**.**&#x30;2

USER TTY LOGI&#x4E;**@** IDLE JCPU PCPU WHAT root pt&#x73;**/**&#x30; 2&#x33;**:**&#x30;7 1&#x35;**.**&#x30;0s &#x30;**.**&#x30;1s &#x30;**.**&#x30;1s top user pt&#x73;**/**&#x31; 2&#x33;**:**&#x33;0 &#x37;**.**&#x30;0s &#x30;**.**&#x30;0s &#x30;**.**&#x30;0s w \[use&#x72;**@**&#x63;entos7 **\~**]**$**

### id <a href="#toc171120031" id="toc171120031"></a>

The **id** command will give you your user i&#x64;**,** primary group i&#x64;**,** and a list of the groups that you belong t&#x6F;**.**

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **id** uid=100&#x30;**(**&#x75;se&#x72;**)** gid=100&#x30;**(**&#x75;se&#x72;**)** groups=100&#x30;**(**&#x75;se&#x72;**)**

On RHE&#x4C;**/**&#x43;entOS you will also get **SELinux** context information with this comman&#x64;**.**

\[roo&#x74;**@**&#x63;entos7 **\~**]**#** **id** uid=&#x30;**(**&#x72;oo&#x74;**)** gid=&#x30;**(**&#x72;oo&#x74;**)** groups=&#x30;**(**&#x72;oo&#x74;**)** context=unconfine&#x64;**\_**&#x75;**:**&#x75;nconfine&#x64;**\_**&#x72;**\\** **:**&#x75;nconfine&#x64;**\_**&#x74;**:**&#x73;&#x30;**-**&#x73;&#x30;**:**&#x63;&#x30;**.**&#x63;1023

### su to another user <a href="#toc171120032" id="toc171120032"></a>

The **su** command allows a user to run a shell as another use&#x72;**.**

laur&#x61;**@**&#x64;ebian&#x37;**:\~$** **su tania** Passwor&#x64;**:**

tani&#x61;**@**&#x64;ebian&#x37;**:/**&#x68;om&#x65;**/**&#x6C;aur&#x61;**$**

### su to root <a href="#toc171120033" id="toc171120033"></a>

Yes you can also **su** to become **root,** when you know the **root password.**

laur&#x61;**@**&#x64;ebian&#x37;**:\~$** **su root** Passwor&#x64;**:**

roo&#x74;**@**&#x64;ebian&#x37;**:/**&#x68;om&#x65;**/**&#x6C;aur&#x61;**#**

### su as root <a href="#toc171120034" id="toc171120034"></a>

You need to know the password of the user you want to substitute t&#x6F;**,** unless your are logged in as **root.** The **root** user can become any existing user without knowing that use&#x72;**’**&#x73; passwor&#x64;**.**

roo&#x74;**@**&#x64;ebian&#x37;**:\~#** **id** uid=&#x30;**(**&#x72;oo&#x74;**)** gid=&#x30;**(**&#x72;oo&#x74;**)** groups=&#x30;**(**&#x72;oo&#x74;**)** roo&#x74;**@**&#x64;ebian&#x37;**:\~#** **su -**

**valentina** valentin&#x61;**@**&#x64;ebian&#x37;**:\~$**

### su - $username <a href="#toc171120035" id="toc171120035"></a>

By defaul&#x74;**,** the **su** command maintains the same shell environmen&#x74;**.** To become another user and also get the target use&#x72;**’**&#x73; environmen&#x74;**,** issue the **su -** command followed by the target usernam&#x65;**.**

roo&#x74;**@**&#x64;ebian&#x37;**:\~#** **su laura** laur&#x61;**@**&#x64;ebian&#x37;**:/**&#x72;oo&#x74;**$**

**exit**

exit roo&#x74;**@**&#x64;ebian&#x37;**:\~#** **su - laura** laur&#x61;**@**&#x64;ebian&#x37;**:\~$** **pwd /**&#x68;om&#x65;**/**&#x6C;aura

### su - <a href="#toc171120036" id="toc171120036"></a>

When no username is provided to **su** or **su -,** the command will assume **root** is the targe&#x74;**.**

tani&#x61;**@**&#x64;ebian&#x37;**:\~$** **su -** Passwor&#x64;**:** roo&#x74;**@**&#x64;ebian&#x37;**:\~#**

### run a program as another user <a href="#toc171120037" id="toc171120037"></a>

The sudo program allows a user to start a program with the credentials of another use&#x72;**.** Before this work&#x73;**,** the system administrator has to set up the **/etc/sudoers** fil&#x65;**.** This can be useful to delegate administrative tasks to another user **(**&#x77;ithout giving the root passwor&#x64;**).**

The screenshot below shows the usage of **sudo.** User **user** received the right to run **useradd** with the credentials of **root.** This allows **user** to create new users on the system without becoming **root** and without knowing the **root password.**

First the command fails for **user.**

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **/usr/sbin/useradd -m valentina** userad&#x64;**:** Permission denie&#x64;**.** userad&#x64;**:** cannot lock **/**&#x65;t&#x63;**/**&#x70;assw&#x64;**;** try again late&#x72;**.**

But with **sudo** it work&#x73;**.**

use&#x72;**@**&#x64;ebian&#x37;**:\~$** **sudo /usr/sbin/useradd -m valentina**

\[sudo] password for use&#x72;**:** use&#x72;**@**&#x64;ebian&#x37;**:\~$**

### visudo <a href="#toc171120038" id="toc171120038"></a>

Check the man page of **visudo** before playing with the **/etc/sudoers** fil&#x65;**.** Editing the **sudoers** is out of scope for this fundamentals boo&#x6B;**.**

use&#x72;**@**&#x72;hel6&#x35;**:\~$** **apropos visudo**

visudo **(**&#x38;**)** **-** edit the sudoers file use&#x72;**@**&#x72;hel6&#x35;**:\~$**

### sudo su - <a href="#toc171120039" id="toc171120039"></a>

On some Linux systems like Debian stable and XDebian stabl&#x65;**,** the **root** user does not have a password se&#x74;**.** This means that it is not possible to login as **root** **(**&#x65;xtra securit&#x79;**).** To perform tasks as **root,** the first user is given all **sudo rights** via the **/etc/sudoers.** In fact all users that are members of the admin group can use sudo to run all commands as roo&#x74;**.**

roo&#x74;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~#** **grep admin /etc/sudoers**

**#** Members of the admin group may gain root privileges

**%**&#x61;dmin ALL=**(**&#x41;L&#x4C;**)** ALL

The end result of this is that the user can type **sudo su -** and become root without having to enter the root passwor&#x64;**.** The sudo command does require you to enter your own passwor&#x64;**.** Thus the password prompt in the screenshot below is for sud&#x6F;**,** not for s&#x75;**.**

use&#x72;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~$** **sudo su -** Passwor&#x64;**:** roo&#x74;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~#**

### sudo logging <a href="#toc171120040" id="toc171120040"></a>

Using **sudo** without authorization will result in a severe warnin&#x67;**:**

use&#x72;**@**&#x72;hel6&#x35;**:\~$** **sudo su -**

We trust you have received the usual lecture from the local System Administrato&#x72;**.** It usually boils down to these three thing&#x73;**:**

**#**&#x31;**)** Respect the privacy of other&#x73;**.**

**#**&#x32;**)** Think before you typ&#x65;**.**

**#**&#x33;**)** With great power comes great responsibilit&#x79;**.**

\[sudo] password for use&#x72;**:** user is not in the sudoers fil&#x65;**.** This incident will be reporte&#x64;**.** use&#x72;**@**&#x72;hel6&#x35;**:\~$**

The root user can see this in the **/var/log/secure** on Red Hat and in **/var/log/auth.log** on Debia&#x6E;**).**

roo&#x74;**@**&#x72;hel6&#x35;**:\~#** **tail /var/log/secure | grep sudo | tr -s ‘ ‘**

Apr 13 1&#x36;**:**&#x30;&#x33;**:**&#x34;2 rhel65 sud&#x6F;**:** user **:** user NOT in sudoers **;** TTY=pt&#x73;**/**&#x30; **;** PWD=**\\**

**/**&#x68;om&#x65;**/**&#x75;ser **;** USER=root **;** COMMAND=**/**&#x62;i&#x6E;**/**&#x73;u **-** roo&#x74;**@**&#x72;hel6&#x35;**:\~#**

### user management <a href="#toc171120041" id="toc171120041"></a>

This chapter will teach you how to use **useradd,** **usermod** and **userdel** to creat&#x65;**,** modify and remove user account&#x73;**.** You will need **root** access on a Linux computer to complete this chapte&#x72;**.**

User management on Linux can be done in three complementary way&#x73;**.** You can use the **graphical** tools provided by your distributio&#x6E;**.** These tools have a look and feel that depends on the distributio&#x6E;**.** If you are a novice Linux user on your home syste&#x6D;**,** then use the graphical tool that is provided by your distributio&#x6E;**.** This will make sure that you do not run into problem&#x73;**.**

Another option is to use **command line tools** like userad&#x64;**,** usermo&#x64;**,** gpassw&#x64;**,** passwd and other&#x73;**.** Server administrators are likely to use these tool&#x73;**,** since they are familiar and very similar across many different distribution&#x73;**.** This chapter will focus on these command line tool&#x73;**.**

A third and rather extremist way is to **edit the local configuration files** directly using vi **(**&#x6F;r vip&#x77;**/**&#x76;ig&#x72;**).** Do not attempt this as a novice on production system&#x73;**!**

### /etc/passwd <a href="#toc171120042" id="toc171120042"></a>

The local user database on Linux **(**&#x61;nd on most Unixe&#x73;**)** is **/etc/passwd.**

\[roo&#x74;**@**&#x52;HEL5 **\~**]**#** **tail /etc/passwd** ing&#x65;**:**&#x78;**:**&#x35;1&#x38;**:**&#x35;2&#x34;**:**&#x61;rt deale&#x72;**:/**&#x68;om&#x65;**/**&#x69;ng&#x65;**:/**&#x62;i&#x6E;**/**&#x6B;sh an&#x6E;**:**&#x78;**:**&#x35;1&#x39;**:**&#x35;2&#x35;**:**&#x66;lute playe&#x72;**:/**&#x68;om&#x65;**/**&#x61;n&#x6E;**:/**&#x62;i&#x6E;**/**&#x62;ash frederi&#x6B;**:**&#x78;**:**&#x35;2&#x30;**:**&#x35;2&#x36;**:**&#x72;ubius poe&#x74;**:/**&#x68;om&#x65;**/**&#x66;rederi&#x6B;**:/**&#x62;i&#x6E;**/**&#x62;ash steve&#x6E;**:**&#x78;**:**&#x35;2&#x31;**:**&#x35;2&#x37;**:**&#x72;oman empero&#x72;**:/**&#x68;om&#x65;**/**&#x73;teve&#x6E;**:/**&#x62;i&#x6E;**/**&#x62;ash pascal&#x65;**:**&#x78;**:**&#x35;2&#x32;**:**&#x35;2&#x38;**:**&#x61;rtis&#x74;**:/**&#x68;om&#x65;**/**&#x70;ascal&#x65;**:/**&#x62;i&#x6E;**/**&#x6B;sh geer&#x74;**:**&#x78;**:**&#x35;2&#x34;**:**&#x35;3&#x30;**:**&#x6B;ernel develope&#x72;**:/**&#x68;om&#x65;**/**&#x67;eer&#x74;**:/**&#x62;i&#x6E;**/**&#x62;ash wi&#x6D;**:**&#x78;**:**&#x35;2&#x35;**:**&#x35;3&#x31;**:**&#x6D;aster damut&#x69;**:/**&#x68;om&#x65;**/**&#x77;i&#x6D;**:/**&#x62;i&#x6E;**/**&#x62;ash sandr&#x61;**:**&#x78;**:**&#x35;2&#x36;**:**&#x35;3&#x32;**:**&#x72;adish stresse&#x72;**:/**&#x68;om&#x65;**/**&#x73;andr&#x61;**:/**&#x62;i&#x6E;**/**&#x62;ash

As you can se&#x65;**,** this file contains seven columns separated by a colo&#x6E;**.** The columns contain the usernam&#x65;**,** an &#x78;**,** the user i&#x64;**,** the primary group i&#x64;**,** a descriptio&#x6E;**,** the name of the home director&#x79;**,** and the login shel&#x6C;**.**

More information can be found by typing **man 5 passwd.**

\[roo&#x74;**@**&#x52;HEL5 **\~**]**#** **man 5 passwd**

### root <a href="#toc171120043" id="toc171120043"></a>

The **root** user also called the **superuser** is the most powerful account on your Linux syste&#x6D;**.** This user can do almost anythin&#x67;**,** including the creation of other user&#x73;**.** The root user always has userid 0 **(**&#x72;egardless of the name of the accoun&#x74;**).**

\[roo&#x74;**@**&#x52;HEL5 **\~**]**#** **head -1 /etc/passwd** roo&#x74;**:**&#x78;**:**&#x30;**:**&#x30;**:**&#x72;oo&#x74;**:/**&#x72;oo&#x74;**:/**&#x62;i&#x6E;**/**&#x62;ash

### Useradd <a href="#toc171120044" id="toc171120044"></a>

You can add users with the **useradd** comman&#x64;**.** The example below shows how to add a user named yanina **(**&#x6C;ast paramete&#x72;**)** and at the same time forcing the creation of the home directory **(-**&#x6D;**),** setting the name of the home directory **(-**&#x64;**),** and setting a description **(-**&#x63;**).**

\[roo&#x74;**@**&#x52;HEL5 **\~**]**#** **useradd -m -d /home/yanina -c “yanina wickmayer” yanina** \[roo&#x74;**@**&#x52;HEL5 **\~**]**#** **tail -1 /etc/passwd** yanin&#x61;**:**&#x78;**:**&#x35;2&#x39;**:**&#x35;2&#x39;**:**&#x79;anina wickmaye&#x72;**:/**&#x68;om&#x65;**/**&#x79;anin&#x61;**:/**&#x62;i&#x6E;**/**&#x62;ash

The user named yanina received userid 529 and **primary group** id 52&#x39;**.**

### /etc/default/useradd <a href="#toc171120045" id="toc171120045"></a>

Both Red Hat Enterprise Linux and Debia&#x6E;**/**&#x44;ebian stable have a file called **/etc/default/useradd** that contains some default user option&#x73;**.** Besides using cat to display this fil&#x65;**,** you can also use **useradd -D.**

\[roo&#x74;**@**&#x52;HEL4 **\~**]**#** **useradd -D**

GROUP=100

HOME=**/**&#x68;ome INACTIVE=**-**&#x31;

EXPIRE=

SHELL=**/**&#x62;i&#x6E;**/**&#x62;ash

SKEL=**/**&#x65;t&#x63;**/**&#x73;kel

### userdel <a href="#toc171120046" id="toc171120046"></a>

You can delete the user yanina with **userdel.** The **-**&#x72; option of userdel will also remove the home director&#x79;**.**

\[roo&#x74;**@**&#x52;HEL5 **\~**]**#** **userdel -r yanina**

### usermod <a href="#toc171120047" id="toc171120047"></a>

You can modify the properties of a user with the **usermod** comman&#x64;**.** This example uses **usermod** to change the description of the user harr&#x79;**.**

\[roo&#x74;**@**&#x52;HEL4 **\~**]**#** **tail -1 /etc/passwd** harr&#x79;**:**&#x78;**:**&#x35;1&#x36;**:**&#x35;2&#x30;**:**&#x68;arry potte&#x72;**:/**&#x68;om&#x65;**/**&#x68;arr&#x79;**:/**&#x62;i&#x6E;**/**&#x62;ash

\[roo&#x74;**@**&#x52;HEL4 **\~**]**#** **usermod -c ‘wizard’ harry**

\[roo&#x74;**@**&#x52;HEL4 **\~**]**#** **tail -1 /etc/passwd** harr&#x79;**:**&#x78;**:**&#x35;1&#x36;**:**&#x35;2&#x30;**:**&#x77;izar&#x64;**:/**&#x68;om&#x65;**/**&#x68;arr&#x79;**:/**&#x62;i&#x6E;**/**&#x62;ash

### creating home directories <a href="#toc171120048" id="toc171120048"></a>

The easiest way to create a home directory is to supply the **-m** option with **useradd** **(**&#x69;t is likely set as a default option on Linu&#x78;**).**

A less easy way is to create a home directory manually with **mkdir** which also requires setting the owner and the permissions on the directory with **chmod** and **chown** **(**&#x62;oth commands are discussed in detail in another chapte&#x72;**).**

\[roo&#x74;**@**&#x52;HEL5 **\~**]**#** **mkdir /home/laura**

\[roo&#x74;**@**&#x52;HEL5 **\~**]**#** **chown laura:laura /home/laura**

\[roo&#x74;**@**&#x52;HEL5 **\~**]**#** **chmod 700 /home/laura** \[roo&#x74;**@**&#x52;HEL5 **\~**]**#** **ls -ld /home/laura/**

drw&#x78;**------** 2 laura laura 4096 Jun 24 1&#x35;**:**&#x31;7 **/**&#x68;om&#x65;**/**&#x6C;aur&#x61;**/**

### /etc/skel/ <a href="#toc171120049" id="toc171120049"></a>

When using **useradd** the **-m** optio&#x6E;**,** the **/etc/skel/** directory is copied to the newly created home director&#x79;**.** The **/etc/skel/** directory contains some **(**&#x75;sually hidde&#x6E;**)** files that contain profile settings and default values for application&#x73;**.** In this way **/etc/skel/** serves as a default home directory and as a default user profil&#x65;**.**

\[roo&#x74;**@**&#x52;HEL5 **\~**]**#** **ls -la /etc/skel/** total 48 drwx&#x72;**-**&#x78;&#x72;**-**&#x78; 2 root root 4096 Apr 1 0&#x30;**:**&#x31;1 **.** drwx&#x72;**-**&#x78;&#x72;**-**&#x78; 97 root root 12288 Jun 24 1&#x35;**:**&#x33;6 **..**

**-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--** 1 root root 24 Jul 12 2006 **.**&#x62;as&#x68;**\_**&#x6C;ogout

**-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--** 1 root root 176 Jul 12 2006 **.**&#x62;as&#x68;**\_**&#x70;rofile

**-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--** 1 root root 124 Jul 12 2006 **.**&#x62;ashrc

### deleting home directories <a href="#toc171120050" id="toc171120050"></a>

The **-**&#x72; option of **userdel** will make sure that the home directory is deleted together with the user accoun&#x74;**.**

\[roo&#x74;**@**&#x52;HEL5 **\~**]**#** **ls -ld /home/wim/** drw&#x78;**------** 2 wim wim 4096 Jun 24 1&#x35;**:**&#x31;9 **/**&#x68;om&#x65;**/**&#x77;i&#x6D;**/**

\[roo&#x74;**@**&#x52;HEL5 **\~**]**#** **userdel -r wim**

\[roo&#x74;**@**&#x52;HEL5 **\~**]**#** **ls -ld /home/wim/** l&#x73;**:**

**/**&#x68;om&#x65;**/**&#x77;i&#x6D;**/:** No such file or directory

### login shell <a href="#toc171120051" id="toc171120051"></a>

The **/etc/passwd** file specifies the **login shell** for the use&#x72;**.** In the screenshot below you can see that user annelies will log in with the **/bin/bash** shel&#x6C;**,** and user laura with the **/bin/ksh** shel&#x6C;**.**

\[roo&#x74;**@**&#x52;HEL5 **\~**]**#** **tail -2 /etc/passwd** annelie&#x73;**:**&#x78;**:**&#x35;2&#x37;**:**&#x35;3&#x33;**:**&#x73;word fighte&#x72;**:/**&#x68;om&#x65;**/**&#x61;nnelie&#x73;**:/**&#x62;i&#x6E;**/**&#x62;ash laur&#x61;**:**&#x78;**:**&#x35;2&#x38;**:**&#x35;3&#x34;**:**&#x61;rt deale&#x72;**:/**&#x68;om&#x65;**/**&#x6C;aur&#x61;**:/**&#x62;i&#x6E;**/**&#x6B;sh

You can use the usermod command to change the shell for a use&#x72;**.**

| <p>\[root<strong>@</strong>RHEL5 <strong>~~</strong>]<strong>#</strong> <strong>usermod -s /bin/bash laura</strong></p><p>\[root<strong>@</strong>RHEL5 <strong>~~</strong>]<strong>#</strong> <strong>tail -1 /etc/passwd</strong> dealer<strong>:/</strong>home<strong>/</strong>laura<strong>:/</strong>bin<strong>/</strong>bash</p> | laur&#x61;**:**&#x78;**:**&#x35;2&#x38;**:**&#x35;3&#x34;**:**&#x61;rt |
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------- |

### chsh <a href="#toc171120052" id="toc171120052"></a>

Users can change their login shell with the **chsh** comman&#x64;**.** Firs&#x74;**,** user harry obtains a list of available shells **(**&#x68;e could also have done a **cat /etc/shells)** and then changes his login shell to the **Korn shell** **(/**&#x62;i&#x6E;**/**&#x6B;s&#x68;**).** At the next logi&#x6E;**,** harry will default into ksh instead of bas&#x68;**.**

\[laur&#x61;**@**&#x63;entos7 **\~**]**$** **chsh -l**

**/**&#x62;i&#x6E;**/**&#x73;h

**/**&#x62;i&#x6E;**/**&#x62;ash

**/**&#x73;bi&#x6E;**/**&#x6E;ologin **/**&#x75;s&#x72;**/**&#x62;i&#x6E;**/**&#x73;h

**/**&#x75;s&#x72;**/**&#x62;i&#x6E;**/**&#x62;ash

**/**&#x75;s&#x72;**/**&#x73;bi&#x6E;**/**&#x6E;ologin

**/**&#x62;i&#x6E;**/**&#x6B;sh

**/**&#x62;i&#x6E;**/**&#x74;csh

**/**&#x62;i&#x6E;**/**&#x63;sh

\[laur&#x61;**@**&#x63;entos7 **\~**]**$**

Note that the **-l** option does not exist on Debian and that the above screenshot assumes that **ksh** and **csh** shells are installe&#x64;**.**

The screenshot below shows how **laura** can change her default shell **(**&#x61;ctive on next logi&#x6E;**).**

\[laur&#x61;**@**&#x63;entos7 **\~**]**$** **chsh -s /bin/ksh** Changing shell for laur&#x61;**.**

Passwor&#x64;**:**

Shell change&#x64;**.**

### user passwords <a href="#toc171120053" id="toc171120053"></a>

This chapter will tell you more about passwords for local user&#x73;**.**

Three methods for setting passwords are explaine&#x64;**;** using the **passwd** comman&#x64;**,** using **openssel passwd,** and using the **crypt** function in a C progra&#x6D;**.**

The chapter will also discuss password settings and disablin&#x67;**,** suspending or locking account&#x73;**.**

### passwd <a href="#toc171120054" id="toc171120054"></a>

Passwords of users can be set with the **passwd** comman&#x64;**.** Users will have to provide their old password before twice entering the new on&#x65;**.**

\[tani&#x61;**@**&#x63;entos7 **\~**]**$** **passwd**

Changing password for user tani&#x61;**.**

Changing password for tani&#x61;**.**

**(**&#x63;urren&#x74;**)** UNIX passwor&#x64;**:**

New passwor&#x64;**:**

BAD PASSWOR&#x44;**:** The password is shorter than 8 characters New passwor&#x64;**:**

BAD PASSWOR&#x44;**:** The password is a palindrome New passwor&#x64;**:**

BAD PASSWOR&#x44;**:** The password is too similar to the old one passw&#x64;**:**

Have exhausted maximum number of retries for service

As you can se&#x65;**,** the passwd tool will do some basic verification to prevent users from using too simple password&#x73;**.** The **root** user does not have to follow these rules **(**&#x74;here will be a warning thoug&#x68;**).** The **root** user also does not have to provide the old password before entering the new password twic&#x65;**.**

roo&#x74;**@**&#x64;ebian&#x37;**:\~#** passwd tania Enter new UNIX passwor&#x64;**:** Retype new UNIX passwor&#x64;**:** passw&#x64;**:** password updated successfully

### shadow file <a href="#toc171120055" id="toc171120055"></a>

User passwords are encrypted and kept in **/etc/shadow.** The **/**&#x65;t&#x63;**/**&#x73;hadow file is read only and can only be read by roo&#x74;**.** We will see in the file permissions section how it is possible for users to change their passwor&#x64;**.** For no&#x77;**,** you will have to know that users can change their password with the **/usr/bin/passwd** comman&#x64;**.**

\[roo&#x74;**@**&#x63;entos7 **\~**]**#** **tail -4 /etc/shadow**

use&#x72;**:$**&#x36;**$**&#x69;kp2Xta5B&#x54;**.**&#x54;m&#x6C;**.**&#x70;**$**&#x32;TZjNnOYNNQKpwLJqoGJbVsZG&#x35;**/**&#x46;ti8ovBR&#x64;**.**&#x56;zRbiDSl7TE&#x71;**\\** IaSM&#x48;**.**&#x54;eBKnT&#x53;**/**&#x53;jlMruW8qffC0JNOR&#x57;**.**&#x42;TW&#x31;**:**&#x31;633&#x38;**:**&#x30;**:**&#x39;999&#x39;**:**&#x37;**:::**

tani&#x61;**:$**&#x36;**$**&#x38;&#x5A;**/**&#x7A;ovx&#x6A;**$**&#x39;qvoqT8i9KIrm&#x4E;**.**&#x6B;4EQwAF5ryz5yzNwEvYjAa9L5XVXQ&#x75;**.**&#x7A;4DlpvMRE&#x48;**\\** eQpQzvRnqFdKkVj17H5S&#x54;**.**&#x63;79HDZw&#x30;**:**&#x31;635&#x36;**:**&#x30;**:**&#x39;999&#x39;**:**&#x37;**:::**

laur&#x61;**:$**&#x36;**$**&#x67;lDuTY5&#x65;**$/**&#x4E;YYWLxfHgZFWeoujaXSMc&#x52;**.**&#x4D;&#x7A;**.**&#x6C;GOxtcxFocFVJNb98nbTPhWFXfKW&#x47;**\\** SyYh1WCv6763Wq5&#x34;**.**&#x77;24Yr3uAZBO&#x6D;**/:**&#x31;635&#x36;**:**&#x30;**:**&#x39;999&#x39;**:**&#x37;**:::**

valentin&#x61;**:$**&#x36;**$**&#x6A;rZa6PV&#x49;**$**&#x31;uQgqR6En9mZB6mKJ3LXRB4CnFko6LRhb&#x68;**.**&#x76;4iqUk9MVreui1lv&#x37;**\\** GxHOUDSKA0N55ZRNhGHa6T2ouFnVn&#x6F;**/**&#x30;o&#x31;**:**&#x31;635&#x36;**:**&#x30;**:**&#x39;999&#x39;**:**&#x37;**:::**

\[roo&#x74;**@**&#x63;entos7 **\~**]**#**

The **/etc/shadow** file contains nine colon separated column&#x73;**.** The nine fields contain **(**&#x66;rom left to righ&#x74;**)** the user nam&#x65;**,** the encrypted password **(**&#x6E;ote that only inge and laura have an encrypted passwor&#x64;**),** the day the password was last changed **(**&#x64;ay 1 is January &#x31;**,** 197&#x30;**),** number of days the password must be left unchange&#x64;**,** password expiry da&#x79;**,** warning number of days before password expir&#x79;**,** number of days after expiry before disabling the accoun&#x74;**,** and the day the account was disabled **(**&#x61;gai&#x6E;**,** since 197&#x30;**).** The last field has no meaning ye&#x74;**.**

All the passwords in the screenshot above are hashes of **hunter2.**

### Encryption with passwd <a href="#toc171120056" id="toc171120056"></a>

Passwords are stored in an encrypted forma&#x74;**.** This encryption is done by the **crypt** functio&#x6E;**.** The easiest **(**&#x61;nd recommende&#x64;**)** way to add a user with a password to the system is to add the user with the **useradd -m user** comman&#x64;**,** and then set the use&#x72;**’**&#x73; password with **passwd.**

\[roo&#x74;**@**&#x52;HEL4 **\~**]**#** **useradd -m xavier**

\[roo&#x74;**@**&#x52;HEL4 **\~**]**#** **passwd xavier** Changing password for user xavie&#x72;**.**

New UNIX passwor&#x64;**:** Retype new UNIX passwor&#x64;**:**

passw&#x64;**:** all authentication tokens updated successfull&#x79;**.**

\[roo&#x74;**@**&#x52;HEL4 **\~**]**#**

### encryption with openssl <a href="#toc171120057" id="toc171120057"></a>

Another way to create users with a password is to use the **-**&#x70; option of userad&#x64;**,** but that option requires an encrypted passwor&#x64;**.** You can generate this encrypted password with the **openssl passwd** comman&#x64;**.**

The **openssl passwd** command will generate several distinct hashes for the same passwor&#x64;**,** for this it uses a **salt.**

use&#x72;**@**&#x72;hel6&#x35;**:\~$** **openssl passwd hunter2**

86jcUNlnGDFpY use&#x72;**@**&#x72;hel6&#x35;**:\~$** **openssl passwd hunter2** Yj7mDO9OAnvq6 use&#x72;**@**&#x72;hel6&#x35;**:\~$** **openssl passwd hunter2**

YqDcJeGoDbzKA use&#x72;**@**&#x72;hel6&#x35;**:\~$**

This **salt** can be chosen and is visible as the first two characters of the has&#x68;**.**

use&#x72;**@**&#x72;hel6&#x35;**:\~$** **openssl passwd -salt 42 hunter2** 42ZrbtP1Ze8&#x47;**.**

use&#x72;**@**&#x72;hel6&#x35;**:\~$** **openssl passwd -salt 42 hunter2** 42ZrbtP1Ze8&#x47;**.**

use&#x72;**@**&#x72;hel6&#x35;**:\~$** **openssl passwd -salt 42 hunter2**

42ZrbtP1Ze8&#x47;**.** use&#x72;**@**&#x72;hel6&#x35;**:\~$**

This example shows how to create a user with passwor&#x64;**.**

roo&#x74;**@**&#x72;hel6&#x35;**:\~#** **useradd -m -p $(openssl passwd hunter2) mohamed**

### groups <a href="#toc171120058" id="toc171120058"></a>

Users can be listed in **groups.** Groups allow you to set permissions on the group level instead of having to set permissions for every individual use&#x72;**.**

Every Unix or Linux distribution will have a graphical tool to manage group&#x73;**.** Novice users are advised to use this graphical too&#x6C;**.** More experienced users can use command line tools to manage user&#x73;**,** but be carefu&#x6C;**:** Some distributions do not allow the mixed use of GUI and CLI tools to manage groups **(**&#x59;aST in Novell Sus&#x65;**).** Senior administrators can edit the relevant files directly with **vi** or **vigr.**

### groupadd <a href="#toc171120059" id="toc171120059"></a>

Groups can be created with the **groupadd** comman&#x64;**.** The example below shows the creation of five **(**&#x65;mpt&#x79;**)** group&#x73;**.**

| roo&#x74;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~#**                | groupadd | tennis   |
| ----------------------------------------------------------------------- | -------- | -------- |
| roo&#x74;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~#**                | groupadd | football |
| roo&#x74;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~#**                | groupadd | snooker  |
| roo&#x74;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~#**                | groupadd | formula1 |
| roo&#x74;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~#** groupadd salsa |          |          |

### group file <a href="#toc171120060" id="toc171120060"></a>

Users can be a member of several group&#x73;**.** Group membership is defined by the **/etc/group** fil&#x65;**.**

roo&#x74;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~#** tail **-**&#x35; **/**&#x65;t&#x63;**/**&#x67;roup tenni&#x73;**:**&#x78;**:**&#x31;00&#x36;**:** footbal&#x6C;**:**&#x78;**:**&#x31;00&#x37;**:** snooke&#x72;**:**&#x78;**:**&#x31;00&#x38;**:** formula&#x31;**:**&#x78;**:**&#x31;00&#x39;**:** sals&#x61;**:**&#x78;**:**&#x31;01&#x30;**:** roo&#x74;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~#**

The first field is the grou&#x70;**’**&#x73; nam&#x65;**.** The second field is the grou&#x70;**’**&#x73; **(**&#x65;ncrypte&#x64;**)** password **(**&#x63;an be empt&#x79;**).** The third field is the group identification or **GID.** The fourth field is the list of member&#x73;**,** these groups have no member&#x73;**.**

### groups <a href="#toc171120061" id="toc171120061"></a>

A user can type the **groups** command to see a list of groups where the user belongs t&#x6F;**.**

\[harr&#x79;**@**&#x52;HEL4b **\~**]**$** groups harry sports

\[harr&#x79;**@**&#x52;HEL4b **\~**]**$**

### usermod <a href="#toc171120062" id="toc171120062"></a>

Group membership can be modified with the useradd or **usermod** comman&#x64;**.**

roo&#x74;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~#** usermod **-**&#x61; **-**&#x47; tennis inge roo&#x74;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~#** usermod **-**&#x61; **-**&#x47; tennis katrien roo&#x74;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~#** usermod **-**&#x61; **-**&#x47; salsa katrien roo&#x74;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~#** usermod **-**&#x61; **-**&#x47; snooker sandra roo&#x74;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~#** usermod **-**&#x61; **-**&#x47; formula1 annelies roo&#x74;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~#** tail **-**&#x35; **/**&#x65;t&#x63;**/**&#x67;roup

tenni&#x73;**:**&#x78;**:**&#x31;00&#x36;**:**&#x69;ng&#x65;**,**&#x6B;atrien footbal&#x6C;**:**&#x78;**:**&#x31;00&#x37;**:**

snooke&#x72;**:**&#x78;**:**&#x31;00&#x38;**:**&#x73;andra formula&#x31;**:**&#x78;**:**&#x31;00&#x39;**:**&#x61;nnelies sals&#x61;**:**&#x78;**:**&#x31;01&#x30;**:**&#x6B;atrien roo&#x74;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~#**

Be careful when using **usermod** to add users to group&#x73;**.** By defaul&#x74;**,** the **usermod** command will **remove** the user from every group of which he is a member if the group is not listed in the comman&#x64;**!** Using the **-a** **(**&#x61;ppen&#x64;**)** switch prevents this behaviou&#x72;**.**

### groupmod <a href="#toc171120063" id="toc171120063"></a>

You can change the group name with the **groupmod** comman&#x64;**.**

roo&#x74;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~#** groupmod **-**&#x6E; darts snooker roo&#x74;**@**&#x70;redato&#x72;**-**&#x70;&#x63;**\~#** tail **-**&#x35; **/**&#x65;t&#x63;**/**&#x67;roup tenni&#x73;**:**&#x78;**:**&#x31;00&#x36;**:**&#x69;ng&#x65;**,**&#x6B;atrien footbal&#x6C;**:**&#x78;**:**&#x31;00&#x37;**:** formula&#x31;**:**&#x78;**:**&#x31;00&#x39;**:**&#x61;nnelies sals&#x61;**:**&#x78;**:**&#x31;01&#x30;**:**&#x6B;atrien dart&#x73;**:**&#x78;**:**&#x31;00&#x38;**:**&#x73;andra

### gpasswd <a href="#toc171120064" id="toc171120064"></a>

You can delegate control of group membership to another user with the **gpasswd** comman&#x64;**.** In the example below we delegate permissions to add and remove group members to serena for the sports grou&#x70;**.** Then we **su** to serena and add harry to the sports grou&#x70;**.**

\[roo&#x74;**@**&#x52;HEL4b **\~**]**#** gpasswd **-**&#x41; serena sports

\[roo&#x74;**@**&#x52;HEL4b **\~**]**#** su **-** serena \[seren&#x61;**@**&#x52;HEL4b **\~**]**$** id harry uid=51&#x36;**(**&#x68;arr&#x79;**)** gid=52&#x30;**(**&#x68;arr&#x79;**)** groups=52&#x30;**(**&#x68;arr&#x79;**)**

\[seren&#x61;**@**&#x52;HEL4b **\~**]**$** gpasswd **-**&#x61; harry sports

Adding user harry to group sports \[seren&#x61;**@**&#x52;HEL4b **\~**]**$** id harry uid=51&#x36;**(**&#x68;arr&#x79;**)** gid=52&#x30;**(**&#x68;arr&#x79;**)** groups=52&#x30;**(**&#x68;arr&#x79;**),**&#x35;2&#x32;**(**&#x73;port&#x73;**)**

\[seren&#x61;**@**&#x52;HEL4b **\~**]**$** tail **-**&#x31; **/**&#x65;t&#x63;**/**&#x67;roup sport&#x73;**:**&#x78;**:**&#x35;2&#x32;**:**&#x73;eren&#x61;**,**&#x76;enu&#x73;**,**&#x68;arry \[seren&#x61;**@**&#x52;HEL4b **\~**]**$**

Group administrators do not have to be a member of the grou&#x70;**.** They can remove themselves from a grou&#x70;**,** but this does not influence their ability to add or remove member&#x73;**.**

\[seren&#x61;**@**&#x52;HEL4b **\~**]**$** gpasswd **-**&#x64; serena sports

Removing user serena from group sports \[seren&#x61;**@**&#x52;HEL4b **\~**]**$** exit

Information about group administrators is kept in the **/etc/gshadow** fil&#x65;**.**

\[roo&#x74;**@**&#x52;HEL4b **\~**]**#** tail **-**&#x31; **/**&#x65;t&#x63;**/**&#x67;shadow sport&#x73;**:!:**&#x73;eren&#x61;**:**&#x76;enu&#x73;**,**&#x68;arry \[roo&#x74;**@**&#x52;HEL4b **\~**]**#**

To remove all group administrators from a grou&#x70;**,** use the **gpasswd** command to set an empty administrators lis&#x74;**.**

\[roo&#x74;**@**&#x52;HEL4b **\~**]**#** gpasswd **-**&#x41; **““** sports

### newgrp <a href="#toc171120065" id="toc171120065"></a>

You can start a **child shell** with a new temporary **primary group** using the **newgrp** comman&#x64;**.**

roo&#x74;**@**&#x72;hel6&#x35;**:\~#** mkdir prigroup

roo&#x74;**@**&#x72;hel6&#x35;**:\~#** cd prigrou&#x70;**/** roo&#x74;**@**&#x72;hel6&#x35;**:\~/**&#x70;rigrou&#x70;**#** touch standar&#x64;**.**&#x74;xt roo&#x74;**@**&#x72;hel6&#x35;**:\~/**&#x70;rigrou&#x70;**#** ls **-**&#x6C; total 0

**-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--.** 1 root root 0 Apr 13 1&#x37;**:**&#x34;9 standar&#x64;**.**&#x74;xt roo&#x74;**@**&#x72;hel6&#x35;**:\~/**&#x70;rigrou&#x70;**#** echo **$**&#x53;HLVL

1

roo&#x74;**@**&#x72;hel6&#x35;**:\~/**&#x70;rigrou&#x70;**#** newgrp tennis

roo&#x74;**@**&#x72;hel6&#x35;**:\~/**&#x70;rigrou&#x70;**#** echo **$**&#x53;HLVL

2

roo&#x74;**@**&#x72;hel6&#x35;**:\~/**&#x70;rigrou&#x70;**#** touch newgr&#x70;**.**&#x74;xt roo&#x74;**@**&#x72;hel6&#x35;**:\~/**&#x70;rigrou&#x70;**#** ls **-**&#x6C; total 0

**-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--.** 1 root tennis 0 Apr 13 1&#x37;**:**&#x34;9 newgr&#x70;**.**&#x74;xt **-**&#x72;&#x77;**-**&#x72;**--**&#x72;**--.** 1 root root 0 Apr 13 1&#x37;**:**&#x34;9 standar&#x64;**.**&#x74;xt roo&#x74;**@**&#x72;hel6&#x35;**:\~/**&#x70;rigrou&#x70;**#** exit exit

roo&#x74;**@**&#x72;hel6&#x35;**:\~/**&#x70;rigrou&#x70;**#**

### user profiles <a href="#toc171120066" id="toc171120066"></a>

Logged on users have a number of preset **(**&#x61;nd customize&#x64;**)** aliase&#x73;**,** variable&#x73;**,** and function&#x73;**,** but where do they come from ? The **shell** uses a number of startup files that are executed **(**&#x6F;r rather **sourced)** whenever the shell is invoke&#x64;**.** What follows is an overview of startup script&#x73;**.**

### system profile <a href="#toc171120067" id="toc171120067"></a>

Both the **bash** and the **ksh** shell will verify the existence of **/etc/profile** and **source** it if it exist&#x73;**.**

When reading this scrip&#x74;**,** you will notice **(**&#x62;oth on Debian and on Red Hat Enterprise Linu&#x78;**)** that it builds the PATH environment variable **(**&#x61;mong other&#x73;**).** The script might also change the PS1 variabl&#x65;**,** set the HOSTNAME and execute even more scripts like **/etc/inputrc** This screenshot uses grep to show PATH manipulation in **/etc/profile** on Debia&#x6E;**.**

roo&#x74;**@**&#x64;ebian&#x37;**:\~#** **grep PATH /etc/profile**

PATH=**“/**&#x75;s&#x72;**/**&#x6C;oca&#x6C;**/**&#x73;bi&#x6E;**:/**&#x75;s&#x72;**/**&#x6C;oca&#x6C;**/**&#x62;i&#x6E;**:/**&#x75;s&#x72;**/**&#x73;bi&#x6E;**:/**&#x75;s&#x72;**/**&#x62;i&#x6E;**:/**&#x73;bi&#x6E;**:/**&#x62;i&#x6E;**”** PATH=**“/**&#x75;s&#x72;**/**&#x6C;oca&#x6C;**/**&#x62;i&#x6E;**:/**&#x75;s&#x72;**/**&#x62;i&#x6E;**:/**&#x62;i&#x6E;**:/**&#x75;s&#x72;**/**&#x6C;oca&#x6C;**/**&#x67;ame&#x73;**:/**&#x75;s&#x72;**/**&#x67;ame&#x73;**”** export PATH roo&#x74;**@**&#x64;ebian&#x37;**:\~#**

This screenshot uses grep to show PATH manipulation in **/etc/profile** on RHEL&#x37;**/**&#x43;entOS&#x37;**.**

\[roo&#x74;**@**&#x63;entos7 **\~**]**#** **grep PATH /etc/profile** case **“:$**{PATH}**:”** in

PATH=**$**&#x50;AT&#x48;**:$**&#x31; PATH=**$**&#x31;**:$**&#x50;ATH export PATH USER LOGNAME MAIL HOSTNAME HISTSIZE HISTCONTROL \[roo&#x74;**@**&#x63;entos7 **\~**]**#**

The **root user** can use this script to set aliase&#x73;**,** function&#x73;**,** and variables for every user on the syste&#x6D;**.**

### bash\_profile <a href="#toc171120068" id="toc171120068"></a>

When this file exists in the home director&#x79;**,** then **bash** will source i&#x74;**.** On Debian Linux &#x35;**/**&#x36;**/**&#x37; this file does not exist by defaul&#x74;**.**

RHEL&#x37;**/**&#x43;entOS7 uses a small **\~/.bash\_profile** where it checks for the existence of **\~/.bashrc** and then sources i&#x74;**.** It also adds **$**&#x48;OM&#x45;**/**&#x62;in to the **$**&#x50;ATH variabl&#x65;**.**

\[roo&#x74;**@**&#x72;hel7 **\~**]**#** **cat /home/user/.bash\_profile**

**#** **.**&#x62;as&#x68;**\_**&#x70;rofile

**#** Get the aliases and functions if \[ **-**&#x66; **\~/.**&#x62;ashrc ]**;** then

**.** **\~/.**&#x62;ashrc fi **#** User specific environment and startup programs

PATH=**$**&#x50;AT&#x48;**:$**&#x48;OM&#x45;**/.**&#x6C;oca&#x6C;**/**&#x62;i&#x6E;**:$**&#x48;OM&#x45;**/**&#x62;in

export PATH \[roo&#x74;**@**&#x72;hel7 **\~**]**#**

### bash\_login <a href="#toc171120069" id="toc171120069"></a>

When **.bash\_profile** does not exis&#x74;**,** then **bash** will check for **\~/.bash\_login** and source i&#x74;**.**

Neither Debian nor Red Hat have this file by defaul&#x74;**.**

### profile <a href="#toc171120070" id="toc171120070"></a>

When neither **\~/.bash\_profile** and **\~/.bash\_login** exis&#x74;**,** then bash will verify the existence of **\~/.profile** and execute i&#x74;**.** This file does not exist by default on Red Ha&#x74;**.** On Debian this script can execute **\~/.bashrc** and will add **$**&#x48;OM&#x45;**/**&#x62;in to the **$**&#x50;ATH variabl&#x65;**.**

roo&#x74;**@**&#x64;ebian&#x37;**:\~#** **tail -11 /home/user/.profile** if \[ **-**&#x6E; **“$**&#x42;AS&#x48;**\_**&#x56;ERSIO&#x4E;**”** ]**;** then

**#** include **.**&#x62;ashrc if it exists

if \[ **-**&#x66; **“$**&#x48;OM&#x45;**/.**&#x62;ashr&#x63;**”** ]**;** then **.** **“$**&#x48;OM&#x45;**/.**&#x62;ashr&#x63;**”** fi fi

**#** set PATH so it includes use&#x72;**’**&#x73; private bin if it exists

if \[ **-**&#x64; **“$**&#x48;OM&#x45;**/**&#x62;i&#x6E;**”** ] **;** then

PATH=**“$**&#x48;OM&#x45;**/**&#x62;i&#x6E;**:$**&#x50;AT&#x48;**”** fi

RHE&#x4C;**/**&#x43;entOS does not have this file by defaul&#x74;**.**

### bashrc <a href="#toc171120071" id="toc171120071"></a>

The **\~/.bashrc** script is often sourced by other script&#x73;**.** Let us take a look at what it does by defaul&#x74;**.**

Red Hat uses a very simple **\~/.bashrc,** checking for **/etc/bashrc** and sourcing i&#x74;**.** It also leaves room for custom aliases and function&#x73;**.**

\[roo&#x74;**@**&#x72;hel7 **\~**]**#** **cat /home/user/.bashrc**

**#** **.**&#x62;ashrc

**#** Source global definitions if \[ **-**&#x66; **/**&#x65;t&#x63;**/**&#x62;ashrc ]**;** then **.** **/**&#x65;t&#x63;**/**&#x62;ashrc

fi

**#** Uncomment the following line if you do&#x6E;**’**&#x74; like systemct&#x6C;**’**&#x73; aut&#x6F;**-**&#x70;aging featur&#x65;**:**

**#** export SYSTEM&#x44;**\_**&#x50;AGER=

**#** User specific aliases and functions

On Debian this script is quite a bit longer and configures **$**&#x50;S&#x31;**,** some history variables and a number af active and inactive aliase&#x73;**.**

roo&#x74;**@**&#x64;ebian&#x37;**:\~#** wc **-**&#x6C; **/**&#x68;om&#x65;**/**&#x75;se&#x72;**/.**&#x62;ashrc

110 **/**&#x68;om&#x65;**/**&#x75;se&#x72;**/.**&#x62;ashrc

### bash\_logout <a href="#toc171120072" id="toc171120072"></a>

When exiting **bash,** it can execute **\~/.bash\_logout.**

Debian use this opportunity to clear the console scree&#x6E;**.**

seren&#x61;**@**&#x64;eb50&#x33;**:\~$** **cat .bash\_logout #** **\~/.**&#x62;as&#x68;**\_**&#x6C;ogou&#x74;**:** executed by bas&#x68;**(**&#x31;**)** when login shell exit&#x73;**.** **#** when leaving the console clear the screen to increase privacy

if \[ **“$**&#x53;HLV&#x4C;**”** = 1 ]**;** then

\[ **-**&#x78; **/**&#x75;s&#x72;**/**&#x62;i&#x6E;**/**&#x63;lea&#x72;**\_**&#x63;onsole ] **&&** **/**&#x75;s&#x72;**/**&#x62;i&#x6E;**/**&#x63;lea&#x72;**\_**&#x63;onsole **-**&#x71; fi

Red Hat Enterprise Linux 5 will simple call the **/usr/bin/clear** command in this scrip&#x74;**.**

\[seren&#x61;**@**&#x72;hel53 **\~**]**$** cat **.**&#x62;as&#x68;**\_**&#x6C;ogout

**#** **\~/.**&#x62;as&#x68;**\_**&#x6C;ogout **/**&#x75;s&#x72;**/**&#x62;i&#x6E;**/**&#x63;lear

Red Hat Enterprise Linux 6 and 7 create this fil&#x65;**,** but leave it empty **(**&#x65;xcept for a commen&#x74;**).**

use&#x72;**@**&#x72;hel6&#x35;**:\~$** **cat .bash\_logout**

**#** **\~/.**&#x62;as&#x68;**\_**&#x6C;ogout
