The document discusses various features and commands related to Linux operating systems. It describes features like being free and open-source, graphical user interfaces, and portability. It also provides examples and explanations of basic Linux commands like echo, head, tail, sort, uniq, and others. Fun commands like sl, fortune, cowsay and cmatrix are also mentioned.
1. Dr. D. P.
Mishra
Digitally signed by Dr. D. P.
Mishra
DN: cn=Dr. D. P. Mishra, o=durg,
ou=BIT,
email=dpmishra@bitdurg.ac.in,
c=IN
Date: 2023.02.14 12:44:22
+05'30'
3. Features of Linux Operating Systems?
⢠Free and Open-Source. ...
⢠Extremely Flexible. ...
⢠Lightweight Infrastructure. ...
⢠Graphical User Interface (GUI) ...
⢠End-to-end encryption. ...
⢠Portable Environment. ...
⢠Shell/ Command-line Interface. ...
⢠Customized keyboard.
⢠Multiuser, multitasking, portability, security âŚ
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
4. Is shell A Programming Language?
⢠A Unix shell is both a command interpreter and a programming
language.
⢠As a command interpreter, the shell provides the user interface to the
rich set of GNU utilities
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
5. Basic Commands.
⢠$ echo command :
⢠Echo is a Unix/Linux command tool used for displaying lines of text or string
which are passed as arguments on the command line.
⢠This is one of the basic command in Linux and most commonly used in shell
scripts.
⢠$ echo [option] [string]
⢠$ echo Hello, World!
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
6. Basic Commands..
⢠who
⢠date
⢠pwd
⢠cd
⢠mkdir
⢠rmdir
⢠ls
⢠cp
⢠mv
⢠rm
⢠cat
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
7. Date , Time & Calendar
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
8. Basic CommandsâŚ
⢠more command is used to view the text files in the command prompt,
displaying one screen at a time in case the file is large (For example log
files).
⢠The more command also allows the user do scroll up and down
through the page.
⢠$ more -d sample.txt
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
10. wc command
⢠wc command gives us useful information about a file by returning no.
of lines, words and bytes
⢠The first column returned is the number of lines.
⢠The second is the number of words.
⢠The third is the number of bytes.
⢠$ echo test >> test.txt
⢠$ wc test.txt
1 1 5 test.txt
⢠Example via pipes, we can count the output of running the ls âal
command:
⢠$ ls âal |wc
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
11. find command
⢠The $ find command can be used to find files or folders matching a
particular search pattern.
⢠It searches recursively
⢠Example : Find all the files under the current tree that have the .txt
extension and print the relative path of each file matching:
$ find -name '*.txtâ
⢠It's important to use quotes around special characters like * to avoid
the shell interpreting them.
⢠Find directories under the current tree matching the name "src"
$ find . -type d -name src
⢠You can search under multiple root trees:
$ find folder1 folder2 -name filename.txt
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
12. $ head command
⢠The head command writes to standard output a specified number of
lines or bytes of each of the specified files, or of the standard input.
⢠If no flag is specified with the head command, the first 10 lines are
displayed by default
⢠The File parameter specifies the names of the input files.
⢠Example :
$ nano example1.txt
⢠Add following lines in file
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
14. $ cat example1.txt
$ head example1.txt
⢠For displaying number of lines â
$ head -n 4 example1.txt
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
15. ⢠For displaying no. of bytes : use the -c (--bytes) argument
⢠To see 20 bytes of output of the sample file, you would run
$ head -c 20 example1.txt
⢠For displaying filename tag : To display the file name before
outputting the first 10 lines, add the -v (--verbose) option:
$ head -v example1.txt
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
16. Displaying Multiple Files with head
⢠You can also display the first lines of multiple files using a single
command:
$ head [option] file_name1 file_name2
$ head example1.txt example2.txt
$ head -n 4 example1.txt example2.txt
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
17. Redirecting output to a text file
⢠You can redirect the output from the head command to a text file (or
log file) using the greater-than sign (>).
⢠Instead of displaying the lines in standard output, they are placed into
the wanted file.
⢠Syntax for redirecting output from head command is :
$ head [options] file_name > output_file
⢠To redirect the first 10 lines of example1.txt to a file
named output1.txt, you would run the command:
$ head example1.txt > output1.txt
$ cat output1.txt
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
18. Using head with Pipeline
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
⢠head can be piped to one or more commands to modify the output:
⢠Syntax:
[command] | head [option]
⢠For example, to list files in the /etc directory using the ls command and
print 10 entries, you would run the command:
$ ls /etc | head
19. $ tail
⢠tail command prints the last few number of lines (10 lines by default)
of a certain file, then terminates.
⢠By default âtailâ prints the last 10 lines of a file, then exits.
⢠This is great for watching log files, for example:
tail -f /var/log/system.log
$ ctrl-C
$ tail -n 10 <filename>
⢠You can print the whole file content starting from a specific line using +
before the line number:
tail -n +10 <filename>
⢠$ tail can do much more and as always my advice is to check man tail
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
20. $ sort command
⢠SORT command is used to sort a file, arranging the records in a
particular order.
⢠By default, the sort command sorts file assuming the contents are
ASCII.
⢠Using options in the sort command can also be used to sort
numerically.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
21. ⢠$ cat > file.txt
abhishek
chitransh
satish
rajan
naveen
divyam
harsh
⢠$ sort file.txt
⢠Output :
abhishek
chitransh
divyam
harsh
naveen
rajan
Satish
Note: This command does not
actually change the input file
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Create a data file
22. $ nl command
⢠The nl command reads the
File parameter (standard
input by default), numbers
the lines in the input, and
writes the numbered lines to
standard output.
⢠nl command is a Unix/Linux
utility that is used for
numbering lines, accepting
input either from a file or
from STDIN.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
23. ⢠$ cat list.txt
apples
oranges
potatoes
lemons
garlic
⢠$ nl list.txt
1 apples
2 oranges
3 potatoes
4 lemons
5 garlic
⢠$ nl list.txt > nlist.txt
⢠$ cat nlist.txt
1 apples
2 oranges
3 potatoes
4 lemons
5 garlic
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Example of nl command
In the example above, we run the same nl command, but
redirect the output to a new file, nlist.txt. Then we use cat to
display the results.
24. $ uniq command
⢠Linux uniq command is used to remove all the repeated lines from a
file.
⢠Also, it can be used to display a count of any word, only repeated lines,
ignore characters, and compare specific fields
⢠Syntax :
$ uniq [OPTION]... [INPUT [OUTPUT]]
⢠Some useful command line options of the uniq command are as following:
⢠-c, --count: it prefixes the lines by the number of occurrences.
⢠-d, --repeated: it is used to print duplicate lines, one for each group.
⢠-D: It is used to print all the duplicate lines.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
25. ⢠Remove repeated lines
$ sort filename.txt | uniq
⢠Counting occurences of word
⢠$ sort filename.txt | uniq âc
⢠Displaying repeated lines -d
⢠$ sort filename.txt | uniq âd
⢠Display unique lines - u option
$ sort filename.txt | uniq âu
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg
Examples of uniq command
34. 8. cmatrix
⢠You might have seen the Hollywood movie âmatrixâ & fascinated with.
⢠For displaying an animation that looks like Hackerâs desktop.
Linux
Laboratory
-
B.Tech.
6th
CSE
-
Dr.
D.
P.
Mishra,
BIT
Durg