Unit I Chapter 2
Unit I Chapter 2
Unit I Chapter 2
Chapter-2
Command Line
Working with the Bash Shell
Working with the Bash Shell
Bash: stands for Bourne Again Shell and it is the default shell
on many Linux distributions.
The Bash shell is a combination of features from the Bourne
Shell and the C Shell.it is the interface that enables the user to
issue command to the kernel and thus act as a mediator between
the kernel and user.
A partial list of other shells follows:
ator
Tcsh(Tenex C shell): A shell with a scripting language that
works like the C programming language. It is very popular with
C programmers.
zsh : A shell that is compatible with Bash but offers even more
features.
Ctrl+D: This key sequence is used to send the end-of-file (EOF) signal
to a command.
Ctrl+B : The Ctrl+B keystroke moves the cursor to the end of the
current command line.
Working with Bash History
• The Bash shell is the history feature. The history mechanism
helps you remember the last commands you used.
cd- You can change your current directory (working directory) with
the cd command.
root@hnl etc] # cd /etc
root@hnl etc] # pwd
/etc
root@hnl etc] # cd /bin
root@hnl etc /bin] # pwd
/bin
mkdir - mkdir command is used to create a new dir. You have to give at
least one parameter to mkdir, the name of the new directory to be created.
# rmdir example
Working with the Red Hat Linux File
System
The Red Hat Linux file system is the structure in which all the information
on your computer is stored. Files are organized within a hierarchy of
directories. Each directory can contain files, as well as other directories.
At the top is the root directory, which is represented by a single slash (/).
/bin — Contains common Linux user commands, such as ls, sort, date,
and chmod.
/boot — Has the bootable Linux kernel and boot loader configuration files
(GRUB).
ls with no options
ls -l
The -l option signifies the long list format. This shows a lot more
information presented to the user than the standard command.
You will see the file permissions, the number of links, owner name,
owner group, file size, time of last modification, and the file or
directory name. This option is used in conjunction with many other
options on a regular basis.
Wildcards can be used when working with the ls
command.
$ rm today.txt
The -i makes rm interactive. Answer with a y and the file goes away.
Answer with an n and you keep the file. To be safe, you can always use
the -i switch with rm. There's no harm or shame in it and you'll be glad
you did at some point in the future.
COPYING FILES WITH CP
Copying files and directories is a very common task for Linux system
administrators.
The copy (cp) command, the file or directory source, and the
destination. To copy a file, file.txt, to the /opt/files directory, use:
$ cp file.txt /opt/files
$ cp -R data /opt/files
The cp command is rare in that both the upper- and the lowercase
options for an action are the same. Of course, you can use wildcards
when copying files to filter them with patterns:
$ cp *.txt /opt/files
MOVING FILES WITH MV
https://www.youtube.com/watch?v=Mz6pJ7TnFUc
https://www.youtube.com/watch?v=KoyAZonYSEI
1. head Command
The head command reads the first ten lines of a any given
file name. The basic syntax of head command is:
head [options] [file(s)]
For example, the following command will display the first ten
lines of the file named ‘/etc/passwd‘.
If more than one file is given, head will show the first ten lines
of each file separately. For example, the following command
will show ten lines of each file.
For example, the following command will print the last ten lines
of a file called ‘access.log‘.
cat Command
The ‘cat‘ command is most widely used, universal tool. It
copies standard input to standard output. The command
supports scrolling, if text file doesn’t fit the current screen.
The basic syntax of cat command is:
The most frequent use of cat is to read the contents of files. All
that is required to open a file for reading is to type cat followed by
a space and the file name.
The cat command also used to concatenate number of files
together.
It can be also used to create files as well. It is achieved by
executing cat followed by the output redirection operator
and the file name to be created.
2. Place the cursor to the line you want to begin copping or cutting.
4. Move the cursor to the end of the text you want to copy or cut. You can use a movement
command or up, down, right, and left arrow keys.
6. Press y to copy, or d to cut the selection.
7. Move the cursor to the location where you want to paste the contents.
8. Press P to paste the contents before the cursor, or p to paste it after the cursor.
Deleting Text
Another action you will often do when working with vi is deleting text.
There are many methods that can be used to delete text with vi. The
easiest is from insert mode: just use the Delete and Backspace keys
to get rid of any text you like. This works just like a word processor.