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
echo hello world ignore the space
echo "hello world" > filename.txt creates the file
echo "hello world 2" >> filename.txt append the file
echo -e "Hello \n World" new line \t table -e is used for escape character
find /etc > etcfiles.txt
find . -name "*.conf"
find . -type f -name "*.conf" type -f is file type -d is directory
find tty?1 /dev
grep <string> <filename> The grep filter line of text or output
grep -v ignore the lines containing
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
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: cat > count.txt
One
Two
Three
Four
Use cat to make a backup of this file to count.txt
create history of all the command in a text file.
In /dev derectory find all the file ends with 2
Sort the file count.txt in reverse order
display line containing "e" in the file count.txt using grep
create a file using echo as below
This is a sunny day
We are enjoying linux
I am the best
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