LinuxTextFiles

Editors

To edit files use the following editors

Viewers

more

To read file use more command

more textfile

and press space to scroll it down. To quit more press q

less

To read file use less command

less textfile

less is more advanced and has many commands

CommandDescription
/abcsearch and highlight abc text (use n to go to next occurrences
ggoes to the top of the file
Ggoes to the bottom of the file
qquit

head

To see first 10 lines o text file use

head textfile

To see first *num* lines use

head -n *num* textfile

tail

To see last 10 lines o text file use

tail textfile

To see last *num* lines use

tail -n *num* textfile

To update automaticaly on file change use fresher option

tail -f /var/log/messages

to quit fresher mode use Ctrl+c

cat

To see hidden characters use cat command

cat textfile

options:

  • -A shows all non-printable characters
  • -b numbers line with text but skip empty lines
  • -n shows numbers of lines
  • -s suppresses repeated empty lines

Text utilities

cut

Filter output from the text file

cut -d : -f 1 /etc/passwd

sort

sort files (often uses in pipes

cut -d : -f 1 /etc/passwd | sort

tr

translate upper case to lower case

echo hello | tr [:lower:] [:upper:]

sed

powerful text editing tool

to print line #5 from text file

sed -n 5p /etc/passwd

to delete line #2 from text file myfile

sed -i -e '2d' myfile

replace 'how' to 'HOW' in text file myfile

sed -i s/how/HOW/g myfile

awk

search for specific patterns

to print 4th column from text file

awk -F : '{ print $4 }' /etc/passwd

to print 4th column for line contains amy from text file

awk -F : '/av631/ { print $4 }' /etc/passwd
Page last modified on July 30, 2021, at 03:31 PM
Powered by PmWiki