Trending December 2023 # Exclude Grep From Ps Results On Linux # Suggested January 2024 # Top 12 Popular

You are reading the article Exclude Grep From Ps Results On Linux updated in December 2023 on the website Achiashop.com. We hope that the information we have shared is helpful to you. If you find the content interesting and meaningful, please share it with your friends and continue to follow and support us for the latest updates. Suggested January 2024 Exclude Grep From Ps Results On Linux

The ps command in Linux is used to display information about the running processes on a system. It provides a snapshot of the current processes, including the process ID (PID), the user that owns the process, the percentage of CPU and memory usage, and the command that started the process. By default, ps only shows information about processes that are running in the same terminal session as the ps command. However, using various options and command line arguments, you can customize the output to show information about all processes running on the system, or even remotely.

Listing All Processes

To list all processes running on a Linux or Unix-like system using the ps command, you can use one of the following command options and arguments −

ps aux − This command shows all processes running on the system, including processes owned by other users. The a option shows processes for all users, the u option shows detailed information about the user running the process, and the x option shows processes that do not have a controlling terminal.

ps -e or ps -ef − This command shows all processes on the system, including the processes without a controlling terminal. The e option shows all processes and the f option displays the full format listing including the parent-child relationship of the processes.

ps -A − This command show all running processes, including those without a terminal controlling.

ps -eLf − It shows all processes in a tree format that show parent-child relationship as well as the thread of a process

Example

Here is an example of using the ps aux command to list all running processes on a Linux system −

$ ps aux USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.1 21644 4100 ? Ss Jan11 0:08 /sbin/init root 2 0.0 0.0 0 0 ? S Jan11 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? S Jan11 0:00 [ksoftirqd/0] root 4 0.0 0.0 0 0 ? S Jan11 0:00 [kworker/0:0] root 5 0.0 0.0 0 0 ? S Jan11 0:00 [kworker/0:0H] ...

This command output shows the following information for each process −

USER − The user that owns the process

PID − The process ID

%CPU − The percentage of CPU usage

%MEM − The percentage of memory usage

VSZ − Virtual memory size

RSS − Resident set size

TTY − The terminal associated with the process

STAT − The process state

START − The time when the process started

TIME − The total CPU time consumed by the process

COMMAND − The command that started the process

Looking for a Specific Process

You can use the ps command in conjunction with other commands, such as grep or awk to search for a specific process. Here’s an example of how you can use the ps command to search for a specific process and display only the relevant information −

root 1027 0.0 0.1 47320 3304 ? Ss Jan11 0:00 /usr/sbin/sshd -D

This command uses the ps aux command to list all running processes, and pipes the output to grep ssh which filters the output to show only the lines that contain the string “ssh”. In this example, the output shows that the ssh daemon process is running and the pid is 1027

Another way to find a specific process is −

root 1027 1 0 Jan11 ? 00:00:00 /usr/sbin/sshd -D

This command uses the ps -ef command to list all running process, and pipes the output to grep ssh, that filters the output to show only the lines that contain the string “ssh”. In this example, the output shows that the ssh daemon process is running, the pid is 1027, parent pid is 1 and other details as well.

You can also use the pgrep command to find the pid of the process you’re looking for, by running

$ pgrep -fl ssh 1027 /usr/sbin/sshd -D

pgrep takes a -f option that match against the entire command line. and -l option to show the name of the command

Excluding grep

If you want to list all processes and filter out a process that contains a specific string, you can use the ps command with grep -v to exclude the string you want to filter out.

For example, to exclude all processes that contain the string “grep” from the output −

This command will display all the process except the ones that have the string grep in the command line.

Here is another way using the ps command alone −

This command will display all process except the ones that have the string grep in the command line, Using the –not-heading option will exclude the headers, and awk with ! and /grep/ pattern matches the lines that do not contain the string ‘grep’ and prints them.

You can replace grep with any string that you want to exclude from the output.

Make a grep Expression That Excludes grep Itself

If you want to use the grep command to filter out processes that contain a specific string, but also exclude the grep command itself from the output, you can use the -v option to invert the match and the -w option to match only the whole word −

This command uses ps aux to list all running processes, and pipes the output to grep -w -v grep, which filters the output to exclude any lines that contain the exact string “grep” and also matches only the whole word.

Another way you can achieve this is by using the awk command

This command uses ps aux to list all running processes, and pipes the output to awk command, which filters the output to exclude any lines that contain the exact string “grep” at the end of the command field. $11 is the field number of the command field, and !~ is a regular expression match negation.

Conclusion

In conclusion, the ps command is a useful tool for listing and monitoring processes running on a Linux or Unix-like system. You can use the various command options and arguments of the ps command to display information about all running processes, or filter the output to show only specific processes. Also, you can use other commands like grep, awk, pgrep to filter the output. You can also use grep with the -v option and -w option to exclude a specific process from the output, as well as awk with a regular expression to match the negation of the string. Keep in mind that the ps command’s output format and options may vary across different Linux distributions and versions.

You're reading Exclude Grep From Ps Results On Linux

Grep Command In Linux: Syntax, Options, Examples, & More

As a system admin on a Linux system, you might have to parse through a huge log file in Linux. It might seem a painstaking task, especially in the instances where you have to match patterns. Thankfully, grep command in Linux is a boon for such situations. If you are wondering what is grep command and how it works, below, we have prepared an easy guide to help you understand this useful Linux command.

What Is the grep Command in Linux

The grep command is a powerful command line tool in Linux used to search and filter out specific patterns or strings in a file, directory, or even in the output of other commands. You may be wondering about its unusual name; well it stands for “Global Regular Expression Print.” It was first introduced by Ken Thompson in 1973 for the Unix operating system. With its versatility and ease of use, the grep command is a must-have tool in every Linux user’s arsenal.

Generally, the grep command comes preinstalled on most Linux distros, but if you find it to be missing on your system, install it using the following commands:

Install on Debian-based systems:

sudo apt install grep

Install on Fedora-based systems:

Install on Arch-based systems:

sudo pacman -S grep

Linux Grep command: Syntax & Options

Using the grep command in Linux is pretty straightforward, thanks to its simple syntax along with the multiple options to play with. The syntax to use the grep command is:

How to Use the Grep Command in Linux

Say, for example, you want to match email addresses, you can use the regex “(.+)@(.+)n“. Seems complicated? Let’s break down this:

(.+) matches any characters except new lines

@ checks if the “@” symbol is present in the given sentence.

Now that you know what are regular expressions and how the grep command works, let’s now see how to use the grep command in Linux.

Search For Strings in Files with grep Command

The most common way to use grep is to search for specific strings in a file. The basic syntax to search with the grep command in files is:

grep "mango" fruits.txt

If you want to search while ignoring the case, then use the -i flag with the grep command for the above example:

grep -i "mango" fruits.txt

Search in Multiple Files with grep

With the grep command, you can not only search in a single file but also multiple files. This feature particularly becomes very handy when you need to go through multiple large files. The syntax to search for strings/patterns in multiple files with the grep command is:

For example, if you want to search for the string “student”, inside the files “student1.txt” and “student2.txt,” use this command:

grep "John" chúng tôi student2.txt

Search All Files in a Directory with grep

Suppose, you need to search for a string and you don’t remember the file name where it exists. You can obviously write all the filenames present in the directory, but instead, you can use simply use the “*” wildcard as shown:

grep "apple" *

If you want to search in specific file types only, use this syntax:

For example, if you want to search for the word “mango” only in .txt files, use this command:

Using Regular Expression with grep

For example, if you want to filter out email IDs use this command:

grep -e "(.+)@(.+)" emails.txt

Search for Multiple Keywords using grep Command

Count Matching Results using grep Command

Sometimes, you may need to know the number of matching results. For this, you can use the -c flag with the grep command:

For example, if you need to see how many email IDs are there in the file student1.txt, use this command:

grep -E -c "(.+)@(.+)" student1.txt

If you want to see the number of lines not matching the search query, simply add the -v flag along with -c:

grep -v -E -c "(.+)@(.+)" student1.txt

Using grep Command with Shell Pipes

For example, if you want to see how many times the gcc command has been executed previously, you can use this command:

This will show only the results containing the word “gcc,” as shown in the picture below.

Using grep Command in Linux

The grep command is an essential tool for users who want to search for specific patterns or words in various files, directories, or even in other Linux command outputs. Once you have got hold of all the essential options and syntax, the grep command can help you to increase your productivity exponentially. While you are here, check out the new features in Ubuntu 23.04.

Grep Command in Linux FAQs

Google On What’s Going On With Faq Rich Results

Google’s John Mueller was asked about the status of the FAQ structured data and if it still worked for producing rich results. Mueller answered yes and explained the process of fine tuning not just the rich results but also the search results themselves.

FAQ Structured Data

Structured data is markup, like HTML that provides the information on the web page in an organized manner that can then be used to show featured results known as Rich Results.

Rich results tend to be coveted because they are big and featured at the top of the search results.

FAQ rich results have the effect of dominating the search results and knocking out one or two competitors from page one of the top ten, resulting in perhaps only seven search results showing instead of ten.

Screenshot of Google’s Mueller Discussing FAQ Rich Results

Does FAQ Structured Data Still Work?

The question was simply worded:

“Does the FAQ still work?”

Mueller answered:

“I assume this means the FAQ structured data. …From what I know that continues to exist and continues to work.”

Mueller followed up by saying that Google makes adjustments to rich results, presumably to achieve specific benchmarks of user satisfaction with the search results.

Here’s how John explained it:

overloading the search results with all of these… bling and extra functionality that just confuses people in the end.

So what often happens is when we start a new type of rich results people will kind of reluctantly try it out and if it works well then everyone tries it out.

And then suddenly the search results page is totally overloaded with this type of structured data.”

This next part is really interesting because he refers to Google’s systems trying to refine the search results along with the engineers.

Mueller’s follow up:

“…Then our systems and our engineers work to kind of fine tune that a little bit so that we continue to use that structured data.

We just don’t show it for all sites all the time.

Which kind of makes sense, similar to how we tune the snippets that we show for websites and tune the rankings and tune the search results overall.

So that’s something where from at least as far as I know I don’t think we’ve turned off any of the FAQ rich results types.”

Fine Tuning the Search Results

Mueller’s response to those questions was to note that Google is constantly making changes (fine tuning?) to the search results and downplayed a cause and effect from the changes the people were asking about.

Google isn’t showing as many FAQ rich results as it had when they were first introduced.

What’s interesting about John Mueller’s explanation for the scarcity of FAQ rich results is that the answer was in the context of Google “fine tuning” the rich results.

When trying to understand some (not all) changes that Google makes to the search engine results pages (SERPs), it might be useful to frame the inquiry within the context of whether the change might be undergoing a fine tuning and if so, what is it that Google is fine tuning it for? The answer is probably a mix of things like user experience and Google’s desire to show as many answers as possible on a web page to satisfy those  users.

Citations

Watch John Mueller answer question at the 32:31 minute mark

Accessing Your Linux Server From Android

If you have a Linux server and it’s not in your living room, chances are good you connect to it remotely. You could be using that server for web hosting, backups, as a development box. or all of the above. No matter what, a remote connection is handy.

Most of the time it would be easy to assume you’re connecting from another computer. You might not have access to a computer all of the time, though. But what about your Android device? Not only is connecting from an Android device doable, it’s fairly easy.

Before you get started

Before you start connecting to your server from Android, you should consider how it affects security. Connecting from Android isn’t inherently insecure, but any additional way you connect to your server is another door. Adding a door means that someone else could potentially open that door. That’s not even considering unintended vulnerabilities like Heartbleed, which caused major trouble a few years ago.

Whether or not you’re connecting from Android, you should read up on hardening your server. After all, better safe than sorry.

Set up your server

One of the most common and secure ways to connect to your server is SSH, or Secure Shell. If you haven’t already done so, you’ll want to install OpenSSH, which also includes SFTP (Secure FTP). Installing and configuring SSH is easy, but beyond the scope of this article. Fear not, as we have a step-by-step guide to installing and configuring SSH and SFTP on Ubuntu. Even if you’re using another distribution, those instructions can get you most of the way there.

Set up your Android device

Both SSH and SFTP are pretty keyboard-heavy, so you may want to consider using a Bluetooth keyboard with your device. There are plenty of Android-compatible Bluetooth keyboards available, and many of them are very affordable. Alternatively, if you don’t have access to an external keyboard, you can install and use the Hacker’s keyboard app.

Next, you’ll need to get yourself an SSH app to connect to your server from Android. Two of the most popular options available right now are JuiceSSH and Termius.

JuiceSSH

JuiceSSH supports Bluetooth keyboards and offers plenty of options. The base version of the app supports two-factor authentication, optional plugins, and ZLib compression on SSH connections. Upgrading to the Pro version adds more color schemes, automatic backup of your connections, and a handy widget. The app is available for free on the Google Play Store.

Termius

Termius is another popular option. In addition to SSH, this app also supports SFTP. If you frequently find yourself needing to upload files from your Android device to your server, this is handy. The free version of the app available on Google Play has most of the features you’ll need. Unfortunately, SFTP support is only included in the Premium version, which costs $59.88 per year.

Connecting to your server

To connect to your server, you’ll either need your username and password or your private SSH key. Using a username and password is easier but is also far less secure. The guide to configuring SSH on Ubuntu above includes a step on generating your keys. To use these with your Android SSH app of choice, you’ll need to copy your public key to your device. One of the easiest ways to do this is to save your key in a password manager like 1Password or LastPass and copy and paste it on your Android phone.

Determining your IP address

Once you have your key imported, all you’ll need is your server’s IP address. There are multiple ways to determine this. First you need to know which IP address you’re looking for.

If your server is a web host or a remote host from a service like Linode or DigitalOcean, you’ll need your server’s public IP address. One simple way is to type the command curl chúng tôi in a terminal window on your server. This uses a website to retrieve your public IP address.

Once you have your private key and IP address, you can use this to connect from your Android device. If you’re looking for things to do on your server’s command line, we have a list to get you started.

Kris Wouk

Kris Wouk is a writer, musician, and whatever it's called when someone makes videos for the web.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Sign up for all newsletters.

By signing up, you agree to our Privacy Policy and European users agree to the data transfer policy. We will not share your data and you can unsubscribe at any time.

How To Build A Package From Source In Linux

Besides its open-source nature, customizability is one of the other reasons many users love Linux: you can modify and configure almost every file to meet your specific needs and style. This includes the ability to rebuild a package from source.

The ability to rebuild a package from the source can be beneficial to any Linux power user because it allows you to change packages, enable or disable a feature, or even apply custom modifications.

This article describes simple steps to rebuild a package from the source.

1. Enable Source Repositories

The first step before rebuilding a source package is to enable the source repositories for your distribution. Enabling the source repos allows you to search and download source packages using the default apt package manager.

In Debian systems, you can add the source packages by editing the “/etc/apt/sources.list” file.

For example, the following are the contents of the “sources.list” for Debian buster with the source packages enabled.

Once enabled, save the file and update the system using the command:

sudo

apt-get update

2. Fetch Source Package

After running the update process, you can then fetch the source package to modify your system.

For example, let us use the tar package. Start by creating a directory to store the source packages:

mkdir

apt-rebuilds

cd

apt-rebuilds

Next, download the source package using the command:

apt-get

source

tar

To view the files in the directory:

ls

-la

3. Check and Install Build Dependencies

The next step involves checking and installig the required build dependencies for the package you wish to rebuild.

Inside the directory location for the source packages, enter the command below to check for the unmet build dependencies.

sudo

dpkg-checkbuilddeps

The command will display all the unmet dependencies for the package. Although you can install them manually, a simpler method is to use apt to install the source packages.

To do this, use the command:

sudo

apt-get build-dep

tar

The command above will fetch the dependencies and install them for you.

4. Modify the Package

At this stage, you will want to make the changes to the package and enable or disable any feature you need. (Doing this is a broad aspect, and thus, we cannot possibly cover every change you can make for each package.)

Once you make all the changes and personal tweaks, recompile the source and save it with a different version number. You can do this using the command:

dch

--local

tar

Running this command will prompt you for your desired editor and launch the changelog for you to edit.

You can add a few lines to describe the changes made and change the version.

5. Build Package

The final step is to build the source package. Ensure you are in the source package directory and run the command:

dpkg-buildpackage

--force-sign

The command will initialize the build process using all the changes made in the above step.

Depending on the changes and the package to rebuild, the process can take a few minutes or longer.

6. Install Package

Once the build process completes, it will generate a binary package in the parent directory. To install, all you have to do is use the dpkg command:

sudo

dpkg

-i

*

.deb In closing

Building packages is a must-have skill for any Linux administrator and a good skill to have as a regular Linux user. Now that you know how to build a package from source, you can also learn how to easily rename files in Linux and how to use and edit the Hosts file in Linux.

John Wachira

John is a technical writer at MTE, when is not busy writing tech tutorials, he is staring at the screen trying to debug code.

Subscribe to our newsletter!

Our latest tutorials delivered straight to your inbox

Sign up for all newsletters.

By signing up, you agree to our Privacy Policy and European users agree to the data transfer policy. We will not share your data and you can unsubscribe at any time.

How To Install Git On Linux

Git is a popular version control system that enables developers to track changes in their codebase and quickly interact with others. It is widely used in the software development business and has evolved into an essential tool for many programmers.

In this article will walk you through the Installation of Git on Linux.

Prerequisites

Access to a user account that has sudo or root rights.

A computer that is running Ubuntu 20.04 or 22.04.

Access to a command line/terminal window (Ctrl+Alt+T).

Install Git using APT

This is the easiest way to install Git on your system because Git package is included in the official Ubuntu chúng tôi you wish to install a specific version or latest stable version, you need to Install Git from source.

[email protected]:-$ sudo apt update Yeading package lists... 99%

This command will refresh the package listings in preparation for upgrades and new package installations.

Then, if there are any pending upgrades, upgrade the system:

sudo apt upgrade [email protected]:-$ sudo apt upgrade Reading package lists... Done Building dependency tree... Done Reading state information... Done Calculating upgrade... Done The following packages were automatically installed and are no lon ger required: libflashromi libftdi1-2 1ibllvmi3 virtualbox-guest-utils Use 'sudo apt autoremove' to remove them. The following NEW packages will be installed: libatomic1 libllvmi5 linux-headers-5.19.0-45-generic linux-hwe-5.19-headers-5.19.0-45 linux-image-5.19.0-45-generic linux-modules-5.19.0-45-generic linux-modules-extra-5.19.0-45-generic systemd-hwe-hwdb The following packages will be upgraded: accountsservice alsa-ucm-conf apparmor apport apport-gtk apt apt-utils avahi-autoipd avahi-daemon avahi-utils base-files bind9-dnsutils bind9-host bindo-libs britty ca-certificates cpp-11 cups cups-browsed cups-bsd cups-client cups-common cups-core-drivers cups-daemon cups-filters cups-filters-core-drivers cups-ipp-utils cups-ppdc sudo apt install git [email protected]:-$ sudo apt install git Reading package lists... Done Building dependency tree... Done Reading state information... Done The following packages were automatically installed and are no nger required: Llibflashrom1 libftdi1-2 1ibllvm13 virtualbox-guest-utils Use 'sudo apt autoremove' to remove them. The following additional packages will be installed: git-man liberror-perl Suggested packages: git-gui gitk gitweb git-cvs git-mediawiki git-svn The following NEW packages will be installed: git git-man liberror-perl © upgraded, 3 newly installed, © to remove and 1 not upgraded. Need to get 4,147 kB of archives. After this operation, 21.6 MB of additional disk space will be used. Do you want to continue? [y/n]

During the installation, you may be asked to confirm the installation by typing ‘y’ and pressing Enter. Please do so in order for the installation to proceed. The system will then download and install the Git package and any dependencies.

git --version

If Git was successfully installed, the version number will be displayed in the output terminal.

Install Git from Source

If you wish to install a specific version of Git or any latest stable version, you need to compile Git from source. Make sure you install the dependencies required to install from source.

sudo apt update sudo apt install dh-autoreconf libcurl4-gnutls-dev libexpat1-dev make gettext libz-dev libssl-dev libghc-zlib-dev

Now choose the version you need to install and copy the tar.gz link from the official git releases page.

Now you can download and extract the version you wish to the /usr/share directory.

Once the download is completed you can move inside the directory and execute the following commands to compile and install Git.

.41.0.tar.gz

HTTP request sent, awaiting response… 362 Found

following] /tags/v2.41.0 3… connected. HTTP request sent, awaiting response… 260 OK Length: 10884275 (16M) [application/x-gzip] saving to: ‘STDOUT’

Here are the instructions for compiling and installing Git on Linux:

cd /usr/src/git-* sudo make prefix=/usr/local all sudo make prefix=/usr/local install [email protected]:~$ cd /usr/src/git-* sudo make prefix=/usr/Tocal all Sudo make prefix=/usr/Tocal install GIT_VERSION = 2.41.6 * new build flags CC oss-fuzz/fuzz-conmit-graph.o CC oss-fuzz/fuzz-pack-headers.o CC oss-fuzz/fuzz-pack-idx.o CC daemon.o * new link flags CC common-main.o cc abspath.o CC add-interactive.o CC add-patch.o CC alias.o CC alloc.o cc apply.o CC archive-tar.o cc archive-zip.o git --version

You will get a sample output similar to the one below.

Now you have compiled and installed Git from source.

Configure the Git User Information

Before you begin using Git, you should configure your user information. This data will be linked to any commits you make in a Git repository. Replace the placeholders with your own name and email address and run the following commands:

git config --global chúng tôi "Your Name" git config --global user.email "[email protected]"

You may check the configuration settings by running the command:

git config --list

A list of setup items, including your name and email address, will be displayed.

Output sample:

If you prefer to manually edit the Git configuration file, you can do so with any text editor you like, such as nano:

nano ~/.gitconfig

Now your changes will be saved inside the ~/.gitconfig folder.

Also read: You might also find useful our guide on How to Modify the Hostname in Linux

Conclusion

To summarize, installing Git on Linux is a simple process. By following the provided steps, you can easily set up Git, update your system, and configure your user information. You are now ready to use Git’s sophisticated version control capabilities for your software development projects after successfully installing it.

Update the detailed information about Exclude Grep From Ps Results On Linux on the Achiashop.com website. We hope the article's content will meet your needs, and we will regularly update the information to provide you with the fastest and most accurate information. Have a great day!