Linux Guides, Tips and Tutorials | LinuxScrew https://www.linuxscrew.com LinuxScrew is a Linux resource that contains many useful guides on Linux, programming, networking, and more. Wed, 20 Jan 2021 17:28:34 +0000 en-US hourly 1 https://wordpress.org/?v=5.5.3 https://www.linuxscrew.com/wp-content/uploads/2020/10/favicon-7-48x48.png Linux Guides, Tips and Tutorials | LinuxScrew https://www.linuxscrew.com 32 32 The Bash Profile and How to Use It https://www.linuxscrew.com/bash-profile https://www.linuxscrew.com/bash-profile#respond Mon, 25 Jan 2021 08:33:19 +0000 https://www.linuxscrew.com/?p=6132 If you’re frequently interacting with Linux via the Bash shell, you’ll eventually want to customize it a bit – perhaps adding your own shortcuts, or setting up the environment to your liking, or even just adding some decorative personalization. This is what the Bash profile is for. It’s stored in your home directory and can… Read More »The Bash Profile and How to Use It

View the original article from LinuxScrew here: The Bash Profile and How to Use It

]]>
If you’re frequently interacting with Linux via the Bash shell, you’ll eventually want to customize it a bit – perhaps adding your own shortcuts, or setting up the environment to your liking, or even just adding some decorative personalization.

This is what the Bash profile is for. It’s stored in your home directory and can be edited to set things up just the way you want each time you log in.

Editing your Bash Profile

To edit your bash profile, open it with the nano text editor by running:

nano ~/.bash_profile

If you want to back up your current profile, make a copy of it by running:

cp .bash_profile .bash_profile.bak

If the ~/.bash_profile file does not exist, the ~/.profile file will be read instead. This is the default on the Ubuntu Linux distribution.

If you want to copy the contents of the default ~/.profile file to a new ~/.bash_profile for editing, you can make a copy:

cp ~/.profile ~/.bash_profile

Note that ~/ in the Linux shell is a shortcut to the current user’s home directory.

Examples

Here are some things you can do with your Bash profile to get started.

Change the Shell Prompt

Usually, your shell prompt will look something like this:

linuxscrew@linuxscrew-host:~$

…a combination of your name, hostname, and the current working directory. This can be changed by modifying the .bash_profile file and adding the following line:

export PS1="?"

This will change the prompt to be a locomotive emoji. This on its own isn’t all that useful, but other things can be added.

This will change the prompt to the current logged in user, followed by the locomotive:

export PS1="\u ?"

You can add your own text, characters, and values. For a list of all of the built-in variables you can use (date, username, current directory, etc.), check out:

https://www.gnu.org/savannah-checkouts/gnu/bash/manual/bash.html#Controlling-the-Prompt

Change The Text and Background Colours!

Building on the above example, we can add some color. This example will make the prompt text red with a blue background:

export PS1="\e[44;31m\u ? \e[0m "

…and this will add that the train emoji should blink:

export PS1="\e[44;31m\u \e[5m? \e[0m "

Note that:

  • \e[ : Starts formatting scheme
  • 44;31 : Background color and text color, respectively
  • \e[5m makes the train icon blink
  • \e[m : Stops the formatting scheme by resetting all attributes

There are a bunch of colors and formatting options you can use. This isn’t an exhaustive list, but it provides a few useful examples:

Code Meaning Example
1 Bolded “\e[1mBolded”
2 Dimmed “\e[2mDimmed”
3 Underlined “\e[4mUnderlined”
4 Blinking “\e[5mBlinking”
5 Inverted Colour “\e[7mInverted”

The available colors are numeric values that can be paired into background/text combinations. They will vary depending on your environment – this command will output the available combinations on your system:

for x in {0..8}; do for i in {30..37}; do for a in {40..47}; do echo -ne "\e[$x;$i;$a""m\\\e[$x;$i;$a""m\e[0;37;40m "; done; echo; done; done; echo ""

Add Your Own Shortcuts / Functions

If you find yourself typing the same series of commands constantly, you can define a shortcut function in your bash profile. Adding the following code to the ~/.bash_profile file will define a new function that lists the directory, then exclaims how nice it is:

myShortcut(){
        ls -la
        echo "Look at that nice directory!"
}

To run it, you’d simply now need to run:

myShortcut

Into the shell and the contents of that function will be executed.

Applying the changes

To apply the changes to your profile and see them without restarting or closing the terminal, just run:

source ~/.bash_profile

What About Zsh?

We recently explored the zsh shell.

Zsh also has a profile file that serves the same purpose as the bash profile, located at:

~/.zprofile

It, too, can be edited just like the Bash profile, but with Zsh specific functions. Give it a go!

 

View the original article from LinuxScrew here: The Bash Profile and How to Use It

]]>
https://www.linuxscrew.com/bash-profile/feed 0
Python range Function – How to Use It [With Examples] https://www.linuxscrew.com/python-range https://www.linuxscrew.com/python-range#respond Sat, 23 Jan 2021 07:04:25 +0000 https://www.linuxscrew.com/?p=6151 The Python range() function returns an immutable sequence of integers between a given start and endpoint, incrementing by a given amount. Python range Syntax Here’s the syntax for the Python range() function: range(start, stop, step) Note that: start is the integer to start incrementing from – it will be included in the range If it is not supplied, it will be… Read More »Python range Function – How to Use It [With Examples]

View the original article from LinuxScrew here: Python range Function – How to Use It [With Examples]

]]>
The Python range() function returns an immutable sequence of integers between a given start and endpoint, incrementing by a given amount.

Python range Syntax

Here’s the syntax for the Python range() function:

range(start, stop, step)

Note that:

  • start is the integer to start incrementing from – it will be included in the range
    • If it is not supplied, it will be assumed to be 0
  • stop is the integer to end the range at – it will NOT be included in the range – the range will end before the stop value
    • If start and stop are the same, an empty range will be returned
  • step is the integer amount each value in the range is incremented by
    • Defaults to 1 if not specified
  • Only integers are supported for all values
  • The range() function will return an immutable sequence of integer values
    • Immutable means that the contents of the sequence cannot be changed

Examples

Here are some examples for using the range() function:

Creating and Looping Over a Range of Integers from 0 to 4

myRange = range(4)
for myNum in myRange:
    print(myNum)

Note that: – The result of the range() function has been assigned to the variable myRange – Each value in the generated range is assigned to the loop variable myNum and printed using a python for statement – As no start or step have been specified for the range() function, they have defaulted to 0 and 1 respectively

The above example will output:

0
1
2
3

Creating and Looping Over a Range of Integers from 10 to 30, in Increments of 5

myRange = range(10, 30, 5)
for myNum in myRange:
    print(myNum)

Note that:

  • We have supplied startstop and step values to the range() function

The above example will output:

10
15
20
25

Creating and Looping Over a Range of Integers from 50 to 30, Decrementing by 2

Negative integers can also be supplied. Using a negative step will decrement instead of incrementing when generating the range values.

myRange = range(50, 40, -2)
for myNum in myRange:
    print(myNum)

The above example will output:

50
48
46
44
42

Conclusion

Creating a range of numbers can be useful for looping over a series of known values or an array of a known size. Looping over a range can be used to perform actions on each value in the range, simplifying making calculations.

For more information on Python, Python functions and behavior, and projects to get you started, check out our other Python articles!

View the original article from LinuxScrew here: Python range Function – How to Use It [With Examples]

]]>
https://www.linuxscrew.com/python-range/feed 0
How to Make a PHP Redirect to a Different Page [Quick & Easy] https://www.linuxscrew.com/php-redirect https://www.linuxscrew.com/php-redirect#respond Fri, 22 Jan 2021 05:40:25 +0000 https://www.linuxscrew.com/?p=6139 Being able to redirect the user to a different page in PHP can be useful if you’ve moved a page to a different location or want to send the user elsewhere – directing them to an access denied or error page instead of the page they were trying to access. This can be easily done… Read More »How to Make a PHP Redirect to a Different Page [Quick & Easy]

View the original article from LinuxScrew here: How to Make a PHP Redirect to a Different Page [Quick & Easy]

]]>
Being able to redirect the user to a different page in PHP can be useful if you’ve moved a page to a different location or want to send the user elsewhere – directing them to an access denied or error page instead of the page they were trying to access.

This can be easily done using the PHP header() function.

Using the PHP header() Function to Redirect to a Different Page

To redirect the user to a different page, simply include the following PHP code:

header("Location: https://linuxscrew.com/");
die();

There are some things to keep an eye out for when doing this:

  • There can be no output prior to calling the header() function
    • header() MUST be called before any content is outputted to the page, be it HTML, text, blank lines, or other output from PHP
  • It is best to run die() after header() has been called to make sure no further content is rendered or no further code is partially executed, especially if you are redirecting away from sensitive content
  • The URL supplied can be relative, or link to an external site (In this example, it redirects to this very website)

For full details of what you can do with the header() function, check the official documentation:

https://www.php.net/manual/en/function.header.php

For more short and sweet PHP articles, check out our PHP category.

View the original article from LinuxScrew here: How to Make a PHP Redirect to a Different Page [Quick & Easy]

]]>
https://www.linuxscrew.com/php-redirect/feed 0
Find Command in Linux [With Useful Examples] https://www.linuxscrew.com/linux-find-command https://www.linuxscrew.com/linux-find-command#respond Thu, 21 Jan 2021 03:14:13 +0000 https://www.linuxscrew.com/?p=6136 The find command in the Linux shell allows you to search for files in the filesystem. It can find files by name, user permissions, and size. The find command can also perform actions on the files which are found. Find Command Syntax The syntax for the find command is as follows: find [OPTIONS] [PATH] [EXPRESSION] Where: [OPTIONS] are options from… Read More »Find Command in Linux [With Useful Examples]

View the original article from LinuxScrew here: Find Command in Linux [With Useful Examples]

]]>
The find command in the Linux shell allows you to search for files in the filesystem. It can find files by name, user permissions, and size. The find command can also perform actions on the files which are found.

Find Command Syntax

The syntax for the find command is as follows:

find [OPTIONS] [PATH] [EXPRESSION]

Where:

  • [OPTIONS] are options from the below table to determine the find behavior
  • [PATH] is the starting point for the search
  • [EXPRESSION] defines the tests to find matching files and any action that should be taken on the found files

Options

Here are the commonly used OPTIONS for the find command, adapted from the manual:

-P Never follow symbolic links. This is the default behavior
-L Follow symbolic links. When find examines or prints information about files, the information used shall be taken from the properties of the file to which the link points, not from the link itself
-H Do not follow symbolic links, except while processing the command line arguments

Expressions

These some common statements from the find manual that can be used to build the EXPRESSION, which tests for matching files and optionally performs actions on them:

Tests (Search conditions)
-empty Find empty files
-executable Matches files that are executable and searchable directories
-group name File belongs to group with name
-mtime n Files data was last modified less than, more than, or exactly n*24 hours ago
-name pattern Base of file name (the path with the leading directories removed) matches pattern pattern
-path pattern File path matches pattern pattern
-readable Matches files which are readable by the current user
-size n File uses less than, more than or exactly n units of space, rounding up (See below table for available units)
-type c File is of type c (See below table for values for c)
-user name File is owned by name user
Actions
-print Outputs the name of the file (Default action)
-prune Ff the file is a directory, do not descend into it
-depth Process each directory’s contents before the directory itself
-delete Delete matched files. The -delete action also acts like an option (since it implies -depth)
-exec command Execute command
-execdir command Like -exec, but the specified command is run from the subdirectory containing the matched file
-ok command Like -exec but ask the user first.
-okdir command Like -execdir but ask the user first in the same way as for -ok.
-printf format Print file details in format

Operators in Expressions

Operators can be used to chain together items in an expression:

-o OR
-a AND (Default operator between expressions when no operator supplied

For the full list of options and expressions for finding files, you can run the following:

man find

Find Command Examples

Options, expressions, and actions can be combined to create simple find operations to list matching files or complex operations that can find files by complex conditions and perform an action. See below for examples:

Find Files by File Name

This example finds all files named myfile in the directory /home/screw:

find /home/screw -name myfile

Search By Type

The above command will return all matching files – including directories, links, and devices – everything in the file system.

The -type f expression limits the search to files only. To search for files named myfile:

find /home/screw  -type f -name myfile

Or, search only for directories:

find /home/screw  -type d -name myfile

The available types are:

b Block (buffered) special
c Character (unbuffered) special
d Directory
p Named pipe (FIFO)
f Regular file
l Symbolic link; this is never true if the -L option or the -follow option is in effect, unless the symbolic link is broken
s Socket

Case Sensitivity

The -name option is case sensitive – to search without case sensitivity use -iname:

find /home/screw -iname mYFiLe

Find Files By Extension Using Wildcards & Regex

You can use wildcards (*) in file names, which allows you to search by file extension:

find -L /home/screw -name '*.pdf'

The above will search for all files with the .pdf extension. The quoted search pattern can contain regex.

Omitting Files By Name Or Extension

The -not operator can be used to omit files by name or pattern, returning all results that do not match:

find /home/screw -type f -not -name '*.pdf'

Omit Entire Directories from Results

Use the -prune option to omit matching paths and their contents. The below example will omit the /home/screw/junk directory from the results:

find /home/screw -path /home/screw/junk -prune -o -print

Search for Files by Size

This example searches for all files less than 500 Kilobytes:

find /home/screw -type f -size -500k

This one will find files between 100 and 200 Kilobytes by passing two size conditions:

find /home/screw -type f -size +100k -size -200k

The available units for searching by size are:

b 512-byte blocks (this is the default if no suffix is used)
c Bytes
w Two-byte words
k Kibibytes (KiB, units of 1024 bytes)
M Mebibytes (MiB, units of 1024 * 1024 = 1048576 bytes)
G Gibibytes (GiB, units of 1024 * 1024 * 1024 = 1073741824 bytes)

Modification or Access Date

The following example finds all .txt files modified in the last 14 days:

find /home/screw -name '*.txt' -mtime 14

To search by last access instead of modification date, use the -atime option instead of -mtime.

You can also add a sign (+ or ) to search for files modified greater or less than the given interval – this example will return files that were modified greater than 14 days ago.

find /home/screw -name '*.txt' -mtime +14

To use minutes instead of days as the unit of time, you can substitute -mmin -amin instead of -mtime and -atime.

As usual, there are a lot more options to mix and match, all available in the manual, available by running:

man find

Owner User/Group

To find all files owned by root in the /home/screw directory, run:

find /home/screw -user root

Permissions

The following command will find all files with global read/write permissions:

find /home/screw -perm 777

See our article on the chmod command and what it does.

Combination

Any combination of search expressions can be used. If no operator is included between them, it will be assumed that both conditions must be met for a file to be a match (i.e., the AND operator is the default).

This example searches for all text files created in the last 14 days less than 500kb:

find /home/screw -name '*.txt' -mtime 14 -type f -size -500k

Actions on Found Files

By default, the find command will print the find operation results (the same as calling the -print action).

find /home/screw -name myfile -print

Customizing the Results Format

You can customize the output of the results to include additional information about any found files. This example prints the file name, followed by a dash, followed by the size of the file in bytes:

find /home/screw -name '*.txt' -printf '%f - %s bytes'

Many variables can be used to customize the output, from the file size to individual date fields for the file modification and access times – check out the manual for the full list.

Writing Results to File

Redirect the results of your find operation to a text file:

find /home/screw -name myfile > find_results.txt

Deleting

The -delete action will delete matching files (without confirmation, so be careful!):

find /home/screw -name '*.junk' -delete

Executing commands with -exec / *-execdir *

You can execute any shell command against each find result using the -exec action:

find /home/screw -name '*.txt' -exec ls -la {} ';'

-exec will execute the command from the current working directory. To execute the command from the location of the found file, use -execdir instead:

find /home/screw -name '*.txt' -execdir ls -la {} ';'

In the above two examples, ls -la is run against each result. The curly braces {} will be replaced with the find command results, and the ‘;’ terminates the command line arguments for the ls command so that find knows where they end.

Prompting for Confirmation with -ok / -okdir

The -ok action works the same as the -exec action, but it asks you before running the given command. This is useful if you want to delete files, but be asked before each file is deleted:

find /home/screw -name '*.txt' -ok rm {} ';'

-okdir also prompts but executes the command from the location of the found file:

find /home/screw -name '*.txt' -okdir rm {} ';'

 

View the original article from LinuxScrew here: Find Command in Linux [With Useful Examples]

]]>
https://www.linuxscrew.com/linux-find-command/feed 0
How to Update Kali Linux [Quick Guide] https://www.linuxscrew.com/how-to-update-kali-linux https://www.linuxscrew.com/how-to-update-kali-linux#respond Wed, 20 Jan 2021 09:19:33 +0000 https://www.linuxscrew.com/?p=6073 So you’ve followed our guide to Installing Kali Linux, and you want to make sure all of your software is up to date. Follow these instructions to make sure you’re on the latest version. Updating Kali Linux from the Terminal Check that the /etc/apt/sources.list file is populated: cat /etc/apt/sources.list You should see something like: deb http://http.kali.org/kali kali-rolling… Read More »How to Update Kali Linux [Quick Guide]

View the original article from LinuxScrew here: How to Update Kali Linux [Quick Guide]

]]>
So you’ve followed our guide to Installing Kali Linux, and you want to make sure all of your software is up to date. Follow these instructions to make sure you’re on the latest version.

Updating Kali Linux from the Terminal

Check that the /etc/apt/sources.list file is populated:

cat /etc/apt/sources.list

You should see something like:

deb http://http.kali.org/kali kali-rolling main contrib non-free
deb-src http://http.kali.org/kali kali-rolling main contrib non-free

If you don’t see the above, you may need to add those lines to the file.

If everything looks good in your sources list, you can run the following to update:

sudo apt update

Followed by:

sudo apt full-upgrade -y

Short and sweet!

View the original article from LinuxScrew here: How to Update Kali Linux [Quick Guide]

]]>
https://www.linuxscrew.com/how-to-update-kali-linux/feed 0
How to Install Kali Linux [Easy Guide] https://www.linuxscrew.com/how-to-install-kali-linux https://www.linuxscrew.com/how-to-install-kali-linux#respond Wed, 20 Jan 2021 09:19:33 +0000 https://www.linuxscrew.com/?p=6042 Kali Linux is a Linux distribution built from the ground up for Penetration Testing and Security Auditing. This step-by-step tutorial explains how to install it quickly and easily. What does that mean? It means Kali Linux is for trying to break into (your own) networks and computers to check for vulnerabilities. It contains hundreds of tools for testing for… Read More »How to Install Kali Linux [Easy Guide]

View the original article from LinuxScrew here: How to Install Kali Linux [Easy Guide]

]]>
Kali Linux is a Linux distribution built from the ground up for Penetration Testing and Security Auditing. This step-by-step tutorial explains how to install it quickly and easily.

What does that mean? It means Kali Linux is for trying to break into (your own) networks and computers to check for vulnerabilities.

It contains hundreds of tools for testing for security vulnerabilities and tools for computer forensics, reverse engineering, and security research.

Kali Linux can be run from a CD or USB stick or installed like any other Linux distribution – here’s how.

Downloading the Kali Linux Install Image

Download the appropriate image for your system (Kali Linux 64-Bit (Installer) is compatible with most modern PCs) from

https://www.kali.org/downloads/

 

install kali 1

Writing the Install Image to Disk or USB Stick

Windows 10 DVD Installation

If you’ve got a DVD burner on your computer, insert a blank disc, and right-click on the downloaded Kali Linux ISO image, and select ‘Burn disk image’ – easy!

Ubuntu DVD Installation

If you’re on Ubuntu and are burning to DVD, right-click on the downloaded ISO Image and select ‘Write to Disk’ – also easy!

Windows 10 USB Stick Installation with Rufus

If you’re using a USB stick (which is at least 4GB) to install Kali Linux, download Rufus – a neat tool for writing ISO images to bootable USB sticks:

https://rufus.ie/

Open Rufus up and make the following selections:

  • Set Device to the USB stick you wish to write the ISO image to
    • Watch out! It’ll delete everything on the USB stick, so make sure you’re sure and that you’ve selected the right device
  • Set Disk or ISO Image to the Kali Linux ISO file
  • Leave everything else as is

Now click START and wait around a bit. Your bootable Kali Linux Install USB is now ready!

Ubuntu USB Stick Installation with Startup Disk Creator

Ubuntu has a built-in tool for writing a bootable Linux ISO image to a USB stick – the Startup Disk Creator. To set up your USB stick:

  • Insert your USB stick
  • Search Ubuntu’s Application launcher for ‘Startup Disk Creator’ and launch the application
  • Select the Kali Linux ISO which was downloaded in the previous step as the source disk
  • Select your USB stick as the disk to use
  • Confirm your USB device – Make sure you’re certain of your selected USB device, as all data on it will be wiped!
  • Wait a bit – and your bootable USB stick is ready!

Installing Kali Linux on your PC

Insert the Kali Linux disc or USB stick from the previous step into the computer you wish to install Kali Linux on to.

WARNING: Depending on your selections during the installation process, the entire contents of the computer you are installing Ubuntu on may be wiped – so make sure you’re paying attention to what you’re doing (and always have backups)

Now, power up or reboot the computer. You will need to make sure it boots from your installation media.

This may happen automatically. If it does not, reboot again and watch for a prompt to select which device to boot from.

It usually looks something like this:

Press DEL to interrupt startup and select boot device.

If you don’t see one, you may have to consult the user manual for your computer to find out which key to press to interrupt boot and select the boot device (it’s usually DELETEF2, or F12, depending on your manufacturer).

install kali 2

Once you’ve successfully booted the installation media, you’ll see the above screen. Select Graphical Install.

install kali 3

install kali 4

install kali 5

Select your LanguageLocation, and Keyboard Layout. Once these choices are made, the setup process will run some checks and then proceed.

install kali 6

install kali 7

Name your computer something sensible. If you’re going to be using Kali Linux for it’s intended purpose, an ambiguous name is probably for the best.

install kali 8

install kali 9

install kali 10

Set your username and password to something secure!

install kali 11

Select your timezone and continue to set up your hard disk.

install kali 12

Guided – use entire disk is the most straight-forward option – but be aware that it will overwrite the current contents of the disk you are installing to – make sure you’ve backed up!

install kali 13

Select the hard disk you wish to install Kali Linux to.

install kali 14

All files in one partition is sufficient for normal usage (and new users, as it states).

install kali 15

Finally, select Finish partitioning and write changes to disk and click Continue to overwrite your disk and install Kali Linux.

install kali 16

Confirm your choice again by selecting Yes and clicking Continue.

install kali 17

Wait around a bit – it may take a few minutes for your disks to be partitioned and formatted and the base system to be installed.

install kali 18

Once the base system is installed, you’ll be asked what additional software packages should be installed – the defaults are a good start, so leave things as they are and continue.

install kali 19

Again, the installation of packages may take a few minutes (or more).

install kali 20

For your system to boot, the GRUB bootloader will need to be installed.

Select Yes to install GRUB on your primary drive and Continue.

install kali 21

Select your hard disk to confirm that you wish to install the GRUB bootloader on it.

install kali 22

install kali 23

We’re done! Remove the installation disc or USB stick and Continue to reboot.

install kali 24

Once your PC boots, the GRUB bootloader will now be shown and will boot Kali Linux after a few seconds.

install kali 25

Log in using the credentials you supplied earlier.

install kali 26

The Kali Linux desktop!

install kali 27

Check out the extensive Kali Linux documentation for instruction on using all of the security-related packages it includes.

Conclusion

Kali Linux is now installed and ready to test your network’s limits! If you’d like to learn how to update Kali Linux, then be sure to check out our other guide.

View the original article from LinuxScrew here: How to Install Kali Linux [Easy Guide]

]]>
https://www.linuxscrew.com/how-to-install-kali-linux/feed 0
How to Install Anaconda (Python & R) on Ubuntu https://www.linuxscrew.com/install-anaconda-ubuntu https://www.linuxscrew.com/install-anaconda-ubuntu#respond Tue, 19 Jan 2021 09:19:26 +0000 https://www.linuxscrew.com/?p=6032 We like Python. Anaconda is a popular distribution of Python and the R programming languages, which includes package management and deployment tools, with hundreds of packages pre-installed. Anaconda is aimed at data scientists and people working with machine learning, but it’s useful for anyone. It has a quick and easy install process for Ubuntu, so… Read More »How to Install Anaconda (Python & R) on Ubuntu

View the original article from LinuxScrew here: How to Install Anaconda (Python & R) on Ubuntu

]]>
We like Python. Anaconda is a popular distribution of Python and the R programming languages, which includes package management and deployment tools, with hundreds of packages pre-installed.

Anaconda is aimed at data scientists and people working with machine learning, but it’s useful for anyone. It has a quick and easy install process for Ubuntu, so here’s how to get up and running!

Download the Anaconda installer

Anaconda has various additions, and we want the Open Source (free!) individual edition, available from:

https://www.anaconda.com/products/individual

Scroll down and download the 64-Bit (x86) Installer into its own directory, or use the shell commands below:

mkdir ~/anaconda-installer
cd ~/anaconda-installer
wget  https://repo.anaconda.com/archive/Anaconda3-2020.11-Linux-x86_64.sh

The download may take a few minutes.

Run the Anaconda Installer

Now that the installer has downloaded, run it:

sh  Anaconda3-2020.11-Linux-x86_64.sh

install anaconda ubuntu 1

Press ENTER to read the license agreement (keep tapping enter to keep scrolling through it) and type ‘yes’ when prompted to accept and continue.

install anaconda ubuntu 2

Press ENTER to accept the default install directory (or change it first if you’d prefer it be installed somewhere else).

install anaconda ubuntu 3

When asked whether to run conda init, enter ‘yes.’

This will update your

.bashrc

file to make the conda command accessible on your PATH (this means Anaconda commands will be available in your shell no matter which folder you’re currently navigating).

For these changes to take effect – close and reopen your terminal, reboot, or run:

. ~/.bashrc

You can now delete the directory we downloaded the installation files to;

rm -rf ~/anaconda-installer

Checking the Installation

To check everything is installed and accessible, run:

conda --help

If everything is working, you should see some helpful text.

If You’re on a System with a GUI

If you are using a GUI (i.e., a computer with a desktop interface, rather than running on a server or accessing a computer remotely via SSH), you can try out the Anaconda Navigator – a graphical tool for managing Anaconda.

Simply run:

anaconda-navigator

…in your terminal.

install anaconda ubuntu 4

Updating Anaconda

To update all of your Anaconda packages, run:

conda update --all

… and press Y to accept the changes.

install anaconda ubuntu 6

Completely Uninstalling Anaconda

To completely uninstall Anaconda, first install the anaconda-clean package for Anaconda to aid in the cleanup of all Anaconda files and configuration:

conda install anaconda-clean

To delete all files and directories created by Anaconda, without being prompted to confirm each file deletion, run:

anaconda-clean --yes

anaconda-clean will remove all files at their current locations and leave a backup copy of them in the directory ~/.anaconda_backup.

This backup directory, and the directory containing the Anaconda program files, can now be removed:

rm -rf ~/anaconda3 ~/.anaconda_backup

Note: This process will not delete the AnacondaProjects directory.

During the setup process, conda init will have made some changes to your ~/.bashrc file, which can be undone by removing the lines from that file manually using the nano text editor:

nano ~/.bashrc

Delete the Anaconda lines highlighted below:

install anaconda ubuntu 7

View the original article from LinuxScrew here: How to Install Anaconda (Python & R) on Ubuntu

]]>
https://www.linuxscrew.com/install-anaconda-ubuntu/feed 0
How to Use The awk Command in Linux [With Examples] https://www.linuxscrew.com/awk-command https://www.linuxscrew.com/awk-command#respond Mon, 18 Jan 2021 09:19:33 +0000 https://www.linuxscrew.com/?p=6027 This guide shows you how to use the awk command in Linux, with plenty of useful everyday examples. AWK is a tool and language for searching and manipulating text available for the Linux Operating System. The awk command and the associated scripting language search files for text defined by a pattern and perform a specific action on the text which… Read More »How to Use The awk Command in Linux [With Examples]

View the original article from LinuxScrew here: How to Use The awk Command in Linux [With Examples]

]]>
This guide shows you how to use the awk command in Linux, with plenty of useful everyday examples.

AWK is a tool and language for searching and manipulating text available for the Linux Operating System.

The awk command and the associated scripting language search files for text defined by a pattern and perform a specific action on the text which matches the pattern.

awk is a useful tool for extracting data and building reports from large text files or large numbers of text files – for example processing logs, or the output of data-recording devices like temperature probes, which have collected a lot of data over a period of time. It can also be used on the output from database queries.

There’s no need to install awk; it should already be available on your Linux System.

awk Syntax

The syntax for using the awk command in the terminal is as follows:

awk [PROGRAM] [INPUT FILES]

Note that:

  • [PROGRAM] is the search pattern and actions to take – it’s the program you want awk to run on the supplied files
    • It can also be supplied as a text file rather than inline by using the -f option
  • [INPUT FILES] are the files you wish awk to work on – it can be several files separated by a space, or the path to a directory, or a pattern of files to match
    • If no input files are specified, awk will work on the piped output from another command

awk Options

The following options can be supplied to the awk command:

-f program-file Program text is read from file instead of from the command-line. Multiple -f options are accepted.
-F value Sets the field separator, FS, to value.
-v var=value Assigns value to program variable var.

For more implementation-specific options for your version of awk, you can check the manual by running:

man awk

Program Actions & Variables

The program you supply to awk will determine what it does to the text files you supply to it. An awk program takes the following format:

CONDITION { ACTION }
CONDITION { ACTION }
...

Where CONDITION is the pattern of text to match and ACTION is the action to take on the matched text. You can have as many conditions and actions as you please.

Actions

The actions supplied are commands that can include calculations, variables, and calling functions. Some built-in functions are implementation-specific, so it’s best to check your manual for these.

Records

awk generally treats each new line in a text file as a record unless otherwise specified via OPTIONS.

Fields

awk will use whitespace (spaces, tabs) to denote the fields in a record unless otherwise specified via OPTIONS.

Variables

awk has many built-in variables that you can use without having to define them yourself, which cover some common scenarios:

Variable Meaning
$0 Represents the entire record
$1, $2, $3 … Field variables – hold the text/values for the individual text fields in a record
NR / Number of Records Current count of the number of input records read so far from all files
FNR / File Number of Records Current count of the number of input records read so far in the current file – Automatically reset to zero each time a new file is started
NF / Number of Fields Number of fields in the current input record – The last field in a record can be referenced using $NF, the 2nd to last field using $(NF-1) and so on
FILENAME Name of the current input file
FS / Field Separator The character(s) used to separate the fields in a record. By default includes any space and tab characters
RS / Record Separator The character(s) used to separate the records in a file. New line by default
OFS / Output Field Separator Character(s) used to separate fields in Awk output. The default is a single space
ORS / Output Record Separator Character(s) used to separate fields in Awk output. The default is a new line
OFMT / Output ForMaT Format for numeric output – Default format is “%.6g”

awk Usage Examples

For these examples, we will work on a single text file called flowers.txt, which contains the following text:

red rose
yellow daffodil
pink flamingo
white rose
blue iris
white lily
red peony
yellow orchid
purple foxglove

Print File Contents

The following awk command will output the contents of a file to the terminal using the awk print function:

awk '{print}' flowers.txt

Print Number of Records (Lines) in File

awk 'END { print NR }' sample.txt

This example will output the number of lines in the file:

9

Search for Text in File Using Regular Expressions

The following command will output the lines in a file describing only types of rose:

awk '/rose/' flowers.txt

Note that REGEX (Regular Expressions) syntax is used to define the text to search.

This command will output:

red rose
white rose

More Regex

awk '/^p/' flowers.txt

This command will only output records starting with p:

pink flamingo
purple foxglove

Using Field Variables

By using field Variables, you can output only the first field for records starting with p:

awk '/^p/ {print $1;}' flowers.txt

Which will output:

pink
purple

Processing Output from other Programs

You can pipe output from other Linux shell programs into awk for processing. This example takes the output from the ls -l command, which lists the contents of the current directory and returns the contents of the 5th field (the size of the file):

ls -l | awk '{print $5}'

Which will output something like:

3104
3072
224
256

…(depending on how many files are in the current directory and how big they are).

Using Built-In Variables

awk '{print NR "-" $2 }' flowers.txt

This command will print the current record number (file line number) followed by the second field – the name of the flower:

1-red rose
2-yellow daffodil
3-pink flamingo
4-white rose
5-blue iris
6-white lily
7-red peony
8-yellow orchid
9-purple foxglove

Combining Actions

Conditions and actions can be combined using && This command will print all records where the first field contains the text red and the second field has less than 5 characters:

awk '$1 ~ /red/ && length($NF) < 5 { print }' flowers.txt

Note:

  • The use of $NF to get to the second field as an alternative to using $2 – possible as it’s the last field and thus equal to the NF (Number of Fields)
  • The length() function is used to calculate the length of the field

So it returns a single matching record from the example file:

red rose

Conclusion

awk is included pretty much universally with Linux for a reason – it’s a staple tool for searching and processing text, which you can use for quickly finding log entries if something goes wrong on your system or for processing captured data for research use.

If you’ve ever tried to do anything more than a simple find/replace on a large collection of text files, you’ll know the value in being able to specifically make replacements or updates to all of your text programmatically, without having to run individual find/replace commands.

Check out our other Linux Tips!

View the original article from LinuxScrew here: How to Use The awk Command in Linux [With Examples]

]]>
https://www.linuxscrew.com/awk-command/feed 0
How to Install Webmin on Ubuntu 20.04 https://www.linuxscrew.com/install-webmin-on-ubuntu https://www.linuxscrew.com/install-webmin-on-ubuntu#respond Sat, 16 Jan 2021 09:19:33 +0000 https://www.linuxscrew.com/?p=6013 Webmin is a system configuration tool that can be run on Linux. This step-by-step tutorial explains how to install Webmin on Ubuntu 20.04. Webmin makes it easy for newbies (and veterans) to monitor and manage their Linux system and the services running on it in a graphical, browser-based interface that can be accessed locally or… Read More »How to Install Webmin on Ubuntu 20.04

View the original article from LinuxScrew here: How to Install Webmin on Ubuntu 20.04

]]>
Webmin is a system configuration tool that can be run on Linux. This step-by-step tutorial explains how to install Webmin on Ubuntu 20.04.

Webmin makes it easy for newbies (and veterans) to monitor and manage their Linux system and the services running on it in a graphical, browser-based interface that can be accessed locally or remotely.

It’s a great tool for people getting started to manage users, web server configurations, file servers, and more. Webmin includes a bunch of modules for common software like Apache and MySQL, and additional packages can be installed to allow it to be used to configure other services.

You might be tempted to try installing Webmin using apt straight away, however

webmin install ubuntu 1

Webmin isn’t in the default Ubuntu repositories!

Adding the Webmin Repository to Ubuntu

To add the Webmin repository to Ubuntu – which will allow webmin to be installed and updated using the apt and apt-get commands, follow these steps;

Add the Webmin GPG Key

To allow the software to be installed from the Webmin repository, first add the developers GPG key to your system by running the following commands in your terminal:

wget https://download.webmin.com/jcameron-key.asc
sudo apt-key add jcameron-key.asc 
rm jcameron-key.asc

 

webmin install ubuntu 2

Add the Webmin Repository to apt

To add the repository to apt, edit the /etc/apt/sources.list file and add the repository to the list using the nano text editor:

sudo nano /etc/apt/sources.list

…and add the following lines to the end of the file:

# Webmin Repository
deb https://download.webmin.com/download/repository sarge contrib 

Press CTRL+X to exit nano, press Y to save changes.

webmin install ubuntu 3

Installing Webmin

With the repository added, we can now install Webmin like any other package using the apt command.

The below commands will double check we have the apt-transport-https package installed (a requirement that should already be met, but it doesn’t hurt to check), update the package lists, and install webmin:

sudo apt install apt-transport-https
sudo apt update
sudo apt install webmin 

Press Y to accept any changes, and Webmin will soon be installed!

webmin install ubuntu 4

Accessing Webmin Locally

Examine the pink highlighted section in the screenshot above, which is the Webmin installation process’s output.

It’s the address you can access Webmin on (yours will be different as your computer probably has a different hostname on the network).

By default, Webmin runs on port 10000, and this can be changed in the Webmin configuration if you’d prefer a different port.

To access Webmin, all we need to do is visit that address!

webmin install ubuntu 5

This doesn’t look good – but it’s OK.

Firefox is warning you that it doesn’t recognize the HTTPS certificate used by Webmin. This certificate was generated for use on your local computer and isn’t verified by any authority.

Just click Advanced and then Accept the Risk and Continue to ignore the warning and continue to Webmin.

webmin install ubuntu 6

WARNING: WE’RE IGNORING THIS SECURITY WARNING BECAUSE WE KNOW EXACTLY WHY IT’S HAPPENED – DON’T IGNORE THESE WARNINGS IF YOU GET THEM WHILE BROWSING THE INTERNET OR YOU AREN’T SURE OF THE CAUSE!

Webmin can also be accessed at the addresses

https://localhost:10000

or

https://127.0.0.1:10000

…from your local computer if you are unable to access it via the hostname.

webmin install ubuntu 7

Once you’ve bypassed the certificate warning, you can log into Webmin.

Accessing Webmin Remotely

If you can’t access Webmin from other computers on your local network using the URL containing the computer’s hostname, you can try connecting using its IP address:

webmin install ubuntu 11

Think I have a funny looking IP address? My network uses a class A subnet, in the format 10.0.0.0 – you might be used to seeing a class C subnet which has the format 192.0.0.0

Using Webmin

webmin install ubuntu 8

Once logged in, webmin will show all sorts of interesting statistics about your running computer.

webmin install ubuntu 9

Expand the menus on the left of the screen to access configuration and metrics for the services running on your system – from web servers to file and database servers.

There are hundreds (thousands?) of Webmin modules, so I won’t cover them here – check out the Webmin documentation for more information on how to leverage them:

https://www.webmin.com/docs.html

View the original article from LinuxScrew here: How to Install Webmin on Ubuntu 20.04

]]>
https://www.linuxscrew.com/install-webmin-on-ubuntu/feed 0
Don’t Install Yaourt on Arch Linux – use Yay instead! https://www.linuxscrew.com/yaourt-yay-arch-linux https://www.linuxscrew.com/yaourt-yay-arch-linux#respond Thu, 14 Jan 2021 09:19:16 +0000 https://www.linuxscrew.com/?p=6010 Yaourt (Yet AnOther User Repository Tool) is (was) a package manager for the Arch Linux distribution, which allowed for the installation of packages from the Arch User Repository (AUR). Don’t install Yaourt; it’s obsolete software. If you need a package manager for Arch Linux, install and use Yay instead! Yay is a package manager for Arch, which lets you install AUR packages.… Read More »Don’t Install Yaourt on Arch Linux – use Yay instead!

View the original article from LinuxScrew here: Don’t Install Yaourt on Arch Linux – use Yay instead!

]]>
Yaourt (Yet AnOther User Repository Tool) is (was) a package manager for the Arch Linux distribution, which allowed for the installation of packages from the Arch User Repository (AUR).

Don’t install Yaourt; it’s obsolete software. If you need a package manager for Arch Linux, install and use Yay instead!

Yay is a package manager for Arch, which lets you install AUR packages.

Why Yay? It’s actively developed and easy to install and use.

Installing

To install Yay for Arch Linux, run the following commands:

sudo pacman -Syy
sudo pacman -S --needed git base-devel
git clone https://aur.archlinux.org/yay.git
cd yay
sudo makepkg -si
  • The first command updates your package databases.
  • The second command installs the required dependencies to retrieve and build the Yay code.
  • The third command downloads the code from the Yay git repository.
  • Fourth changes into the folder where this code is stored
  • The fifth and final command builds and runs the Yay installation package.

Once this is done, you’ll see many things happening on-screen – this is the package being compiled and installed.

You might be asked to confirm to continue – go ahead!

Using Yay on Arch Linux

Search and Install Packages

Type the following into your terminal, substitution packagename with the package you want to search for:

sudo yay packagename

You will receive a list of matching packages – enter the number corresponding to the package you want to install to install it.

Install a Specific Package

If you already know the name of the package you want to install, run:

sudo yay -S packagename

Clean up Unneeded Dependencies

To remove packages that are no longer required to stop them clogging up your system, run:

yay -Yc

Remove package

To remove a package, run:

sudo yay -Rns packagename

View System Statistics

To view information on what packages are installed:

sudo yay -Ps

Conclusion

Yay is a great tool and a worthy replacement for Yaourt – give it a go!

If you’re on Ubuntu or Debian, check out our article on using the apt command to manage packages.

View the original article from LinuxScrew here: Don’t Install Yaourt on Arch Linux – use Yay instead!

]]>
https://www.linuxscrew.com/yaourt-yay-arch-linux/feed 0