Linux Tutorial


How to use the grep command in Linux with examples

In this tutorial, you will learn how to use the grep command in Linux, Unix and OSX, with examples of common use cases.

The grep command in Linux is a utility used to search any given input files for one or more matching words or patterns. It is used to search a single file or an entire directory, including child directories, for a matching string.

Single File Grep Search

To find a word inside of a single file we specify the word we want matched and file to search. For example, to find the word hello in a file named file.txt we would run the following command.

grep "hello" file.txt

#administration #grep #linux

What is GEEK

Buddha Community

How to use the grep command in Linux with examples

Useful Example for the mv command in Linux

mv Command Examples
Below is the basic mv command examples on Linux terminal.

  • Rename file in current directory – For example rename file source.txt to dest.txt in current directory.
  • Move file to destination directory – Move a source.txt file available in current directory to /tmp directory. In above command the file name is unchanged at target directory. You can also rename file name at destination directory just by providing filename at destination.
  • Move file from source directory to destination directory – We can also move files or directory from some other directory to destination directory.
  • Move multiple files to destination at once – The mv accepts multiple source files and move them to the destination directory at once. The following command will move file1.txt, file2.txt in current directory and /opt/file3.txt to the /tmp directory. Here the last command line parameter is used as destination by the mv command.

#linux commands #command #mv #useful example #mv command #linux

Examples of the dig command in Linux

Dig Command Line Options and Examples
Here is the frequently used command line options and example’s of dig command.
1. Basic Dig Command
A basic dig command accept domain name as command line parameter and prints Address record.
2. Query With Specific DNS Server
The default dig command queries to dns server configured on your system. For example, the Linux systems keep default DNS entry in /etc/resolv.conf.
3. Print Short Answer
Use +short command line option to print result in short form. This is basically useful with the shell scripting and other automation tasks.
4. Print Detailed but Specific Result
Use +noall with +answer to print detailed information but specific. This will print only answer section including few more details as a result.

#linux commands #command #dig #dig command #useful examples #linux

Examples of how to use the lsof command in Linux

Below are some of the popular usage of the lsof command.

  1. List all open files
  2. List by filename
  3. List open files by username
  4. List open files by process
  5. List open files by PID
  6. List open files containing directory
  7. Repeat mode
  8. List open files with network protocol
  9. List open files by port
  10. List open files by IPv4/IPv6
  11. List open files on NFS
  12. List locked deleted files

#linux #command #lsof command #examples

date command in Linux with Examples

date Command Examples
Show date time in UTC/GMT
View past dates on specific days
View future dates
View date in other timezone
Print date in specific format
View file modification time

#linux commands #command #date #linux

Examples of the curl command in Linux

URL Syntax
The URL syntax is completely protocol-dependent with cURL. Before reading more about parameters or example, you must know the URL formats, you can use with curl.
CURL Command Options
curl command comes with large number of command line options. Which provides it great flexibility to perform various tasks. Here we will describe you some frequently used command options with curl command.

#linux commands #curl #examples #linux