Commands:

head display the first ten lines of a file.

head -n display first n number of lines.

tail display the last ten lines of a file

tail -n display last n number of lines.

echo "Hello World" keeps the space and tab

  1. echo hello world ignore the space

  2. echo "hello world" > filename.txt creates the file

  3. echo "hello world 2" >> filename.txt append the file

  4. echo -e "Hello \n World" new line \t table -e is used for escape character

find /etc > etcfiles.txt

  1. find . -name "*.conf"

  2. find . -type f -name "*.conf" type -f is file type -d is directory

  3. find tty?1 /dev

grep <string> <filename> The grep filter line of text or output

  1. grep -v ignore the lines containing

  2. grep -i case in-sensitive

diff <filename1> <filename2>

diff -u , diff -c

sort -f <filename>

sort -o <newfile> <oldfile> copy the shorted output to new file

sort -r <filename> sort the file in reverse.

Sed: This is used to perform basic text transformations on an input file. It stands for "stream editor" and is a powerful tool for editing text files or streams in a Linux environment.



Practice

  1. Display the first 12 lines of /etc/services.

  2. Display the last line of /etc/passwd

  3. Use cat to create a file named count.txt that looks like this: cat > count.txt

One

Two

Three

Four

  1. Use cat to make a backup of this file to count.txt

  2. create history of all the command in a text file.

  3. In /dev derectory find all the file ends with 2

  4. Sort the file count.txt in reverse order

  5. display line containing "e" in the file count.txt using grep

  6. create a file using echo as below

This is a sunny day

We are enjoying linux

I am the best

  1. Create 2 files and find the difference.

Answers by: Sudharshan Palabindela

head -12 /etc/services

tail /etc/passwd

cat > count.txt

cat count.txt > backupcount.txt

ll

history > history_for_print.txt

cd /dev

find *2

sort -r count.txt

grep e count.txt

echo -e "This is a sunny day \nWe are enjoying linux \nI am the best" > file.txt