Linux: replace text string in file [Guide]

Editing text files on Linux by hand can be tedious. That’s why it’s good to know how to replace text strings in files using the command line quickly. If you’re new to Linux and don’t know how to do it, we can help! Follow along as we show you how to replace a text string in a file on Linux!

Linux: replace text string

Replace text string in file – sed

The sed tool is the best way to replace a text string in a file on Linux. The reason? It’s straightforward to use and does its job very well. Sed is usually pre-installed on 99% of Linux operating systems, so there’s no need to install it to use it.

Replacing a text string in a file with Sed is done with the sed -i command. Here’s how to use it. First, open up a terminal window on the Linux desktop. You can open up a terminal window by pressing Ctrl + Alt + T on the keyboard.

Once the terminal window is open and ready to use, write out sed -i in the terminal prompt. This is the start of the replacement command.

sed -i

After writing out the sed -i command, add in a ‘ quote mark. This quotation mark is essential, as all text being replaced with sed -i needs to start after this mark.

sed -i '

Following the first  mark, write s/. The s/ goes directly before the existing text you wish to replace using sed.

sed -i 's/

Now that the s/ is written into the terminal command-line prompt, it is time to tell sed what text to replace in the file. In this example, we’ll replace the word “apple.” 

sed -i 's/apple

When the text we want to replace is written into the command, the next step is to write in the new text that will replace it. In this example, we’ll replace “apples” with “oranges.”

sed -i 's/apples/oranges

Once the text we want to replace is written into the command (oranges), close off the command with g/. The g/ tells sed to replace all text instances (apples) with the new text (oranges). It should look like the example below.

Note: if you do not want to replace every text in the file (apples to oranges, for example), remove the g and have it run as sed -i 's/apples/oranges/' instead.

sed -i 's/apple/orange/g'

Finally, tell sed what file the text is in that needs replacing. In this example, fruit.txt in the home directory is the target.

sed -i 's/apples/oranges/g' ~/fruit.txt

Press the enter key to execute the command and replace your text string in the file.

Replace text string in file – Perl

Another way to replace a text string in a file on Linux is with the Perl programming language. Perl is used for text processing a lot, so naturally, it can swap out text strings in files and is perfect for this use case.

To start, ensure you have Perl installed on your Linux PC. Most Linux operating systems come with Perl installed. However, if you do not have it, check your operating system’s help page for information on how to get it working.

Using Perl to replace text strings in a file requires the terminal. Open up a terminal on the Linux desktop by pressing Ctrl + Alt + T on the keyboard. Or, search for “Terminal” in the app menu and launch it that way.

Once the terminal window is open and ready to use, start by typing out perl -pe in the command-line prompt. The perl -pe command is what is needed to replace a text string in a file.

perl -pe

Upon writing out perl -pe in the terminal prompt, you will need to start with the first ‘ quote mark. This mark tells Perl where the text replacement area is in the command.

perl -pe '

Following the first ‘ quote mark, add s/, followed by the string of text you wish to replace, and another /. For example, to replace “apples” in the fruit.txt file, you’d write out the following text.

perl -pe 's/apples/

After writing out the word(s) you wish to replace, add in the word that will replace the existing text. For example, if you want to replace “apples” in “fruit.txt” with “oranges,” add in “oranges” after perl -pe 's/apples/ so it looks like perl -pe 's/apples/oranges/.

perl -pe 's/apples/oranges/

Once both strings of text are in the command, you’ll need to specify the input file that Perl uses. For example, if you want to replace text in the “fruit.txt” file, you’ll need to specify it in the command.

Note: in this example, the “fruit.txt” file is in the home directory (~/). Be sure to replace “~/fruit.txt” with your text file’s location for the command to work.

perl -pe 's/apples/oranges/' ~/fruit.txt

Now that the input file (the file you’re modifying with Perl) is added to the command, the command should look like it does below.

perl -pe 's/apples/oranges/' ~/fruit.txt > /tmp/output.txt;cat /tmp/output.txt > ~/fruit.txt

When the command above is run, the text string will be replaced with the new text you specified. In our example, we replaced “apples” with “oranges.” To view the changes, enter the command below.

cat fruit.txt

The post Linux: replace text string in file [Guide] appeared first on AddictiveTips.

Ubuntu: delete app history [Guide]

After using Ubuntu for a while, the app history builds up, slowing down your system. Thankfully, it is easy to clear this app history to speed up your system. In this guide, we’ll show you how.

Ubuntu: delete app history

Method 1 – Bleachbit

If you want to delete app history on Ubuntu, the best way to go is Bleachbit. It’s a fantastic tool that can do a deep scan of your system and erase app history. Bleachbit is open-source and works on everything from web browser app history to photo thumbnails, etc.

Installing Bleachbit on Ubuntu

Sadly, the Bleachbit application isn’t a default Ubuntu application and doesn’t come pre-installed. For this reason, you must install it before attempting to use it on your system. 

To start the installation of Bleachbit, open up the Ubuntu Software Center. To open up Ubuntu Software Center, press Win on the keyboard, search for “Ubuntu Software,” and open up the app.

Once the app is open, find the search box, type in “Bleachbit,” and press the Enter key to view the search results. Look through the search results for “Bleachbit, and click on it with the mouse.

After selecting “Bleachbit,” look for the “Install” button and click on it with the mouse. You’ll then be prompted to enter your password. Do so. When your password is entered, Bleachbit will begin installing.

Click “Launch” when done to open up the app.

Terminal installation

Don’t want to install the Bleachbit application on your Ubuntu PC using the Ubuntu Software Center? Try setting it up with the terminal. To start, launch a terminal window by pressing Ctrl + Alt + T on the keyboard.

Once the terminal window is open, use the apt install command to install the “bleachbit” package on your computer.

sudo apt install bleachbit

Upon entering the command above, Ubuntu will ask for your password. Type it out and press the Enter key, then press to install the software.

Delete app history with Bleachbit

To delete app history on your Ubuntu PC with Bleachbit, start by launching the app. You can launch the app by searching for “Bleachbit” in your Linux desktop’s application menu.

Once the Bleachbit program is open, follow the step-by-step instructions below.

Step 1: In Bleachbit, look to the left-hand sidebar. Once in the sidebar, look for the app history you wish to clear. For example, to clear Discord app history, select the box next to “Discord,” or for Firefox, select the box next to “Firefox,” etc.

Step 2: After selecting all apps you wish to clear, find the “Preview” button in the app’s top-left corner and click on it. When you click on “Preview,” Bleachbit will calculate the amount of space saved after deleting your app history.

Step 3: Locate the “Clean” button in the top-left hand corner of the app, and click on it. By selecting this button, Bleachbit will attempt to clear all the app’s history files (s) you selected in Step 1.

Keep in mind that the cleaning process may take some time, especially if you’ve selected apps with many files on your Linux PC. For best results, be patient and sit back and wait for everything to complete. 

When the cleaning process is complete, Bleachbit will show you what was deleted in the log on the screen. Please read it, then close the app as the process is complete.

Method 2 – Stacer

Another way to clear app history on Ubuntu is with Stacer. It’s a system optimizer and all-around helpful tool for Linux that many in the community swear by. It has a built-in cleaning app that users can use to clear app history. Here’s how to do it.

Installing Stacer on Ubuntu

Before attempting to use Stacer to clear app history on Ubuntu, you must install it. In the past, on AddictiveTips, we’ve gone over how to install the Stacer application. Follow that guide to learn how to get the app working on your Ubuntu system.

Once you’ve gotten Stacer installed on your Ubuntu PC, move on to the next section of the guide.

Delete app history with Stacer

To clear application history on Ubuntu with Stacer, open up the app by searching for it in your app menu. Once the Stacer application is open, follow the step-by-step instructions below.

Step 1: In Stacer, look to the left-hand sidebar in the app for the broom icon, and click on it. The broom icon is the Stacer “System Cleaner” area.

Step 2: Inside the System Cleaner area, check the box next to “Application Caches” and “Application Logs”. By selecting these options, you’re telling Stacer that you want to clear your app history on Ubuntu.

Step 3: Click on the blue magnifying glass icon to start the cleaning process in Stacer. From there, check both “Application Logs” and “Application Caches” once again. Then, press the blue broom icon to clean your app history.

When the cleaning process is complete, you’ll see green text saying that your files have been cleaned. After reading the text, close Stacer as it is no longer needed.

The post Ubuntu: delete app history [Guide] appeared first on AddictiveTips.

Linux: test disk speed [Guide]

Need to test your hard drive speed on Linux but can’t quite figure it out? We can help! Follow along with this guide as we go over how you can test your disk speed on Linux!

Linux: test disk speed

Gnome Disk Utility

If you want to test disk speed on Linux, the best way to go about it is with the Gnome Disk Utility. It’s a handy, easy-to-understand program that can benchmark and test hard drive speeds.

The Gnome Disk Utility application doesn’t come pre-installed on every Linux operating system, though, so before we go over how to use it to test your hard drive disk speed, you will need to install the program.

To start the installation of Gnome Disk Utility on your Linux PC, open up a terminal window. You can open up a terminal window by pressing Ctrl + Alt + T on the keyboard. Or, open up the app menu and search for “Terminal.”

Once the terminal window is open and ready to use, follow along with the installation instructions down below to get the Gnome Disk Utility application set up on your Linux PC.

Ubuntu

On Ubuntu, install the Gnome Disk Utility application by making use of the apt install command below.

sudo apt install gnome-disk-utility

Debian

Those using Debian Linux will be able to get the Gnome Disk Utility application set up by executing the apt-get install command.

sudo apt-get install gnome-disk-utility

Arch Linux

On Arch Linux, the Gnome Disk Utility application is installable via the Pacman command below.

sudo pacman -S gnome-disk-utility

Fedora

Those on Fedora Linux can get the Gnome Disk Utility program working via the dnf install command.

sudo dnf install gnome-disk-utility

OpenSUSE

On OpenSUSE Linux, the Gnome Disk Utility program is easily installed by making use of the zypper install command below.

sudo zypper install gnome-disk-utility

Now that the Gnome Disk Utility application is open launch the program by searching for “Disks” in your app menu. Then, follow the step-by-step instructions down below to test your disk speed on Linux.

Step 1: Inside the Gnome Disk Utility app, look to the left-hand sidebar and locate the disk whose speed you want to test. Then, click on it with the mouse to look at the overview of the app’s drive.

Step 2: Find the menu button in Gnome Disk Utility, and select it with the mouse to open it up. If you cannot find the menu, look to the left of the minimize button.

Inside the Gnome Disk Utility menu, locate the “Benchmark Disk” button and select it with the mouse. By choosing the “Benchmark Disk” button, you’ll open up the tester tool.

Step 3: Once the benchmark tool is open, locate the “Start Benchmark” button, and click on it to start up the benchmark. Keep in mind that this benchmark could take a bit of time to complete, so be patient. 

When the benchmark tool is complete, Gnome Disk Utility will create a full readout of your hard drive. To check the speed, find the “Average Read Rate” and “Average Write Rate.” This will tell you your hard drive speed.

HDParm

HDParm is another application that you can use to test your disk speed on Linux. It’s not as easy to use as Gnome Disk Utility, and there isn’t a GUI, but it is just as helpful. 

The HDParm application isn’t installed by default on every Linux operating system out there, but it is on quite a few. To check if HDParm is installed on your computer, run the hdparm –help command in a terminal window. 

If you do not have HDParm installed on your Linux PC, open up a terminal window on the Linux desktop by pressing Ctrl + Alt + T on the keyboard. Once the terminal window is open, follow the installation instructions below.

Ubuntu

You can install HDParm on Ubuntu with the apt command.

sudo apt install hdparm

Debian

To install HDParm on Debian, use apt-get.

sudo apt-get install hdparm

Arch Linux

On Arch Linux, install HDParm by using Pacman command.

sudo pacman -S hdparm

Fedora

On Fedora, install HDParm with dnf.

sudo dnf install hdparm

OpenSUSE

Install HDParm on OpenSUSE with zypper.

sudo zypper install hdparm

Once HDParm is installed on your computer, follow the step-by-step instructions below to test your disk speed.

Step 1: First, run the lsblk command to view all connected hard drives on the system. 

lsblk

Look through and find the hard drive you plan to test. In this example, we’ll test /dev/sda. For more information on finding hard drive info in lsblk, read this guide on the subject.

Step 2: Execute the hdparm -Tt command on the hard drive to begin the test.

sudo hdparm -Tt /dev/sda

When the test is complete, you’ll see the test results on the screen. 

The post Linux: test disk speed [Guide] appeared first on AddictiveTips.

Ubuntu: check kernel version [Guide]

If you use Ubuntu, at some point you may be curious what your kernel version is. Unfortunately, in Ubuntu, the developers don’t tell you how to check the kernel info. In this guide, we’ll show you 4 ways you can check your kernel version on Ubuntu. 

Ubuntu: check kernel version

Method 1 – Uname 

The best and quickest way to check the kernel version on Ubuntu is with the uname command. This tool can tell you your exact kernel release version, and a lot of other valuable information as well.

To use the uname command, you must open up a terminal window on the Ubuntu desktop. To open up a terminal window on the desktop press Ctrl + Alt + T on the keyboard. Alternatively, search for “Terminal” in the app menu and open it that way. 

Once the terminal window is open, execute the uname -a command. This command will print out all system information, including your kernel version information.

uname -a

If you’d prefer to just get the kernel information, instead of the kernel information, plus OS release name, and other information, you can replace the uname -a command for the uname -srm command. This command will only show you Ubuntu’s kernel version.

uname -srm

Save output

Want to save the output of uname -srm to a text file for later? Here’s how to do it. Re-run the uname -srm command but with the symbol on the end, and point it to a new text file.

uname -srm > ~/kernel-info.txt

When the command is complete, you can take a look at the text file at any time for information on the Ubuntu kernel by making use of the cat command below.

Note: you can also open up the “kernel-info.txt” in your favorite text editor to view the information instead of cat.

cat ~/kernel-info.txt

Method 2 – Hostnamectl

Another way to find the Ubuntu kernel version is with the Hostnamectltool. It’s a systemd tool that allows users to find information about the system. It can be used to view your Ubuntu kernel version. Here’s how.

To view your kernel information, execute the hostnamectl status command. By executing this command, the Hostnamectl program will show you a complete readout of the hostname of your system, Operating System name, kernel info, etc.

hostnamectl status

Look through the Hostnamectl output for the “Kernel” section. Once you’ve found it, the information next to it is the Ubuntu kernel information.

Don’t want to look at other information in Hostnamectl aside from the kernel version info? Use the grep command to filter out your kernel info.

hostnamectl status | grep "Kernel:"

Save output

If you’d like to save the Hostnamectl output to a text file to read later, you can do it by redirecting the command to a text file. To save the entire Hostnamectl output to a text file, execute the command below.

hostnamectl status > ~/kernel-info.txt

Alternatively, if you’d like to save just the kernel section of the output, you can do so by entering the following command.

hostnamectl status | grep "Kernel:" > ~/kernel-info.txt

To view the kernel-info.txt file, execute the cat command below. Or, open up “kernel-info.txt” in your favorite GUI text editor.

cat ~/kernel-info.txt

Method 3 – /proc/version

The third way of viewing kernel information on Ubuntu is with the /proc/version file. This file has tons of info to look at. To take a look at it, you’ll need to use the cat command below.

cat /proc/version

In the cat output, locate “Linux version.” Next to the “Linux version” section of the text file is your Ubuntu kernel version. 

Save output

To save the output of /proc/version to a text file for later, redirect the cat /proc/version command to a text file in your home folder.

cat /proc/version > ~/kernel-info.txt

To read the text file, use the cat command on “kernel-info.txt”, or open up “kernel-info.txt” in your favorite GUI text editor.

Method 4 – Neofetch

The fourth way of viewing kernel information on Ubuntu Linux is with the Neofetch system information tool. It’s a powerful tool that scans your Ubuntu system for tons of information and prints it out in a nice output, next to your OS logo. 

To get started with Neofetch, you must install the program on your computer. To install it, open up a terminal window by pressing Ctrl + Alt + T on the keyboard. Then, enter the command below.

sudo apt install neofetch

Once the Neofetch application is installed on your Ubuntu PC, execute the neofetch command in a terminal. Keep in mind that the output may take a couple of seconds, as the program needs to collect the information.

neofetch

After executing the neofetch command, look through the output for the “Kernel” section. Next to “Kernel,” you’ll see your Ubuntu kernel version. 

Save output

If you’d like to save the Neofetch terminal output to a text file to read for later, generate the output but this time, redirect it to a text file rather than allowing it to print on the screen.

neofetch > ~/kernel-info.txt

You can view the Neofetch output in the “kernel-info.txt” text file at any time by executing the cat command below, or, by opening it up in your favorite text editor.

cat ~/kernel-info.txt

The post Ubuntu: check kernel version [Guide] appeared first on AddictiveTips.

How to install the Neo-to GTK theme on Linux

Neo-to is a fancy, neon-like GTK theme for the Linux desktop. It’s charming to look at and is sure to spruce up your bland Linux desktop! Here’s how to install it on your Linux computer!

Neo-to GTK theme on Linux

Downloading Neo-to 

The Neo-to GTK theme is available to all Linux users for download via the Gnome-look.org theme website. There are several different variations of the Neo-to GTK theme to download.

To download any of the theme versions, start by heading over to the Neo-to Gnome-look page. Once on the page, click on the “Files” tab to view the various theme packs available for download.

Inside the “Files” area, click on the blue download icon in the “DL” column to start the download. The download of the Neo-to theme will not take long. When it is complete, move on to the next section of the guide. 

Extracting Neo-to 

The Neo-to GTK theme is distributed to Linux users in the form of a TarXZ archive. This archive needs to be extracted before the theme can be installed, as Linux themes can’t be activated in an archive format.

To start the extraction, open up a terminal window on the Linux desktop. To open up a terminal window, press the Ctrl + Alt + T keyboard combination. Then, use the CD command to move into the “Downloads” directory where the theme file was downloaded.

cd ~/Downloads

Once inside the “Downloads” folder, the extraction can begin. Using the tar command, extract the No-to theme files to your computer.

If you’ve downloaded the “neo-to.tar.xz” theme pack, you can easily extract it with the following command.

tar xvf neo-to.tar.xz

Did you grab the “neo-to-white.tar.xz” theme to use on your Linux PC? Extract it with the following command. 

tar xvf neo-to-white.tar.xz

Want to install the “neo-to-lighter-headerbar.tar.xz” theme pack on your computer? If so, you’ll need to enter the command below.

tar xvf neo-to-lighter-headerbar.tar.xz

When your Neo-to theme packs are fully extracted, the installation can begin. Move on to the next section of the guide to get Neo-to set up on your Linux PC!

Installing Neo-to 

There are two ways to install the Neo-to GTK theme on Linux. The first way to install the theme is known as single-user, allowing only the person who installs the theme to have access to it. The second way of installing Neo-to is known as system-wide, which enables any Linux user to access the theme once installed.

To start the installation of Neo-to on Linux, open up a terminal window. Once the terminal window is open, follow along with the installation method down below that you prefer.

Single-user

To install Neo-to as a single-user, start by using the mkdir command to create a new theme folder in your home directory. This theme folder will enable your user account to access the Neo-to GTK theme.

mkdir -p ~/.themes

After creating a new ~/.themes folder, you’ll be able to install themes locally on your computer so that only your Linux user account can access them. Next, use the CD command to move into the “Downloads” directory. The “Downloads” directory is where the Neo-to theme package was extracted previously. 

cd ~/Downloads/

Inside of the “Downloads” directory, use the mv command to move the Neo-to theme files into your newly created ~/.themes directory. 

mv  neo-to*/ ~/.themes/

Once everything is moved, the Neo-to theme file is installed in single-user mode. Confirm that the installation is successful by running the ls command below.

ls ~/.themes

System-wide

To install Neo-to in system-wide mode, start by accessing the “Downloads” directory to which the theme pack was extracted previously. You can access this folder by making use of the CD command below.

cd ~/Downloads

Inside of the “Downloads” directory, use the sudo -s command to elevate your terminal session to “root” without leaving the directory you’re in.

sudo -s

Once the terminal session has root access, the installation of Neo-to in system-wide mode can begin. Using the mv command, install Neo-to to the /usr/share/themes/ directory.

mv neo-to*/ /usr/share/themes/

Once the installation is complete, Neo-to is set up on your Linux PC in system-wide mode. To verify that the installation was successful, run the ls command below.

ls /usr/share/themes/

Activating Neo-to 

The Neo-to GTK theme is installed on your Linux PC, but installing it doesn’t activate the theme. To start using the Neo-to GTK theme on your Linux PC as your default GTK theme, you will need to change your default GTK theme to “Neo-to.”

Unsure about how to change the default GTK theme on your Linux PC? Check out the list of links below and choose the desktop environment you use on Linux to learn how to change GTK themes!

The post How to install the Neo-to GTK theme on Linux appeared first on AddictiveTips.