Linux Linux Basics by Editorial Staff February 24, 2023 written by Editorial Staff February 24, 2023 Commands: wc : to count the number of lines words and characters [root@localhost redhat]# wc myfile 3 2 13 myfile wc –l : to count numbers of lines only [root@localhost redhat]# wc -l myfile 3 myfile wc –w : to count the number of words only [root@localhost redhat]# wc -w myfile 2 myfile wc –c : to count the number of characters only [root@localhost redhat]# wc -c myfile 13 myfile wc –lw : to count the number of lines and words only [root@localhost redhat]# wc -lw myfile 3 2 myfile wc –cl : to count the number of characters and lines only [root@localhost redhat]# wc -cl myfile 3 13 myfile wc –wc : to count the number of words and characters only [root@localhost redhat]# wc -wc myfile 2 13 myfile File Command It is used to determine the given file type How to find what type of file you have? [root@localhost redhat]# file dba dba: data [root@localhost redhat]# file myfile myfile: ASCII text What is the paste command? it is used to join two or more files horizontally by using delimiters. Syntax: paste <file1> <file2> [root@localhost redhat]# paste states capitals ap am ts hyd ka ban ma what is the –d “:” command? If you want to join any two or more files horizontally with any specific delimiter If you want to join any two or more files horizontally with any specific delimiter [root@localhost redhat]# paste -d ":" states capitals ap:am ts:hyd ka:ban ma: How to save files in redirection files? [root@localhost redhat]# paste -d ":" states capitals >temp [root@localhost redhat]# What is the cut command? It retrieves specific files and characters I want to create an emp file [root@localhost redhat]# cat>emp eno ename esal edesg 101 raju 40k mg 102 ramu 3ok eng 103 ramesh 50k sm Now retrieve the file [root@localhost redhat]# cut -f 1,3 emp eno esal 101 40k 102 3ok 103 50k if you retrieve characters [root@localhost redhat]# cut -c 1,5 emp ee 1r 1r 1r What is the echo command? The echo responsible is to print a line of text [root@localhost redhat]# echo "this is ramesh" this is ramesh [root@localhost redhat]# How to find date in echo command? [root@localhost redhat]# echo "this is ramesh. today date is: `date`" this is ramesh. today date is: Tue Aug 10 21:16:00 IST 2021 [root@localhost redhat]# What is the tr command? It translates character by character in the given file How to translate a character? [root@localhost redhat]# cat>test this is my text file [root@localhost redhat]# tr "aeiou" "AEIOU" <test thIs Is my tExt fIlE [root@localhost redhat]# What is –s “ “ command? It is reduced to space between sentences [root@localhost redhat]# tr -s " " <test this is my text file [root@localhost redhat]# How to save the content in a file? [root@localhost redhat]# tr -s " " <test >>temp1 [root@localhost redhat]# What is the diff command? The diff command responsibility is to compare line by line in the files How to compare files to content? [root@localhost redhat]# diff file1 file2 1,3c1,3 < raju < ramu < rani --- > laxmi > seetha > latha [root@localhost redhat]# How to compare the file? [root@localhost redhat]# cmp file1 file2 file1 file2 differ: byte 1, line 1 [root@localhost redhat]# What is the head command? The head command responsible is to top 10 lines in the file [root@localhost redhat]# head demo hi.. to.. all.. good.. morning.. good... evening... all... see.. you... [root@localhost redhat]# How to save the head file 10 line into another file? [root@localhost redhat]# head -10 demo >>myfile [root@localhost redhat]# What is the tail command? The tail responsible is to list and last < and > ( last 10 ) lines [root@localhost redhat]# tail demo to.. all.. good.. mornig.. good... evening... all... see.. you... good.. [root@localhost redhat]# What is the ‘( ; )‘ semicolon command? The( ; ) semicolon is responsible to execute commands in a single line [root@localhost redhat]# date; pwd; logname Tue Aug 10 22:42:25 IST 2021 /home/redhat redhat [root@localhost redhat]# What is the sort command? the sort command is to sort the content. If you want to arrange the content it will help (ascending and descending order). [root@localhost redhat]# cat>sample unix linux java dba oracle [root@localhost redhat]# How to sort ascending order? [root@localhost redhat]# sort sample dba java linux oracle unix [root@localhost redhat]# How to sort descending order? [root@localhost redhat]# sort -r sample unix oracle linux java dba [root@localhost redhat]# -r : to arrange to descending order What is –u command? The command is eliminated any repeated lines [root@localhost redhat]# sort -u sample dba java linux oracle unix [root@localhost redhat]# What is uniq command? It displays uniq lines of the files or reports the repeated lines in the file [root@localhost redhat]# cat>sample dba java linux linux java oracle msdba msdba [root@localhost redhat]# How to eliminate repeated lines? [root@localhost redhat]# uniq sample dba java linux java oracle msdba [root@localhost redhat]# How to see duplicated lines in a file? [root@localhost redhat]# uniq -d sample linux msdba [root@localhost redhat]# How to see non duplicated lines in a file? [root@localhost redhat]# uniq -u sample dba java java oracle [root@localhost redhat]# 0 comment 0 FacebookTwitterPinterestEmail Editorial Staff previous post Linux Basics next post Git Commands You may also like Linux Basics February 24, 2023 Linux Basics February 24, 2023 Linux Basics February 23, 2023 Linux Basics February 23, 2023 Linux December 19, 2022 Leave a Comment Cancel Reply Save my name, email, and website in this browser for the next time I comment.