Day 2
1. Linux Directory Structure:
Most commonly used top-level directories:
/
“Root”, the top of the file system hierarchy
/bin
Binaries and other executable programs
/etc
System configuration files
/home
Home directory (various user files)
/opt
Optional or third party software
/tmp
Temporary space, typically cleared on reboot
/usr
User related programs, libraries, and docs.
/var
Variable data, most notably log files
Applications that are not shipped with the OS are typically installed in:
/usr/local/
/opt
Comprehensive Directory Listing
/boot
Files needed to boot the operating system.
/cdrom
Mount point for CD-ROMs.
/cgroup
Control Groups hierarchy.
/dev
Device files, typically controlled by the operating system and the system administrators.
/etc
System configuration files.
/export
Shared file systems.
/home
Home directories.
/lib
System Libraries.
/lib64
System Libraries, 64 bit.
/lost+found
Used by the file system to store recovered files after a file system check has been performed.
/media
Some Linux OS might use to mount removable media like CD-ROMs.
/mnt
Used to mount external file systems.
/opt
Optional or third party software.
/proc
Provides info about running processes.
/root
The home directory for the root account.
/sbin
System administration binaries.
/selinux
Used to display information about SELinux.
/usr/bin
Binaries and other executable programs.
/usr/lib
Libraries.
/usr/local
Locally installed software that is not part of the base operating system.
/usr/sbin
System administration binaries.
/var
Variable data, most notably log files.
/var/log
Log files.
Some Linux OS might use:
/srv
Contains data which is served by the system.
/srv/www
Web server files.
/srv/ftp
FTP files.
/sys
Used to display and sometimes configure the devices known to the Linux kernel.
Application directory structures:
Often install in:
/usr/local/programname
/usr/local/programname/bin
/usr/local/programname/etc
/usr/local/programname/lib
/usr/local/programname/log
Application installed in /opt
/opt/programname
/opt/programname/bin
/opt/programname/etc
/opt/programname/lib
/opt/programname/log
Examples of specific companies:
/opt/companyname
/opt/companyname/bin
/opt/companyname/etc
/opt/google
/opt/google/crhome
/opt/google/earth
Variation applications sometimes follow:
/etc/opt/programname
/opt/programname/bin
/opt/programname/lib
/var/opt/programname
Applications without given directory structure, so they are installed in a shared manner:
/usr/local/bin/programname
/usr/local/etc/programname.conf
/usr/local/lib/libprogramname.so
2. What is the Shell?
– The default interface to Linux
– A program that accepts your commands and executes those commands
– Also called a command-line interpreter
Command Line Interface (CLI)
Graphical User Interface (GUI)
The prompt:
[philipp@linuxsvr ~]$
Username and the Linux system I’m connected to. The dollar sign tells me that I am a normal user.
[philipp@linuxsvr ~]#
The pound sign typically tells me that I am a superuser or the root account (administrator in a windows system).
Example prompts:
philipp@linuxsvr $
[philipp@linuxsvr /tmp]$
linuxsvr:/home/philipp>
philipp@linuxsvr:~>
[16:45:51 linuxsvr ~]$
$
%
>
Tilde Expansion:
~philipp = /home/philipp
~pat = /home/pat
~root = /root
~ftp = /srv/ftp
3. Basic Linux Commands
ls
– Lists directory contents.
ls -l
– Long list of directory contents.
cd
– Changes the current directory.
cd
without any arguments takes you to your home directory.
pwd
– Displays the present working directory.
cat
– Concatenates and displays files.
echo
– Displays arguments to the screen.
echo $PATH
man
– Displays the online manual.
man ls
– To learn more about the command: ls
Type q
to exit the manual.
exit
– Exits the shell or your current session.
clear
– Clears the screen.
which
command:
which
– Locate a command.
which cat
which tac
– Display content of file in reverse order.
--help
command:
--help
– Add to a command to get help.
-h
– ls -h
i.e.
man
document navigation:
Enter key – Moves down line by line.
Space bar – Moves down an entire paoge.
Lower case ‘g’ key – Move to the top of the screen.
Capital ‘G’ key – Move to the bottom of the screen.
Lower case ‘q’ key – To exit/quit.
If you are not sure which command to use, you can search through the manual page using this command: man -k SEARCH_TERM
.
For example: man -k calendar
.
Directories:
.
– This directory.
..
– The parent directory.
cd -
– Change to the previous directory.
/
– Directory seperator (forward slash).
echo $OLDPWD
– Shows directory we have been previously in.
./cat
– Execute something in current directory, i.e. cat
(instead of the $PATH directory).
mkdir [-p] directory
– Create a directory.
rmdir [-p] directory
– Remove a empty directory.
rm -rf directory
– Recursively removes everything in and below that directory. (Be careful, using rm -rf
removes are not undoable!)
The part of the command in square brackets is optional.
[-p]
– Parents, for example:
mkdir -p 1 directory1/directory2/directory3
The ls
command:
ls -l
– Detailed list of directory content.
Example details displayed:
Permission: -rw-rw-r--
Number of links: 1
Owner name: philipp
Group name: users
Number of bytes in the file: 10400
Last modification time: Sep 27 08:52
File name: sales.data
Hidden files are not displayed using ls
, you need to use ls -a
. Hidden files begin with a dot i.e.: .mydata.
Combine the ls
command with command line arguments, for example ls
to list files with -l
to display a long list, and -a
for all files, including hidden.
ls -l -a
can also be written as ls -la
Use ls -F
to reveal file types.
or ls -lF
for a long listing format.
For example, ending with:
/
– A directory.
@
– A link (symbolic link to file).
*
– An executable.
ls -t
– List files by time.
ls -r
– Reverse order.
ls -latr
– Long listing including all files reverse sorted by time.
ls -R
– Lists files recursively, in the current directory and any sub-directory below that.
ls -d
– Only list directory names, not their content.
ls --color
– Colorize the output.
Combination of -F
and --color
: ls -F --color
If there is a file with a space (try to avoid this), you can use double or single quotes to execute a command: ls -l "my notes.txt"
The tree
command:
Similar to ls -R
, but creates visual output:
tree -d
– List directories only.
tree -C
– Colorize output.
Combine -d
and -C
: tree -Cd