While the above syntax looks simple, with this utility, we can perform complex searches without trouble. We’ll be discussing some of the most useful search patterns to make the most out of this command. Using the find command without any parameters, it will find all files or directories in the current location.
Find a File or Directory By Name
The number one use for the find command is the basic file/directory search. If we want to search for a file or directory by name, we must use the -name tag
There are other variables that we can add to our search to get more accurate results.
#command in linux #linux
mv Command Examples
Below is the basic mv command examples on Linux terminal.
#linux commands #command #mv #useful example #mv command #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
Generally on the development and staging environments have disk issues where multiple application’s are running. Sometimes we also face low disk space on production systems.
Few days back my production application goes down. After searching for half an hour, I found the application was down due to disk full on my server. So I had searches all files greater than 1 GB and then all files greater than 100 MB. There was few logs files which was large in size, which caused disk full.
In this tutorial, you will learn how to search file by their size using find command.
#linux commands #command #file #find #linux
In this remove or delete directories and files linux tutorial guide, you will learn how to remove empty directory and non empty directory linux using command line. And as well as how to remove/file files linux using command line.
So, this tutorial guide will show you you how to use the
rmdir commands to remove or delete files and directories in Linux with and without confirmation.
#how to delete directory in linux #how to remove non empty directory in linux #remove all files in a directory linux #linux delete all files in current directory #linux delete all files in a directory recursively #delete all files in a directory linux
This guide takes a tour of some of the best command-line tools that are used for searching matching strings or patterns in text files. These tools are usually used alongside regular expressions – shortened as REGEX – which are unique strings for describing a search pattern.
Without much further ado, let’s dive in.
Coming in the first place is the grep utility tool – is an acronym for Global Regular Expression Print, is a powerful command-line tool that comes in handy when searching for a specific string or a pattern in a file.
Grep ships with modern Linux distributions by default and gives you the flexibility to return various search results. With grep, you can perform a vast array of functioning such as:
The syntax for using the grep command is quite simple:
$ grep pattern FILE
For example, to search for the string ‘Linux‘ in a file, say, hello.txt while ignoring case sensitivity, run the command:
$ grep -i Linux hello.txt
Search For String in a File
To get more options that you can use with grep, simply read our article that examples more advanced grep command examples.
By default, sed command prints the output to STDOUT (Standard Out), implying that the result of the execution is printed on the terminal instead of being saved in a file.
Sed command is invoked as follows:
$ sed -OPTIONS command [ file to be edited ]
For example, to replace all instances of ‘Unix‘ with ‘Linux‘, invoke the command:
$ sed 's/Unix/Linux' hello.txt
Replace String in a File
If you want to redirect output instead of printing it on the terminal, use the redirection sign
( > ) as shown.
$ sed 's/Unix/Linux' hello.txt > output.txt
Redirect Output to File
The output of the command is saved to the output.txt file instead of being printed on the screen.
To check out more options that can be used, once again check out the man pages.
$ man sed
Ack is a fast and portable command-line tool written in Perl. Ack is considered a friendly replacement for grep utility and outputs results in a visually appealing manner.
Ack command searches the file or directory for the lines that contain the match for the search criteria. It then highlights the matching string in the lines.
Ack has the capacity to distinguish files based on their file extensions, and to a certain extent, the content in the files.
Ack command syntax:
$ ack [options] PATTERN [FILE...] $ ack -f [options] [DIRECTORY...]
For example, to check for the search term Linux, run:
$ ack Linux hello.txt
Check a String in a File
The search tool is quite intelligent and If no file or directory is provided by the user, it searches the current directory and subdirectories for the search pattern.
In the example below, no file or directory has been provided, but ack has automatically detected the available file and searched for the matching pattern provided.
$ ack Linux
Search String in a Directory
To install ack on your system run the command:
$ sudo apt install ack-grep [On Debian/Ubuntu] $ sudo dnf install ack-grep [On CentOS/RHEL]
#awk command #linux commands #sed command #commandline tools #linux tricks #linux