Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Last Updated: Mar 27, 2024
Difficulty: Easy

Linux - Tools

Leveraging ChatGPT - GenAI as a Microsoft Data Expert
Speaker
Prerita Agarwal
Data Specialist @
23 Jul, 2024 @ 01:30 PM

Introduction

In the 1990s, Finnish software engineer Linus Torvalds and the Free Software Foundation developed the Linux OS. It is an open-source operating system. It provides a list of tools to perform various tasks.
 

In this article, we will discuss the basic tools available in Linux to perform basic operations and locate files, set time and date, sleep mode etc.

Linux - Tools

Tools for Searching Files in Linux

Mainly two basic tools are used in Linux for finding a specific file inside a directory.

  1. Find Tool.
     
  2. Locate Tool.
     

The find tools and locate tools are used to search a file by filename. However, the difference between the two operations is that whereas the find tool checks the filesystem, locate searches the database as a background process. The find command generally takes longer than the locate command.

Linux Find Tool

It is used to search a list of files satisfying various conditions, such as

  • Filetype.
     
  • User ownership.
     
  • Size.
     
  • Date and time.
     
  • File name and many more.
     

The syntax of the Linux command for the Find tool:

find <file-location> <conditions> <search-keyword>

 

It is in the form of the following:

$ find [Where to begin your search]
[expression chooses what to find in the filesystem] [-options] [What to find]

 

Parameters

We can search a file by using different parameters.

Using File name

We may search over every file that ends in ".txt." To perform this, use the following syntax:

find . /CodingNinjas-name example .txt

 

Using File type

The file type can be specified using the '-type' keyword. To perform this, use the following syntax:

find . -type d -name .txt

 

It will display all files that end in ".txt."

The following are some of the file types:

  • f: normal file
     
  • d: directory
     
  • l: symbolic links
     
  • b: Blocking devices
     

Finding Directory

To find a directory, use the 'type -d' option. To perform this, use the following syntax:

find . type -depth -name Newdirectory

 

Newer Files

The '-newer' keyword facilitates the search for more recent files than the specified file. To perform this, use the following syntax:

find . -newer example.txt

 

Empty Files

Use the '- empty' keyword to find all the empty files and folders in the specified directory. We can use the following syntax:

find ./CodingNinjas -empty

 

Linux Locate Tool

The Locate tool searches the file in the database. You can use the "updatedb" command to update your database if you are unable to locate a file using the locate command because your database is out of date.

The Syntax for the locate tool: 

locate[OPTION]… PATTERN..

 

If any of the provided matches are discovered, this command will exit with status 0. It will terminate with status 1 if no match is discovered or if a fatal error occurs.

 

Options

Here are some useful command-line options:

🧩 -A, --all: This option displays only entries that match all PATTERNs rather than just the one that matches.

🧩 -b, –basename: It matches only the base name against the given patterns.

🧩 -c, –count: Only print the number of matching items on standard output; do not print file names.

🧩 -d, --database DBPATH: It is used to substitute DBPATH for the default database.

🧩 -e, --existing: When the command is used, it displays only entries that refer to existing files.

🧩 -h, -help: Successfully exit by printing a list of all available options to standard output.

🧩 -i, –ignore-case: When matching patterns, ignore case-related differences.

🧩 -L, --follow: When the '—existing' option is supplied, it is used to check for the existence of files and to track trailing symbolic links. The output will not contain the broken symbolic links.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

Linux Date Tool

Use the Linux date command to display the date, time zone, etc. The Linux system's date and time are also set using it. It is typically used to calculate dates over time and show the date in various formats.

The syntax of the date tool:

date [OPTION] [FORMAT]

Options

Some useful command line options are as follows:

🧩 -f, --file=DATEFILE:  It resembles the '—date' option in specific ways.

🧩 -R, --rfc-email: The RFC 5322 formatted date and time are shown on it. For example, Sun,30 October 2022, 02:34:56 -0600.

🧩 --rfc-3339=FMT: It displays the date and time in RFC 3339 format.

🧩 -r, --reference=FILE: This option displays the FILE's most recent modification time.

🧩 -s, --set=STRING: It's employed to set the time specified by STRING.

🧩 --help: It is utilised to show the instruction manual.

Format

Some useful command line formatting options are as follows:

🧩 %a and %A: %a serves to display the name of the weekday in shortened form (e.g., Mon) and %A is utilised to show the complete weekday name (e.g., Monday).

🧩 %b and %B: %b serves to display the month's name in shortened form (e.g., Jan) and %B is utilised to show the complete month name (e.g., January).

🧩 %c: The time and date are displayed using it (e.g., Sun Oct 30 23:05:25 2005).

🧩 %d and %D: %d indicates the day of the month (e.g., 01). The same as %m/%d/%y, %D represents the date.

🧩 %e: It is used to show the day of the month with a gap between the digits.

🧩 %F: Similar to %Y-%m-%d, %F is used to display the whole date.

Linux Time Tool

The Linux time command shows the execution time of a command. It assists in evaluating the efficiency of the commands and scripts. The syntax of the Time command is as follows:

time [OPTION] [Arguments]

 

Some of the command line options are as follows:

🧩 -a, —append: This option allows you to attach files so that data can be used rather than overwritten in the output file. The '-o' option works well with this option.

🧩 -f FORMAT, --format FORMAT: The format string used to manage time output is called the FORMAT.

🧩 --help: A description of the supported parameters and usages is provided in the help manual.

🧩 -v, --verbose: This option is used to show the output in great detail.

🧩 -V, --version: This command is used to show the installed time command's version information.

Linux Sleep Tool

The sleep command in Linux allows the terminal to wait for a set amount of time. The execution can be delayed by using a dummy task. It takes time in seconds by default. The delay time can be chosen in minutes (m), hours (h), and days (d). It assists in stopping the execution of any specific instruction for a predetermined time.

The syntax of the Sleep command is as follows:

sleep [OPTION]

 

Options

There are just two command line options that the sleep command offers, and they are as follows:

🧩 help: It is utilised to show the instruction manual.

🧩 version: This option is used to show version information.

Read about Instruction Format in Computer Architecture

Linux File Compress and Decompress Tools

These tools are used to compress a file or to view a compressed file. We will discuss each one of the tools one by one.

Linux Bzip and Bunzip

The bzip2 command can be used to compress a file similarly to the gzip. It takes a little more time but compresses better than gzip. The syntax of  bzip2 is as follows:

bzip2 CodingNinjas


The bunzip2 decompresses the file like gunzip. The syntax of  bunzip2 is as follows:

bunzip2 CodingNinjas

 

Linux Zcat or Zmore

Zcat can be used to view compressed or zipped files. The syntax is as follows:

zcat CodingNinjas


Similar to how more and less work for unzipped files, zmore and zless work for compressed files.

Linux Bzcat

Files that have been compressed with the bzip command will be shown using the command bzcat.

The Syntax is as follows:

bzcat CodingNinjas

Frequently Asked Questions

What are the basic components of Linux?

The most widely used open-source and free OS is Linux. Linux is ideal for all server applications because it was created to support high-volume and multithreading applications. There are mainly three components of Linux: Kernel, System Library, and System Utility.

What is Linux Loader?

The default boot loader for Linux is called LILO, or Linux Loader. It can boot operating systems from hard discs and is not dependent on a particular file system. Using LILO, many factors, including the root device, can be separately set.

Is learning Linux difficult?

Learning Linux is not difficult. The more familiar you are with modern technology, the simpler it will be for you to grasp the fundamentals of Linux. The fundamental Linux commands can be learned in a few days, but it will probably take a few weeks to feel more comfortable with them.

Conclusion

We have discussed the basic Linux tools. We started with the find and locate tools. Further, we discussed the date, time, sleep tools, and syntax. We also discussed the file compressor and decompressor tools in Linux.

We hope this blog helped you learn the basic tools available in Linux platforms. We recommend visiting Coding Ninjas Studio to learn more topics about Linux, such as

🔥 Linux Operating System.

🔥 Types of Operating Systems.

🔥 Functions of an Operating System.

If you liked our article, do upvote our article and help other ninjas grow.  You can refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingSystem Design, and many more!

Head over to our practice platform Coding Ninjas Studio to practice top problems, attempt mock tests, read interview experiences and interview bundles, follow guided paths for placement preparations, and much more!!

Happy Reading!!

Topics covered
1.
Introduction
2.
Tools for Searching Files in Linux
2.1.
Linux Find Tool
2.1.1.
Parameters
2.1.2.
Using File name
2.1.3.
Using File type
2.1.4.
Finding Directory
2.1.5.
Newer Files
2.1.6.
Empty Files
2.1.7.
Linux Locate Tool
2.1.8.
Options
3.
Linux Date Tool
3.1.
Options
3.2.
Format
4.
Linux Time Tool
5.
Linux Sleep Tool
5.1.
Options
6.
Linux File Compress and Decompress Tools
6.1.
Linux Bzip and Bunzip
6.2.
Linux Zcat or Zmore
6.3.
Linux Bzcat
7.
Frequently Asked Questions
7.1.
What are the basic components of Linux?
7.2.
What is Linux Loader?
7.3.
Is learning Linux difficult?
8.
Conclusion