Linux and Shell Programming
- Mohan
Why this Course?
Agenda
SECTION I
Introduction to Linux
SECTION VII
Basic Unix Tools
SECTION II
Command line Interface
SECTION VIII Regular Expressions
SECTION III
Shell Basics
SECTION IX VI Editor
SECTION IV
Pipes and Commands
SECTION X
Scripting
SECTION V
Cron Jobs
SECTION XI
User Management
SECTION VI
Linux File Tree
SECTION XII
File Security
SECTION I
How Linux came into this world?
Linux Architecture and Common Linux Terminology
Various Linux Distributions
Linux File System
Boot Process Have you ever wondered?
Display Manager - GUI
INTRODUCTION TO LINUX
How did the Linux came into this world?
In 1992.
LINUS TORVALDS
USING UNIX
How it is maintained now?
MODERATORS
DEVELOPER COMMUNITY
LINUS TORVALDS
5
History
In 1991, Linus Torvalds wrote his own OS kernel.
In 1992, Linux became an OS with GPL open source license.
Formed a strong developer community targeting intel x86 based pcs.
Developers created Patches add, edit, remove lines of code.
Patches from developer community Moderators Linus Torvalds Linux Kernel.
Subsequently ported for other hardware platforms.
Facts
Linux is based on UNIX.
Linux is Multi-user.
Linux uses a hierarchical file system with top node called root ( / )
Access to the OS through the shell
Offers a text based command interface
Linux Architecture and Common terminologies
OS
APPLICATION
KERNELBOOTLOADER
DAEMON
E
S
IU
T
L
U
M
SHELL
X11 WINDOW MANAGER
FILESYSTEM
PACKAGES/PACKAGE MANAGER
Common Linux Terminology
Kernel Glue between Hardware and applications
Distribution Collection of software making up a Linux distribution
Boot loader Program that boots the operating system (GRUB, LILO)
Service Programs that run as background processes (httpd, ftpd, dhcpd)
Shell Command line Interpreter
X11 window Manager Graphical subsystem for most of the Linux OS.
File system Method to store and organize files (ext3, ext4, Fat32, NTFS)
Package manager Manages the collection of software in the Linux OS.
8
Linux Distributions
Differences package management systems, software versions, and file locations.
Fedora (CentOS, RHEL)
The Linux kernel 2.6.32 is used in RHEL/CentOS 6.x
It uses the RPM-based yum package manager.
RHEL is widely used by enterprises which host their own systems.
SLES (OpenSUSE)
The Linux kernel 3.11 in openSUSE 12.3.
It uses the RPM-based zypper package manager.
It includes the YaST (Yet another System Tool) application for system administration purposes.
Debian (Ubuntu, Linux Mint)
The Linux kernel 3.13 is used in Ubuntu 14.04.
It uses the DPKG-based apt-get package manager.
Ubuntu has been widely used for cloud deployments.
10
Some questions worth thinking about before deciding on a distribution include:
What is the main function of the system? (server or desktop)
What types of packages are important to the organization? For example, web server, word
processing, etc.
How much hard disk space is available? For example, when installing Linux on an embedded
device, there will be space limitations.
How often are packages updated?
How long is the support cycle for each release? For example, LTS releases have long term
support.
Do you need kernel customization from the vendor?
What hardware are you running the Linux distribution on? For example, X86, ARM, PPC, etc.
Do you need long-term stability or short-term experimental software?
11
Linux File System
A file system storing and organizing
A partition is a logical part of the disk, whereas a file system is a method of storing/finding
files on a hard disk (usually in a partition).
ext2, ext3, ext4, XFS, JFS,NTFS, etc.
12
Linux File System contd..
Linux
Win
- /usr/bin
- C:\Windows\system32
Linux
Win
- case-sensitive
- not case-sensitive
http://www.pathname.com/fhs/pub/fhs-2.3.pdf - Become an Linux Expert!!!
13
The Boot Process..
When the computer is started, POST (Power On Self Test) is run.
BIOS is stored in the ROM chip.
Using the information in bios keyboard, monitor and memory are initialized and tested.
After POST, Control shifts to the Boot loader.
Boot loader is stored in the hard disk ( Boot Sector/ Efi partition)
14
The Boot Process..
The Boot loader is responsible for loading the Operating System.
1st Stage BIOS/MBR method
Boot loader resides at 1st sector of hard disk (MBR)
MBR also has the partition table.
Boot loader finds the bootable partition and searches 2nd stage of bootloader.
1st Stage EFI/UEFI method
UEFI Firmware contains a boot manager which has the location of EFI partition.
Boot loader resides in EFI partition in hard disk.
2nd Stage
2nd stage of boot loader resides under /boot.
Loads and compresses the kernel Image.
Analyses the hardware and loads the device drivers.
15
The Boot Process..
Besides starting the system, init is responsible for keeping the system running and for shutting it down cleanly
Getty -> responsible for asking you username and password
16
The Boot Process..
Generally, in a Linux desktop system, the X Window System is loaded as the final step in the
boot process.
A service called the display manager keeps track of the displays being provided, and loads
the X server (so-called because it provides graphical services to applications, sometimes
called X clients).
Session manager, starts and maintains the components of the graphical session.
Window manager, controls the placement and movement of windows.
17
Display Manager (X Window System)
GNOME is the default to display manager in most of the environment.
Unity, KDE, Xfce are the other desktop environments.
It is not mandatory for a Linux to have an X-system (Try ctrl+alt+fn)
18
SECTION II
INTRO TO LiNUX CLI
19
Why CLI
2 Ways GUI, CLI
NO overhead in CLI interface.
How do you change your username and password in linux?
GUI (GNOME) System Preferences AboutMe change password.
CLI
Open Terminal type passwd
How do you enter 50 files? How do you rename 50 files?
Which is easier for repetitive tasks?
How do you automate things?
graphical user interfaces make easy tasks easier, while command line interfaces
make difficult tasks possible
20
Working with directories
Commands
Description
cd
Change Directory
tree
Display the Directories and files in tree structure
pwd
Display current working directory
ls
List files
ls -a
List all files
ls -l
List file details
ls -lh
List file details human readable form
mkdir
Make a directory
rmdir
Remove a directory
rmdir -rf
Force remove a directory recursively
ln -s
Create soft link
Absolute and Relative Paths
Auto path Completion (tab)
Relative Paths..
Root directory
Home directory
Parent directory
..
Current directory
Previous directory
21
Try it Yourself
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
Display your current directory. Change to the /etc directory. Check your current directory again.
Now change to your home directory using only three key presses.
Change to the /boot/grub directory using only eleven key presses.
Go to the parent directory of the current directory using relative path.
Go to the root directory.
List the contents of the root directory. List a long listing of the root directory.
Stay where you are, and list the contents of /etc. Also, list the contents of /bin and /sbin.
Stay where you are, and list the contents of ~.
List all the files (including hidden files) in your home directory.
List the files in /boot in a human readable format.
Create a directory testdir in your home directory.
Change to the /etc directory, stay here and create a directory newdir in your home directory.
Create in one command the directories ~/dir1/dir2/dir3 (dir3 is a subdirectory from dir2, and dir2 is a
subdirectory from dir1 ).
Remove the directory testdir.
22
Working with files
File/Dir names are case sensitive
Everything is a file (directories are special cases)
Use i for interactive option
Commands
Description
file <>
Displays what type of file
touch
Create an empty file
touch -t
Change timestamp
rm
remove a file
rm -f
force remove file
rm -rf
Recursive force
cp <file1> <file2>
<dest>
Make copy of file/files
cp -r <dir1> <dir2> <dest>
Recursive copy (for directories)
mv
Rename/move
23
Try it Yourself
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
List the files in the /bin directory.
Display the type of file of /bin/cat, /etc/passwd and /usr/bin/passwd.
Download 46220.pdf using wget http://www.farnell.com/datasheets/46220.pdf
1.
Display the type of file of 46220.pdf
2.
Rename 46220.pdf to datasheet.jpg (use mv).
3.
Display the type of file of datasheet.jpg
Create a directory ~/touched and enter it. Create a empty file today.txt in touched.
Create a file yesterday.txt to match yesterday's date.
Copy yesterday.txt to copy.yesterday.txt
Create a directory called ~/testbackup and copy all files from ~/touched into it.
Create a sub-directory subdir in the directory testbackup
Use one command to remove the directory ~/testbackup and all files into it.
Create a directory ~/etcbackup and copy all *.conf files from /etc into it. Did you include all
subdirectories of /etc ?
24
Working with file contents
Commands
Description
head -<no_of_lines>
<file>
display the first ten lines of a file
Tail -<no_of_lines> <file>
display the last ten lines of a file
cat
Display/concatenate
cat > <filename>
Create a file
tac
Display the file reverse (line order)
more / less
displaying files that take up more than one screen
du h <file/dir>
25
Try it Yourself
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
Display the first 12 lines of /etc/services.
Display the last line of /etc/passwd.
Use cat to create a file named count.txt that looks like this: One Two Three Four Five
Use cp to make a backup of this file to cnt.txt.
Use cat to make a backup of this file to catcnt.txt.
Display catcnt.txt, but with all lines in reverse order (the last line first).
Use more to display /var/log/messages.
Use ls to find the biggest file in /etc. Use du find the biggest file.
Open two terminal windows (or tabs) and make sure you are in the same directory in both. Type echo
this is the first line > tailing.txt in the first terminal, then issue tail -f tailing.txt
in the second terminal. Now go back to the first terminal and type echo This is another line >>
tailing.txt (note the double >>), verify that the tail -f in the second terminal shows both lines. Stop the
tail -f with Ctrl-C.
Use cat to create a file named tailing.txt that contains the contents of tailing.txt followed by the
contents of /etc/passwd.
Use cat to create a file named tailing.txt that contains the contents of tailing.txt preceded by the contents
of /etc/passwd.
26
SECTION IV
SHELL CONCEPTS And Commands
27
Shell Expansion
arguments
White space removal (test with echo)
Single quotes & double quotes (double quotes allow parsing of variables, single quotes dont)
which command will search for binaries in the $PATH environment variable
External or builtin commands? (use type to check)
aliases
Can be used to temporarily substitute or abbreviate a commands. alias ll='ls -lh --color=auto'
Providing no argument will display all the aliases.
How to make permanent? (write in .bashrc)
unalias using unalias command.
display shell expansion with set x, and stop displaying it with set +x
28
Try it yourself
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
14.
How many arguments are in this line (not counting the command itself).
touch '/etc/cron/cron.allow' 'file 42.txt' "file 33.txt"
Is tac a shell builtin command ?
Is there an existing alias for rm ?
Read the man page of rm, make sure you understand the -i option of rm. Create and
Remove a file to test the -i option.
Execute: alias rm='rm -i' . Test your alias with a test file. Does this work as expected ?
List all current aliases.
Create an alias called 'city' that echoes your hometown.
Use your alias to test that it works.
Execute set -x to display shell expansion for every command.
Test the functionality of set -x by executing your city and rm aliases.
Execute set +x to stop displaying shell expansion.
Remove your city alias.
What is the location of the cat and the passwd commands ?
29
Try it yourself
13. Explain the difference between the following commands:
echo
/bin/echo
14. Explain the difference between the following commands:
echo Hello
echo -n Hello
15. Display A B C with two spaces between B and C.
16. Complete the following command (do not use spaces) to display exactly the
following output:
4+4
=8
10+14
=24
17. Use echo to display the following exactly:
??\\commands and arguments
85
Find two solutions with single quotes, two with double quotes and one without quotes
18. Use one echo command to display three words on three lines.
30
Shell Variables
Permanent shell variables called Environment variables, often needed by applications.
Shell variables can be created temporarily like aliases.( Use .bashrc to create Env variables)
Some examples to try $HOSTNAME, $USER, $UID, $SHELL, and $HOME.
Starts with a $sign and they are case sensitive.
Use the set command to display a list of both shell and environment variables. env only
gives environment variables, which are passed along to child processes.
Use the unset command to remove a variable from your shell environment.
Customize your terminal using $PS1
$PATH variable is determines where the shell is looking for binaries.
Use {} to combine variable to string. ${prefix}man
Unbound variables warning : set u and set +u
31
Try it Yourself
1. Use echo to display Hello followed by your username. (use a bash variable!)
2. Create a variable answer with a value of 42.
3. Copy the value of $LANG to $MyLANG.
4. List all current shell variables.
5. List all exported shell variables.
6. Do the env and set commands display your variable ?
6. Destroy your answer variable.
7. Create two variables, and export one of them.
8. Display the exported variable in an interactive child shell.
9. Create a variable, give it the value 'Dumb', create another variable with value 'do'. Use
echo and the two variables to echo Dumbledore.
10. Find the list of backslash escaped characters in the manual of bash. Add the time to your
PS1 prompt.
32
Different types of Shell..
Find default shell
Find all Shells available
Change shell
Change default shell
--->
--->
--->
grep <USERNAME> /etc/passwd
cat /etc/shells
Just type the shell name
---> csh
33
control operators
Operator
Description
Examples
Multiple commands run sequentially
echo Hello ; echo World
&
Run binaries in the background (shell will not wait)
vsim &
&&
second command is executed only if the first one
succeeds
cd <dir> && ls
||
second command is executed only when the
first command fails
echo first || echo second
&& and ||
#
rm file1 && echo It worked! || echo It
failed!
comment
\ escaping
\ backslash
echo escaping \\\ \#\ \&\ \"\ \'
Multiple arguments separated by backslash.
echo This command line \
> is split in three \
> parts
34
Try it yourself
Each question can be answered by one command line!
1. When you type passwd, which file is executed ?
2. What kind of file is that ?
3. Execute the pwd command twice. (remember 0.)
Demonstration of && and II
4. Execute ls after cd /etc, but only if cd /etc did not error.
5. Execute cd /etc after cd etc, but only if cd etc fails.
6. Echo it worked when touch test42 works, and echo it failed when the touch failed. All
on one command line as a normal user (not root). Test this line in your home directory and
in /bin/ .
7. Execute sleep 6, what is this command doing ?
8. Execute sleep 200 in background (do not wait for it to finish).
9. Write a command line that executes rm file55. Your command line should print 'success'
if file55 is removed, and print 'failed' if there was a problem.
(optional)10. Use echo to display "Hello World with strange' characters \ * [ } ~ \
\ ." (including all quotes)
35
Shell History
Example Commands
Descriptions
Up arrow Navigation
Execute the last command
!!
Execute the last command
!ec
Execute the last command that started with ec
history 10
History of last 10(n) commands.
!411
Executes the 411th (nth) command.
echo $HISTFILE
The commands are stored in .bash_history
36
Try it Yourself
1.
2.
3.
4.
5.
Issue the command - echo Hi welcome
Repeat the previous command using only two characters (there are two solutions!)
Display the last 5 commands you typed.
Issue the long echo from question 1 again, using the line numbers you received from the
command in question 3.
Where are these commands stored when exiting the shell ?
37
File Globbing generating file names
Examples
*
generate filenames, matching the asterisk
to any combination of characters (even none).
ls File*
matching the question mark with exactly one character.
ls file? ls file??
[]
any of the characters between [ and the first subsequent ]
ls file[A9] file[a-z]* ls [fF]ile[!1]
Try it Yourself
1. Create a test directory and enter it.
2. Create the following files : file1 file10 file11 file2
fileAB filea fileA fileAAA
file(
File2 File3
file 2
file33
38
Try it Yourself
3. List (with ls) all files starting with file
4. List (with ls) all files starting with File
5. List (with ls) all files starting with file and ending in a number.
6. List (with ls) all files starting with file and ending with a letter
7. List (with ls) all files starting with File and having a digit as fifth character.
8. List (with ls) all files starting with File and having a digit as fifth character and nothing else.
9. List (with ls) all files starting with a letter and ending in a number.
10. List (with ls) all files that have exactly five characters.
11. List (with ls) all files that start with f or F and end with 3 or A.
12. List (with ls) all files that start with f have i or R as second character and end in a number.
13. List all files that do not start with the letter F.
39
SECTION V
PIPES AND COMMANDS
40
Input/Output Redirection
)
1>
(
t
ou
d
t
S
Three basic streams (stream0, stream1, stream2)
Stdin(0<)
Bash
Stderr(2>)
>f
>Stdout
keyboard
ile
echo Hi! > file.txt
Bash
echo HI! 1> file.txt
display
>Stderr
ay
l
p
dis
keyboard
Bash
rm nothing.txt 2> err.txt
rm nothing.txt 1> out.txt 2> err.txt
rm nothing.txt 1> out.txt 2>&1
2> file
rm nothing.txt &> out_and_err.txt
41
Error
Redirection
To stdout
Redirection and pipes STDOUT (or) STDERR of one command to STDIN of a second
command
>> append append to the EOF
< stdin grep something (or) grep something < some_file
42
FILTERS
Examples
cat
putting stdin on stdout
tac sdf.txt | cat | cat | cat | cat | cat
tee
putting stdin on two stdout
cat sdf.txt | tee asdf.txt | cat
grep
lines matching the string.
cat sdf.txt | grep sachin
grep -v
lines not matching the string.
cat sdf.txt | grep v sachin
grep -i
Case insensitive
cat sdf.txt | grep i sachin
cut
Select columns from files, depending on a delimiter
cut -d: -f1,3 /etc/passwd | tail -3
echo 1:2:3:4:5 | cut -d: -f1,4
translate
Translate the characters
cat sdf.txt | tr 'e' 'E
cat sdf.txt | tr 'a-z' 'A-Z
cat sdf.txt | tr 'a-z' n-za-m
cat sdf.txt | tr s
wc
Count lines, words,
wc -l sdf.txt
wc -w
wc -c
43
Description
Examples
sort
Sort in order
sort sdf.txt
sort k2 sdf.txt
uniq
Remove reoccurrences and count reoccurences
sort sdf.txt | uniq
sort sdf.txt | uniq -c
comm
Compare two lists result in 3 columns
comm list1.txt list2.txt
sed
Streaming editor using regular expressions
echo level5 level7 | sed s/level/jump/g
cat sdf.txt | sed '/wor/d'
who | wc -l
who | cut -d' ' -f1 | sort
who | cut -d' ' -f1 | sort | uniq
grep bash /etc/passwd | cut -d: -f1
44
Try it Yourself
1. Put a sorted list of all bash users in bashusers.txt.
2. Put a sorted list of all logged on users in onlineusers.txt.
3. Make a list of all filenames in /etc that contain the string conf in their filename.
4. Make a sorted list of all files in /etc that contain the case insensitive string conf in their
filename.
5. Write a line that removes all non-letters from a stream.
6. Write a line that receives a text file, and outputs all words on a separate line.
7.Use grep and wc to find the no of modules in a netlist
45
Getting help
Commands
Description
man <command>
Manual page of a command
man <config_file>
Manual page of a command
man <daemon>
Manual page of a command
man k <partial_command>
List all relevant commands with one line description
apropos
Same as above
whatis
List the commands one line description
whereis
Displays the manual page location
mandb
Indexes the manual entries
Try it Yourself - Find what is the command to move a file. Where is the manual located?
Which.
Help
Go to bin dir
46
SECTION IX
FILESECURITY, CRON JOBS
47
Users and Groups
-
User
Type of File
Group
Others
Regular File
Directory
Permission
Access to files
Access to directory
Symbolic Link
/etc/motd
r (read)
Read contents (cat)
Read contents (ls)
w (write)
Edit contents (VI)
Create files/dirs (touch/mkdir)
Named Pipe
x (execute)
Execute the file (script.sh)
Open the directory (cd)
Block device
/dev/sda
Character device
/dev/console
socket
If you dont have access to a file, then you cant change its permissions
48
Permissions
Users and groups
ls lh
cut -d: -f1 /etc/passwd | column
chgrp <groupname><filename>
Change group
chown <username> <filename>
Change Owner
chmod
chgrp
chmod g-r
chmod u+x
chmod o-r
chmod a+w
If you dont have access to a file, then you cant change its permissions
49
TRY IT YOURSELF
1. As normal user, create a directory ~/permissions. Create a file owned by yourself in there.
2. Copy a file owned by root from /etc/ to your permissions dir, who owns this file now ?
3. As root, create a file in the users ~/permissions directory.
4. As normal user, look at who owns this file created by root.
5. Change the ownership of all files in ~/permissions to yourself.
6. Make sure you have all rights to these files, and others can only read.
7. With chmod, is 770 the same as rwxrwx--- ?
8. With chmod, is 664 the same as r-xr-xr-- ?
9. With chmod, is 400 the same as r-------- ?
10. With chmod, is 734 the same as rwxr-xr--
50
Cron Job sheduler
30 10 * * * echo HI >file.txt
30 10 * * * cd ~ && echo HI >file.txt
crontab -l lists all the scheduled tasks
crontab -e schedule new task or edit running tasks(editor)
0 */2 * * * /home/verif.pl
00 20 * * * /home/dft.sh
51
TRY IT YOURSELF
Create cron directory in home folder.
Use the date command to see the current timing.
Schedule a job that puts Hi Welcome in the file hi.txt. hi.txt should be in the directory ~/cron
Schedule a job to append date and time every minute.
52
SECTION VI
MISSED BASIC UNIX TOOLS
53
find
locate
date
cal
sleep
time
gzip
zcat
bzip and bzip2
tar
54
TRY IT YOURSELF
1. Explain the difference between these two commands. This question is very important. If
you don't know the answer, then look back at the shell chapter.
find /data -name "*.txt"
find /data -name *.txt
2. Explain the difference between these two statements. Will they both work when there are
200 .odf files in /data ? How about when there are 2 million .odf files ?
find /data -name "*.odf" > data_odf.txt
find /data/*.odf > data_odf.txt
3. Write a find command that finds all files created after January 30th 2010.
4. Write a find command that finds all *.odf files created in September 2009.
5. Count the number of *.conf files in /etc and all its subdirs.
55
6. Two commands that do the same thing: copy *.odf files to /backup/ . What would be a
reason to replace the first command with the second ? Again, this is an important question.
cp -r /data/*.odf /backup/
find /data -name "*.odf" -exec cp {} /backup/ \;
7. Create a file called loctest.txt. Can you find this file with locate ? Why not ? How do
you make locate find this file ?
8. Use find and -exec to rename all .htm files to .html.
9. Issue the date command. Now display the date in YYYY/MM/DD format.
10. Issue the cal command. Display a calendar of 1582 and 1752. Notice anything special ?
56
SECTION III
Linux File tree
57
Linux file tree
/bin
bin binaries for all users
sbin - binaries to configure the operating system
/lib
/bin and /sbin often use shared libraries located in /lib
Lib32 and lib64
/opt
/opt is to store optional software
Empty at the start
58
Linux file tree configuration and data directories
Data Directories
/etc
Editable Text Configuration
Contains machine-specific configuration files
/home
init.d
Start and stop daemons
/srv
Data served by your system
x11
/etc/X11/xorg.conf
/media
skel
Skeleton dir for new home dir
Mount point for removable
devices
sysconfig OS related config
/root
/mnt
/tmp
Temporary files
/boot
/boot directory contains all files needed to boot the
computer
.cfg or .conf
59
Linux file tree
Unix system resources
Memory Directories
/usr
Sharable, read only data
/dev
populated with files as the kernel
is recognising hardware
/usr/bin
User related binaries
/dev/sda
Harddisk related
/usr/include
Include files for c
/dev/tty
/dev/pts
Terminal files
/usr/local
Install software locally (admin)
/usr/share
architecture independent data
/proc
what the kernel manages, and is
a means to interact with it directly
/proc/cpuinfo
/
proc/interrup
ts
displays the interrupts
/proc/kcore
The physical memory is
represented in /proc/kcore
Variable data
/var/log
All log files
/var/log/messages
What has gone wrong
(event viewer)
/var/cache
cache data for several
applications.
60
Try it yourself
1. Does the file /bin/cat exist ? What about /bin/dd and /bin/echo. What is the type of these
files ?
2. What is the size of the Linux kernel file(s) (vmlinu*) in /boot ?
3. Create a directory ~/test. Then issue the following commands:
cd ~/test
dd if=/dev/zero of=zeroes.txt count=1 bs=100
od zeroes.txt
dd will copy one times (count=1) a block of size 100 bytes (bs=100) from the file /dev/zero
to ~/test/zeroes.txt. Can you describe the functionality of /dev/zero ?
4. Now issue the following command:
dd if=/dev/random of=random.txt count=1 bs=100 ; od random.txt
dd will copy one times (count=1) a block of size 100 bytes (bs=100) from the file /dev/
random to ~/test/random.txt. Can you describe the functionality of /dev/random ?
5. Issue the following two commands, and look at the first character of each output line.
ls -l /dev/sd* /dev/hd*
ls -l /dev/tty* /dev/input/mou*
The first ls will show block(b) devices, the second ls shows character(c) devices. Can you
tell the difference between block and character devices ?
61
Try it yourself
6. Use cat to display /etc/hosts and /etc/resolv.conf. What is your idea about the purpose
of these files ?
7. Are there any files in /etc/skel/ ? Check also for hidden files.
8. Display /proc/cpuinfo. On what architecture is your Linux running ?
9. Display /proc/interrupts. What is the size of this file ? Where is this file stored ?
10. Can you enter the /root directory ? Are there (hidden) files ?
11. Are ifconfig, fdisk, parted, shutdown and grub-install present in /sbin ? Why are these
binaries in /sbin and not in /bin ?
12. Is /var/log a file or a directory ? What about /var/spool ?
13. Open two command prompts (Ctrl-Shift-T in gnome-terminal) or terminals (Ctrl-Alt-F1,
Ctrl-Alt-F2, ...) and issue the who am i in both. Then try to echo a word from one terminal
to the other.
14. Read the man page of random and explain the difference between /dev/random and /
dev/urandom.
62