Find Files in Linux (Red Hat)

It doesn’t matter if you have worked on Linux your entire life or if you are a complete noob. Being able to find and manage files in Linux is a skill you will use every day.

In this article, You will learn how to:

Find Files

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

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

Several operator flags are useful for the find command.

type

• f = regular file

Bash
find . -type f –name httpd.conf

• d = directory

Bash
find . –type d –name html

• l = symbolic link

Bash
find . –type l –name redhat-release

user

• File is owned by the user (username or UID)

Find the top 5 files.

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

Reading Files

cat

This reads the file and outputs all of it to stdout.

The cat command in Linux is a versatile tool for working with text files. Here are some useful examples:

Displaying File Contents:

Bash
cat filename

This command will display the entire content of the specified file on the terminal.

Concatenating Multiple Files:

Bash
cat file1 file2 > newfile

This concatenates the content of file1 and file2 and writes the result to newfile.

Appending to a File:

Bash
cat file1 >> existingfile

Appends the content of file1 to the end of existingfile.

Numbering Lines:

Bash
cat -n filename

Displays the content of the file with line numbers.

Displaying Line Contents Matching a Pattern:

Bash
cat filename | grep "pattern"

Displays lines containing the specified pattern using the grep command.

Displaying Non-Printable Characters:

Bash
cat -v filename

Displays non-printable characters as visible representations.

Creating a New File with Content from the Terminal:

Bash
cat > newfile

Allows you to type content directly into the terminal, and when you press Ctrl+D, it saves the input to newfile.

Viewing Multiple Files with Page Breaks:

Bash
cat file1 file2 | more

Displays the content of file1 and file2 with a page break, allowing you to navigate through the content.

Displaying Tabs as ^I:

Bash
cat -T filename

Shows tabs in the file as ^I.

Displaying Line Endings:

Bash
cat -E filename

Displays lines with a $ symbol at the end, indicating the line endings.

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”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 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

The file name is a pointer to the inode

There are two types – 

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

Part 1 – How to use Grep and Regular Expressions (RegEx)

Part 2 – How to manipulate files in RedHat

Part 3 – Red Hat Permissions

Part 4 – How to change the root password on Red Hat

Part 5 – How to use Red Hat as a virtual machine host

Part 6 – How to configure local storage

Part 7 – how to manage users and groups in Red Hat Linux

Part 8 – how to configure NTP Network Time Protocol in Red Hat

Elsewhere On TurboGeek:  Restarting WebSphere (WAS) after a reboot

Richard.Bailey

Richard Bailey, a seasoned tech enthusiast, combines a passion for innovation with a knack for simplifying complex concepts. With over a decade in the industry, he's pioneered transformative solutions, blending creativity with technical prowess. An avid writer, Richard's articles resonate with readers, offering insightful perspectives that bridge the gap between technology and everyday life. His commitment to excellence and tireless pursuit of knowledge continues to inspire and shape the tech landscape.

You may also like...

7 Responses

  1. 01/09/2022

    […] Part 2 – How to manipulate files in RedHat […]

  2. 19/10/2022

    […] Part 2 – How to manipulate files in RedHat […]

  3. 19/10/2022

    […] Part 2 – How to manipulate files in RedHat […]

  4. 20/10/2022

    […] Part 2 – How to manipulate files in RedHat […]

  5. 24/03/2023

    […] Part 2 – How to manipulate files in RedHat […]

  6. 23/07/2023

    […] Part 2 – How to manipulate files in RedHat […]

  7. 16/10/2023

    […] Part 2 – How to manipulate files in RedHat […]

Leave a Reply

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

Translate »