2. What is command?
A command is an instruction given to our computer by us to do whatever
we want.
In Mac OS, and Linux it is called terminal, whereas, in windows it is
called command prompt. Commands are always case sensitive.
Commands are executed by typing in at the command line followed by
pressing enter key.
This command further passes to the shell which reads the command and
execute it. Shell is a method for the user to interact with the system.
Default shell in Linux is called bash (Bourne-Again Shell).
There are two types of shell commands:
Built-in shell commands: They are part of a shell. Each shell has some
built in commands.
External/Linux commands: Each external command is a separate
executable program written in C or other programming languages.
3. Command Navigation
Here is a list of commonly used keyboard shortcuts using the
default shell, bash :
4.
5.
6. Linux mkdir Command
The mkdir stands for 'make directory‘
Syntax:
mkdir <dirname1>
To make multiple directories
Syntax:
mkdir <dirname1> <dirname2> <dirname3> ...
8. Linux rmdir Command
Command : rmdir <director name>
This command is used to delete a directory. But will not be able to
delete a directory including a sub-directory. It means, a directory
has to be empty to be deleted.
Command : rmdir –p
This command will delete a directory including its sub-directories
all at once. In below picture, all sub-directories have been deleted
with 'rmdir -p' command.
9.
10.
11. Types of Files
Regular files (-): It contain programs, executable
files and text files.
Directory files (d): It is shown in blue color. It
contain list of files.
Special files
• Block file (b)
• Character device file (c)
• Named pipe file (p)
• Symbolic link file (l)
• Socket file (s)
14. Linux touch Command
• touch command is a way to create empty files (there are some other
methods also).
• You can update the modification and access time of each file with the
help of touch command.
Syntax:
touch <filename>
touch myfile1 myfile2 // To create multiple files in one command
15. Linux touch Command
• To see the access and change time of your file, you need to
use stat command.
Now after using touch -r demo.txt Demo.txt command,
time of Demo.txt has been changed wit reference to time of demo.txt
18. Man Command
The "man" is a short term for manual page. In Unix like
operating systems such as Linux, man is an interface to
view the system's reference manual.
A user can request to display a man page by simply
typing man followed by a space and then argument. Here
its argument can be a command, utility or function. A
manual page associated with each of these arguments is
displayed.
If you will provide a section number in the command,
then man will be directed to look into that section number
of the manual and that section page will be displayed.
And if not, then by default it will display the first page
and you have to go through the entire sections in a pre-
defined manner.
19. Man Command
Command : man –ls
This command will display all the information
about 'ls' command as shown in the screen shot.
20. Sections in the man Page:
Executable programs and shell commands
System calls
Library calls
Special files
File formats and conventions
Games
Miscellaneous
System administration commands
Kernel routines
Syntax for a particular section:
man section_number keyword
For example : man 2 passwd
21.
22. Command Man –a
This command help us to show all the man page sections
of a particular topic.
Sections will come in ascending order that is lowest
section number will come first.
To go to the next section press 'q' and then enter.
In the next slide, we have given the command 'man -a
chmod'. We know that chmod has two sections (1) and
(2).
24. Linux man -f (whatis)
This command works like 'whatis' command which we'll study in later
sections. It searches for the manual page name for a given command and
displays the result with a short description about the particular manual
page.
25. Linux man -k
This command works like 'whatis' command which we'll study in later
sections. It searches for the manual page name for a given command
and displays the result with a short description about the particular
manual page.
$ man –k chmod
27. Linux head command
The 'head' command displays the starting content of a file. By
default, it displays starting 10 lines of any file.
For example : head jtp.txt
If we'll write two file names then it will display first ten lines (in
this case file has five lines only) of each file separated by a heading.
For example : head doc1.txt doc2.txt
The 'head -n' option displays specified number of lines.
For example : head -15 jtp.txt
The 'head -c' command counts the number of bytes of a file.
For example : head -c 20 jtp.txt
28. Linux Tail command
The 'tail' command displays the last lines of a file. Its
main purpose is to read the error message. By default, it
will also display the last ten lines of a file.
For example : tail jtp.txt
The ‘tail -n' option displays specified number of lines.
For example : tail -n<number> <file name>
The 'tail -c' option displays the specified number of bytes
from the last.
Syntax: tail -c<number> <file name>
Example: tail -c12 jtp.txt
29. Linux cat command
Linux cat command (to create a file)
The 'cat' command can be used to create a new file with
greater than sign (>).
Command : cat >filename
Press 'enter' after every line and you will be directed to
the next line. To save your file, go to the next line,
press 'ctrl+d' and your file will be saved.
The 'cat' command with double greater than
sign (>>) append (add something in the last of a file)
something in your already existing file.
Syntax: cat >> file name
Example: cat >> filename
30. Linux cat command
The 'cat' command can be used to copy the content of a
file into another file.
Syntax: cat (older file name)>(newer file name)
Example: cat combo>combo2
The 'cat' command can be used to concatenate the
contents of multiple files in a single new file.
Syntax:
cat <filename1> <filename2>.... > <newFilename>
Example:
cat file1 file2 file3 >combo
31. Linux cat command
To Insert A New Line
A new line will be inserted while concatenating multiple files by
using a hyphen (-).
syntax:
cat - <filename1> <filename2>. . . . > <new filename>
Example:
cat - file1 file2 file3 >combo
The 'cat -n' option displays line numbers in front of each line in
a file.
The 'cat -n' option displays line numbers in front of each line in a
file.
Syntax: cat -n <fileName>
Example: cat -n jtp.txt
32. Linux cat command
The 'cat -b' option removes the empty lines.
Syntax: cat -b (file name)
Example: cat -b meenu.txt
The 'cat -n' option displays line numbers in front of each line in
a file.
Syntax: cat -n <fileName>
Example: cat -n meenu.txt
The 'cat-e' option displays a '$' sign at the end of every line.
Syntax: cat -e <fileName>
Example: cat -e prog.txt
33. Linux cat command
The 'cat -b' option removes the empty lines.
Syntax: cat -b (file name)
Example: cat -b meenu.txt
The 'cat << EOF ' option displays an end marker at the end of a
file. It is called here directive and file content will be saved at the
given end marker.
The file can be saved with the help of 'ctrl + d ' keys also. It works
like the end marker.
Note: Any word other than 'EOF' can be used for the end marker.
Syntax: cat << EOF
Example: cat > exm.txt << EOF
34. Linux tac command
The 'tac' command is the reverse of the 'cat' command. It is also
known as 'cat' backward. It will display the file content in reverse
order. It prints the last line first, then second last and so on. Such way,
it prints the first line at last.
Syntax: tac <file name>
Example: tac count
To Separate The Content
The 'tac --separator' command will separate the content from the
mentioned string or keyword from the rest of the file content.
Syntax: tac <file name> --separator "<string>"
Example: tac count --separator "two"
tac count --separator "five"
tac count --separator "one"
35. Linux More command
As 'cat' command displays the file content. Same way 'more'
command also displays the content of a file.
Only difference is that, in case of larger files, 'cat' command output
will scroll off your screen while 'more' command displays output one
screen ful at a time.
Following keys are used in 'more' command to scroll the page:
Enter key: To scroll down page line by line.
Space bar: To go to next page.
b key: To go to the backward page.
/ key: Lets you search the string.
Syntax: more <file name>
Example: more /var/log/udev
36. Linux More command
Note: The 'more' command can't be used to display binary files.
37. Linux Filesystem Hierarchy Standard
(FHS) The Root Directory
Ubuntu with the help of the command "ls /". Here, we have written (/) to represent root
directory.
Enter the command man hier. It will display directory structure of your system.
38.
39.
40. Linux Binary Directory
Binary files are the files which contain compiled source code (or
machine code). They are also called executable files because they can
be executed on the computer.
Binary directory contains following directories:
/bin
/sbin
/lib
/opt
/bin
41. Linux Binary Directory
The '/bin' directory contains user binaries, executable files, Linux
commands that are used in single user mode, and common commands
that are used by all the users, like cat, cp, cd, ls, etc.
The '/bin' directory doesn't contain directories.
Example: ls /bin
42. Linux Binary Directory
The '/sbin' directory also contains executable files, but unlike '/bin' it
only contains system binaries which require root privilege to perform
certain tasks and are helpful for system maintenance purpose. e.g.
fsck, root, init, ifconfig, etc.
Example: ls /sbin
43. Linux Binary Directory
The '/lib' directory contains shared libraries which are often used by the
'/bin' and '/sbin' directories. It also contains kernel module. These filenames
are identiable as ld* or lib*.so.*.
Example: ls /lib
/lib/modules: The '/lib/modules' stores kernel modules and has a directory
for each installed kernel. Modules are meant to use extra hardware support
without making a new kernel.
/lib32 and /lib64: During compilation time of libraries you'll encounter
through the directories named '/lib32' and '/lib64' which will clarify register
size to be used. A 64-bit system may have compatibility for 32-bit binary.
44. Linux Configuration Directory
The configuration directory contains configured files which
configures the parameters and initial settings for some computer
programs.
Configuration directory have following sub-directories:
1. /boot
The '/boot' directory contains boot loader files which are essential to
boot the system. In other words, they only contain files which are
needed for a basic Linux system to get up and going.
You may find '/boot/grub' directory which contains
'/boot/grub/grub.cfg' (older system may have /boot/grub/grub.conf)
which defines boot menu that is displayed before the kernel starts.
Example: ls /boot
46. Linux Configuration Directory
Configuration directory have following sub-directories:
2. /etc
All the machine related configuration files are kept in '/etc'. Almost
everything related to the configuration of your system is placed here.
It also contain startup and shutdown shell script which is used to start
and stop a program. All the files are static and text based and no
binary files can be placed in this directory.
The meaning of 'etc' is very controversial. Earlier it was referred to
as 'Etcetera' because it could contain all the files that did not belong
from anywhere else. But recently its most likely meaning is 'Editable
Text Configuration' or 'Extended Tool chest'.
Configuration files will have an extension of .conf.
47. Linux Configuration Directory
Configuration directory have following sub-directories:
2. /etc
Some common directories of /etc are:
/etc/init.d/: The term 'init' is short for initialization. This directory contains script to control the system
or to start and stop the daemons (background process). The 'init' is a daemon process that continues
running until the system is shut down.
/etc/X11/: The X Window system configuration files are stored in this directory. The configuration file of
graphical display (xorg.conf) is also stored here.
/etc/skel/: The term 'skel' is short for skeleton. Everything in the system has a skeleton which is called
hidden file and is stored in this directory. It is not an important part in the system and can be deleted but
still it serves a specific purpose. Its purpose is to serve the basic set of files, a basic framework which can
be used in the creation of a new user.
48. Linux Data Directory
Data directory is used to store data of the system.
Data directory contains following directories.
/home
/root
/srv
/media
/mnt
/tmp
49. Linux Data Directory
The '/home' directory stores users personnel files. After the '/home' there is a
directory which is generally named at the user's name like we have '/home/meenu'.
Inside this directory we have our sub-directories like Desktop, Downloads,
Documents, pictures, etc.
Example: ls /home
ls /home/meenu
The '/root' directory is the home directory of the root user.
Please note that '/root' directory is different from (/) root.
The term 'srv' is short for service. The '/srv' directory contains server specific data
for services provided by the system like www, cvs, rysync, ftp, etc.
The '/media' directory acts as a mount point for removable media devices such as
CD-Rom, floppy, USB devices, etc.
This is newly introduced directory and hence a system can run without this directory
also.
Example: ls /media
50. Linux Data Directory
The term 'mnt' stands for mount. The '/mnt' directory should be empty
and sysadmins can only mount temporary filesystems.
The term 'tmp' stands for temporary. Data stored in '/tmp' is
temporary and may use either disk space or RAM. When system is
rebooted, files under this directory is automatically deleted. So it is
advisable that never use '/tmp' to store important data.
51. Linux Memory Directory Memory directory contains files of the whole system. All the device information,
process running indata or system related information are stored in this directory.
Memory directory contains the following directories.
/dev
/proc
/sys
/dev
The term 'dev' is short for device. As you know in Linux operating system
everything is a file. It appears to be an ordinary file but doesn't take up disk space.
Files which are used to represent and access devices are stored here including
terminal devices like usb. All the files stored in '/dev' are not related to real devices,
some are related to virtual devices also.
/dev/tty and /dev/pts: The '/dev/tty' file represents the command line interface that
is a terminl or console attached to the system. Typing commands in a terminal is a
part of the graphical interface like Gnome or KDE, then terminal will be represented
as '/dev/pts/1' (here 1 is replacable by any another number).
/dev/null: The '/dev/null' file is considered as black hole, it has unlimited storage but
nothing can be retrieved from it. You can discard your unwanted output from the
terminal but can't retrieve it back.
52. Linux Memory Directory
/proc
The term 'proc' is short for process. Same as '/dev', '/proc' also doesn't take up disk
space. It contains process information. It is a pseudo file system that contains
information about running processes. It also works as virtual file system containing
text information about system resources.
/proc conversation with the kernel: The '/proc' displays view of the kernel, what
the kernel manages and it is a means to directly communicate with the kernel.
Also most of the files in '/proc' are of 0 bytes yet they contain a lot of data. Most
of the files are readable only, some require root privileges and some are
writable.
/proc/interrupts: The '/proc/interrupts' displays the interrupt.
Example: cat /proc/interrupts
/sys
The term 'sys' is short for system. Basically it contains kernel information about
hardware. It was created for Linux 2.6 kernel. It is a kind of '/proc' and is used for
plug and play configuration.
53. Linux Memory Directory
Look at the below snapshot, command "ls /proc" displays content of '/proc'. Many
files are named as numbers and some named files are also there.
The '/proc' has some file properties like date, which keeps on updating as shown in
the below snapshot.