RHCSA: How to manipulate files in RedHat

Here is part 2 of the RHCSA learning sessions. This will focus on some of the core components to manipulate files.

You will learn how to:

Find Files

  • Find files
  • Read files
  • Manipulate test
  • Link files

Finding files is a key skill needed for any system admin.

There are a number of operator flags which are useful for the find command.

type

• f = regular file

find . -type f –name httpd.conf

• d = directory

find . –type d –name html

• l = symbolic link

find . –type l –name redhat-release

user

• File is owned by user (username or UID)

Find top 5 files

find -type f -exec du -Sh {} + | sort -rh | head -n 5

Reading Files

cat

This reads the file and outputsall of it to stdout.

less and more

Also known as “pagers” these commands will output the contents of a file to the screen, but allow you to navigate through the file as well

head and tail

These commands let you look at the lines starting at the top or bottom of the file, respectively.

Text Manipulation

sort

wc

This can be used to sort input in many ways, alphabetically numerically, or with different fields as the sort key. Sorting is also available in reverse.

Short for “word count,” this utility can count the number of lines, words, characters, bytes, and the length of the longest line in the file.

diff

Usually used to generate patch files, diff can display the differences between two or more files.

Linking Files

File name is pointer to inode

There are 2 types – 

  • hard link –  This is link between files that point to the same inode
  • soft link – is a pointer, acts like a redirect

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *

Follow by Email
YouTube
YouTube
Instagram