Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

Explain use of following commands with example.

1. path

  • The path command in Linux displays the list of directories that the shell searches for executable programs.
  • This information is important for the shell to know where to find the program you want to run.

Example:

$ path
/usr/local/bin:/usr/bin:/bin

This output shows that the shell will search for programs in the following directories:

  • /usr/local/bin
  • /usr/bin
  • /bin


If you type a program name at the command prompt without specifying its full path, the shell will search each of these directories in order until it finds the program.

2. pwd

  • The pwd command in Linux stands for “print working directory.”
  • It displays the absolute path of the current directory you are working in.

Example:

$ pwd
/home/bard

This output shows that the current working directory is /home/bard.

3. wc

  • The wc command in Linux stands for “word count.”
  • It counts the number of lines, words, and bytes in a file or files.

Example:

$ wc file.txt
10 25 123 file.txt

This output shows that the file file.txt has:

  • 10 lines
  • 25 words
  • 123 bytes

You can also use the wc command with options to count specific types of characters or bytes.

Example:

$ wc -c file.txt
123 file.txt

This output shows that the file file.txt has 123 bytes.

The wc command is a versatile tool that can be used for a variety of tasks, such as checking the size of a file, counting the number of lines in a code file, or checking the number of words in a document.

4. grep

grep is used to search for lines in a file that match a specified pattern. It is a powerful tool for filtering and analyzing text data.

Example:

$ grep "error" file.txt

This command searches the file file.txt for lines containing the word “error”.

Output:

Line 10: An error occurred while processing the data.
Line 25: Error: File not found.

5. echo

echo is used to print text to the standard output. It is a simple but versatile command with various use cases.

Example:

$ echo "Hello, world!"

This command will print the text “Hello, world!” to the console.

6. cat

cat is used to read and display the contents of one or more files. It can also be used to concatenate files.

Example:

$ cat file1.txt file2.txt

This command will display the contents of both file1.txt and file2.txt consecutively.