Linux учу on windows

Getting started with Linux and Bash

This tutorial will help those new to Linux to get started installing and updating packages using the Ubuntu distribution of Linux that is installed by default using WSL, as well as using some basic commands with the Bash command line.

Installing and Updating Software

You can install and update software programs directly from the command line using the preferred package manager for the distribution you are running.

In Ubuntu, for example, first update the list of software available by running ‘sudo apt update’. Then, you can directly get software by using the ‘sudo apt-get install’ command followed by the name of the program you wish to install:

To update programs that have already been installed, you can run:

sudo apt update && sudo apt upgrade 

Different distributions of Linux often have different package managers and will require using an install command specific to the associated package manager. For example, the main package manager for Arch Linux is called pacman and the install command would be sudo pacman -S . The main package manager for OpenSuse is called Zypper and the install command would be sudo zypper install . The main package manager for Alpine is called apk and the install command would be sudo apk add . The two main package managers for Red Hat distributions, like CentOS, are YUM and RPM and an install command could be sudo yum install or sudo rpo -i . Refer to the documentation of the distribution you are working with to find out what tools are available for you to install and update software.

Working with files and directories

To view the path of the directory you are currently in, use the ‘pwd’ command:

To create a new directory, use the ‘mkdir’ command followed by the name of the directory you want to create:

To change directories, use the ‘cd’ command followed by the name of the directory you want to navigate to:

To see the contents within the directory you are currently in, type ‘ls’ into the command line:

By default, the ‘ls’ command will print the name of all the files and directories only. To get additional information such as the last time a file was modified or file permissions, use the flag “-l”:

Читайте также:  Система управления базами данных линукс

You can create a new file via the ‘touch’ command followed by the name of the file you would like to create:

You can edit files using any downloaded graphical text-editor or the VS Code Remote – WSL extension. You can learn more about getting started with VS Code here

If you prefer to edit a file directly from the command-line, you’ll need to use a command-line editor such as vim, emacs, or nano. Many distributions come with one or more of these programs installed, but you can always install these programs by following the installation instructions outlined in the guide from above.

To edit your file with your preferred method of editing, simply run the program name followed by the name of the file you’d like to edit:

notepad.exe hello_world.txt 

To see the contents of a file in the command line, use the ‘cat’ command followed by the file you’d like to read:

Using Pipes and Redirect Operators

A pipe ‘|’ redirects the output from one command as input into another command. For example, lhscmd | rhscmd would direct the output from lhscmd to rhscmd. Pipes can be used in a variety of ways to quickly accomplish tasks through the command line. Below are just a few simple examples of how pipes can be used.

Imagine you want to quickly sort the contents of a file. Take the fruits.txt example below:

cat fruits.txt Orange Banana Apple Pear Plum Kiwi Strawberry Peach 

You can quickly sort this list by using a pipe:

$ cat fruits.txt | sort Apple Banana Kiwi Orange Peach Pear Plum Strawberry 

By default, the output of the ‘cat’ command is sent to standard output; however, the ‘|’ allows us to instead redirect the output as the input to another command, ‘sort’.

Another use case is searching. You can use ‘grep’ which is a helpful command that searches input for a particular search string.

cat fruits.txt | grep P Pear Plum Peach 

You can also use redirect operators like ‘>’ to pass the output to a file or stream. For example, if you wanted to create a new .txt file with the sorted contents of fruit.txt:

cat fruits.txt | sort > sorted_fruit.txt 
$ cat sorted_fruit.txt Apple Banana Kiwi Orange Peach Pear Plum Strawberry 

By default, the output of the sort command is sent to standard output; however, the ‘>’ operator allows us to instead redirect the output into a new file named sorted_fruits.txt.

You can use pipes and redirect operators in many interesting ways to more efficiently complete tasks directly from the command line.

Читайте также:  Cmake gui linux install

Источник

How to Run Linux Apps on Windows 10 and 11 Using WSL

Yosra Emad

Yosra Emad

How to Run Linux Apps on Windows 10 and 11 Using WSL

I’ve been using Windows Subsystem for Linux (WSL) for my OS class for quite a while now. And I love how I can use Linux commands in Windows in a straightforward way without the added complexity of installing a virtual machine or dual booting.

By the end of this article, you should be able to run Linux commands right from Windows like this:

Untitled

Prerequisites

To have WSL running effectively, I suggest you upgrade to Windows 11. WSL is also available on Windows 10, but it is way more efficient on Windows 11 based on my experience.

For Windows 10, you’ll need to have build 21364 or higher.

This article will cover what you can do on both Windows 10 and 11

How to Install WSL

The command to run WSL is straightforward:

This will download the Linux kernel, set WSL 2 as the default, and install Ubuntu as the default distribution.

Don’t want ubuntu? Here is the command for you:

These are the available distributions as of now:

  • Ubuntu
  • OpenSUSE Leap 42
  • SUSE Linux Enterprise Server 12 (SLES)
  • Kali Linux
  • Debian GNU/Linux

After this, you’ll find an app called Ubuntu (or any other distro) in your start menu:

Untitled-1

Open the Linux Terminal

Open the Ubuntu app that you just installed, and you’ll be greeted with a Linux terminal! Try running some commands:

Untitled-2

What if I want to access my Windows files?

If you go to your file explorer (winkey+E) you’ll find a new Linux option on the left where all your Linux files exist. This is where when any files you create in the terminal will be located:

Untitled-3

But what if you want to access your regular files?

Luckily, you can do that easily. Just run the following command in your Linux terminal:

If you run ls here, you’ll find your computer drives. This way you’ll be able to cd your way into your files.

Untitled-4-1

How to Create Aliases in WSL2

Do you ever have a long command to type and wish there were a shortcut for it? Then, aliases are your friends.

There are two ways to create aliases:

How to create per session aliases in WSL2

To create an alias in your current session of Linux (the alias will be forgotten once you close the terminal), then you should run the following command:

alias runc='gcc main.c -o main' 

How to create permanent aliases in WSL2

We’ll edit a file called .bash_aliases to save our aliases.

Run the following commands:

Look through the list of files that are printed out and look for .bash_aliases .

If you can’t find it, run the following command:

Читайте также:  Acer es1 533 linux

Now in order to edit the file, run this command:

You’ll be greeted with a screen like this:

Untitled-5

  • Press «i» to start typing, and add as many aliases as you want.
alias runc='gcc main.c -o main' alias hello='echo hello' 
  • To exit the typing mode, press «ctrl + c».
  • To exit Vim and save the files type «:wq!» (I’m proud that I didn’t have to google that.)

Now you’re ready! Restart Ubuntu and start typing any of the following aliases above and it should work perfectly:

Untitled-6

How to Run GUI Apps

Okay cool, now we know how to run command line apps from WSL2. But what if we want to run Linux GUI apps? The answer is simple – you just need to install the GUI app before running it. I’ll use Firefox as an example.

Untitled

If you already have Firefox on your Windows machine, you’ll find that it isn’t open. That’s because you’re now running Firefox for Linux not Windows.

You can even run Firefox for Linux right from the start menu if you use Windows 11. You’ll find it under your distro’s folder.

Untitled

Conclusion

This article covered how to run WSL 2 effectively. If you have any questions, feel free to contact me on any of my social media platforms

Источник

Running Linux programs on Windows

To run a Linux program on Windows, you have these options:

  • Run the program as-is on the Windows Subsystem for Linux (WSL). In WSL your program executes directly on the machine hardware, not in a virtual machine. WSL also enables direct filesystem calls between Windows and Linux systems, removing the need for SSL transport. WSL is designed as a command-line environment and is not recommended for graphics-intensive applications. For more information, see Windows Subsystem for Linux Documentation.
  • Run the program as-is in a Linux virtual machine or Docker container, either on your local machine or on Azure. For more information, see Virtual Machines and Docker on Azure.
  • Compile the program using gcc or clang in the MinGW or MinGW-w64 environments, which provide a translation layer from Linux to Windows system calls.
  • Compile and run the program using gcc or clang in the Cygwin environment, which provides a more complete Linux environment on Windows compared to MinGW or MinGW-w64.
  • Manually port your code from Linux and compile for Windows using Microsoft C++ (MSVC). This involves refactoring platform-independent code into separate libraries, and then re-writing the Linux-specific code to use Windows-specific code (for example, Win32 or DirectX APIs). For applications that require high performance graphics, this is probably the best option.

Feedback

Submit and view feedback for

Источник

Оцените статью
Adblock
detector