Basic Linux Commands (Text Processing and Searching)

Known as an open-source operating system with a highly active community, Linux continues to thrive. Countless contributions from both the community and its founder have made Linux immensely popular. Linux commands are one of the key aspects that make it so fascinating to learn, as executing specific commands can make using Linux much more efficient. As discussed in our previous article on Basic Linux Commands (Managing Files and Directories), this time we will explore Linux commands used for text processing and searching for files or folders.

Learning Linux commands is akin to learning a new language. Each command helps us control the system more precisely and effectively. From managing files to monitoring the system, these commands are essential for interacting with Linux. In this article, we will cover the essential basic commands that every Linux user should know.


Linux Commands for Text Processing and Searching

1. The nano and vi Commands

Text editors widely known among Linux users include nano and vim (commonly referred to as vi). Using the nano or vim command is quite straightforward; you simply need to run the following command:

$ nano filename
$ vi filename

When using the commands above, if the file already exists in your current directory, it will automatically open, allowing you to modify it right away. However, if the file does not exist yet, a new file will be created automatically once you save your changes, without needing to run the touch command first.

2. The cat Command

:Short for “concatenate,” cat is a frequently used command in Linux. It can be used to create and write new files, view file contents, and combine multiple files together

$ cat > filename

To combine the contents of multiple files into a single file:

$ cat filename1 filename2 > filename3

To view the contents of a file:

$ cat filename

3. The grep Command

The grep command, which stands for Global Regular Expression Print, is used to search for a specific string or text within a file’s content. This command displays all the lines that contain the searched text, making it extremely useful when looking for specific information within large files, such as log files.

$ grep [search word] [filename]

4. The head Command

The head command is quite similar to cat, except that head only displays the first ten lines of a file.

$ head [options] [filename]

TerdapaThere are several options that can be added when running the head command, such as:

  • -n [row]: Useful for viewing only a specific number of lines from the beginning of a file. For example, head -n 3 filename will only display the first three lines of a file.

5. The tail Command

The tail command is the exact opposite of the head command; it is used to view the last ten lines of a file.

$ tail [options] [filename]

6. The diff Command

The diff command is used to compare and display the differences between the contents of files.

$ diff [options] filename1 filename2

7. The locate Command

The locate command is used to find the location of a file within the system database.

$ locate filename

8. The find Command

The find command is used to display the location of a file within a specific directory.

$ find [options] [pathdir] [expression]

Conclusion

That concludes our discussion on basic commands for text processing and searching for files or folders. By mastering these commands, you will indirectly enhance your skills and proficiency in using Linux.

Index