Tuesday, April 5, 2022

Linux File related commands

 Split command

When files are too long and you want to split into multiple files then use split command

Spliting a file into multiple files and each file should have max 25 lines

ls -l /etc >myfile.txt

split -l 25 myfile.txt

wc command

To find the number of lines/words/Characters then we use wc command

cat xaa | wc

cat xaa | wc -l

cat xaa | wc -w

cat xaa | wc -c

sort command

To arrange the values in ascending or descending order

cat > numbers

2

3

4

1

8

7

9

5

Arrange numbers in ascending order

sort numbers

Arrange numbers in descending order

sort -r numbers

Arrange the number field in asc/desc order

du  /var/log > diskspace

sort -n -r diskspace

cmp 

cmp command is used to comparing 2 files

cmp file1 file2



0 comments:

Post a Comment