One place for hosting & domains

      Command

      A Complete Guide to the nslookup Command


      The nslookup command is a useful tool for investigating domain name propagation issues. It allows users to obtain information regarding domain names and IP addresses from the Domain Name System (DNS) infrastructure. This guide introduces and explains how to use the nslookup command, and provides several examples.

      What is the nslookup Command?

      The name of the nslookup command is an abbreviated version of “name server lookup”. nslookup sends a request to the local domain name system server asking for information from its DNS records. In response, the DNS server returns the IP address or relevant domain information for a specific website or server. However, it can also return the domain associated with a particular IP address.

      The nslookup command can be used in either interactive or non-interactive mode. It is available on Linux, macOS, and Windows systems, and provides several useful options. The command relies on the underlying TCP/IP and networking system tools.

      Here are some of the main purposes of the nslookup command:

      • nslookup quickly returns the IP address for any domain. It is considered one of the best tools for troubleshooting DNS problems. It is especially handy for situations where the IP address of a domain has recently changed, but requests for the domain are not resolving.
      • It is used to investigate suspicious domains. A good example is a web address designed to closely mimic an existing domain, for instance, examp1e.com in place of example.com.
      • It can defend against cache poisoning in which invalid domain information is sent to secondary DNS servers, known as resolvers.

      How Do DNS Lookups Work?

      Each DNS server maintains a list of mappings between domain names and their associated IP addresses. When a DNS server receives a DNS request for a particular domain name from a web server, it translates the domain into an IP address. It then returns the address to the web server, which uses it to request the web page. Every internet client uses DNS services to properly transmit outgoing TCP/IP packets.

      Typically a DNS responds to a request by retrieving information from its cache. The cache is updated when updates are received. If the domain name entry for a particular domain has been recently changed, the server might not have received the updated information yet. In this event, the nslookup command still receives the outdated information from the DNS. This allows users to see what the local DNS record points to and determine whether the DNS update has propagated fully.

      The nslookup command typically sends its request to the local DNS server. However, an alternate DNS can be specified, such as the root system within the DNS zone. Not all servers are accessible because many internal DNS systems are private and do not respond to external requests. Therefore, private DNS servers don’t respond to external nslookup requests.

      Note

      In actual practice, there are two types of DNS services. A recursive DNS service, also known as a resolver, maintains a cache of the domain name mappings, but does not process any updates.

      In many networks, a resolver initially handles DNS queries. If it does not have the information, perhaps because the entry has aged out, it forwards the request to an authoritative DNS. Authoritative DNS systems maintain the master DNS records and are responsible for keeping the tables updated. The authoritative DNS returns the IP address to the resolver, which relays it back to the original web server. The resolver also caches the mapping for future requests.

      What Information Can the nslookup Command Retrieve?

      A DNS server maintains several different types of domain records, covering topics including reverse lookups, mail servers, and time-to-live settings. Here is a list of all the available DNS records.

      • Address (A) Record: Lists the IP address of the domain. Each address for the domain is described using a separate address record, so a domain can have multiple addresses and “A” records.
      • Canonical Name (CNAME) Record: Lists any aliases for the host.
      • Mail Exchange (MX) Record: Provides information about the mail servers within the domain.
      • Name Server (NS) Record: Lists all primary and secondary name servers for the domain.
      • Pointer (PTR) Record: A pointer record enables reverse lookups. It lists the host name associated with an IP address.
      • Start of Authority (SOA) Record: An SOA record indicates the most authoritative host for the DNS zone. A zone groups together multiple domains within the same organization.
      • Text (TXT) Record: A TXT record contains notes about the domain. Administrators often use this field to verify ownership and prevent spam.
      • Time-to-Live (TTL) Record: This setting indicates how long resolvers should cache the DNS information.

      Before You Begin

      1. If you have not already done so, create a Linode account and Compute Instance. See our
        Getting Started with Linode and
        Creating a Compute Instance guides.

      2. Follow our
        Setting Up and Securing a Compute Instance guide to update your system. You may also wish to set the timezone, configure your hostname, create a limited user account, and harden SSH access.

      Note

      This guide is written for a non-root user. Commands that require elevated privileges are prefixed with sudo. If you are not familiar with the sudo command, see the
      Users and Groups guide.

      How to Use the nslookup Command

      nslookup is available for the Linux, macOS, and Windows operating systems. However, the syntax is structured slightly different on Windows. This guide focuses on how to use the command on Linux-based systems, but the commands are very similar on macOS. Information on how to use nslookup on Windows can be found in the
      Microsoft documentation.

      The nslookup command supports both interactive and non-interactive modes. Interactive mode is useful for script development, troubleshooting, and exploratory searches. The non-interactive command is better for quick searches for a single piece of information. The non-interactive command can be fully integrated into scripts and software applications.

      nslookup is pre-installed and ready-to-use on most Linux-based systems. If it is not, it easily can be installed from the command line.

      • Debain and Ubuntu:

        sudo apt-get install dnsutils
        
      • AlmaLinux, CentOS Stream, Fedora, and Rocky Linux:

        sudo dnf install bind-utils
        

      Using nslookup in Interactive Mode

      To use nslookup interactively, simply enter the command nslookup from a terminal with no additional parameters. The interactive prompt should appear.

      nslookup
      
      >

      Note

      If you receive an error message when running the nslookup command, the network services might have been stopped. Reboot the system to reinitialize the process.

      The interactive prompt accepts requests for server information without requiring the nslookup command. To use nslookup to find the IP address for the English-language Wikipedia domain, enter the following:

      en.wikipedia.org
      

      The local DNS server returns its own address along with information about the en.wikipedia.org domain. The reply lists the canonical name of the server and its Ipv4 and Ipv6 addresses:

      Server:		127.0.0.53
      Address:	127.0.0.53#53
      
      Non-authoritative answer:
      en.wikipedia.org	canonical name = dyna.wikimedia.org.
      Name:	dyna.wikimedia.org
      Address: 91.198.174.192
      Name:	dyna.wikimedia.org
      Address: 2620:0:862:ed1a::1

      Note

      This answer is said to be non-authoritative because it is provided by the local DNS, not the DNS associated with the domain.

      To change the request type, use the set directive and append the preferred option. The following example sets the type for all further requests to ns. This instructs the nslookup utility to request information about the name servers used within the domain.

      set type=ns
      

      When nslookup sends another query about the domain, a list of nameservers is retrieved.

      wikipedia.org
      
      Server:		127.0.0.53
      Address:	127.0.0.53#53
      
      Non-authoritative answer:
      wikipedia.org	nameserver = ns0.wikimedia.org.
      wikipedia.org	nameserver = ns1.wikimedia.org.
      wikipedia.org	nameserver = ns2.wikimedia.org.
      
      Authoritative answers can be found from:

      To exit interactive mode, use the exit keyword.

      exit
      

      Using nslookup Non-interactively

      nslookup can also be used in non-interactive mode, in the same way as other Linux commands. To use the nslookup command non-interactively, use the format nslookup [options] domain_name. The command returns the same information it did in interactive mode. This is the correct mode to use in scripts and applications requiring accurate DNS information.

      To display basic information about a domain, enter the nslookup command and the name of the domain. This example displays the “A” records for the domain. An “A” record lists the IP addresses for a web host.

      nslookup wikipedia.org
      
      Server:		127.0.0.53
      Address:	127.0.0.53#53
      
      Non-authoritative answer:
      Name:	wikipedia.org
      Address: 91.198.174.192
      Name:	wikipedia.org
      Address: 2620:0:862:ed1a::1

      To validate the results on a different DNS server, append the name of the server to the end of the command. This example requests the IP address of wikipedia.org directly from a Wikipedia name server. The response contains the authoritative answer for the domain.

      nslookup wikipedia.org ns0.wikimedia.org
      
      Server:		ns0.wikimedia.org
      Address:	208.80.154.238#53
      
      Name:	wikipedia.org
      Address: 91.198.174.192
      Name:	wikipedia.org
      Address: 2620:0:862:ed1a::1

      nslookup Examples

      Although users are most often searching for nameserver and IP address information, nslookup provides access to all DNS records. This section includes examples showing how to use nslookup to obtain more detailed DNS information.

      Specify the type of record to search for using the type option. Add the option -type=option_type directly after the nslookup directive and before any domain name. Replace option_type with the name of the record type. For instance, to view the nameservers for a domain, use -type=ns. The following example displays nameserver information for wikipedia.org.

      nslookup -type=ns  wikipedia.org
      
      Server:		127.0.0.53
      Address:	127.0.0.53#53
      
      Non-authoritative answer:
      wikipedia.org	nameserver = ns0.wikimedia.org.
      wikipedia.org	nameserver = ns1.wikimedia.org.
      wikipedia.org	nameserver = ns2.wikimedia.org.
      
      Authoritative answers can be found from:

      To view mail server information for a domain, set the type to mx.

      nslookup -type=mx  wikipedia.org
      
      Server:		127.0.0.53
      Address:	127.0.0.53#53
      
      Non-authoritative answer:
      wikipedia.org	mail exchanger = 10 mx1001.wikimedia.org.
      wikipedia.org	mail exchanger = 10 mx2001.wikimedia.org.
      
      Authoritative answers can be found from:

      nslookup can also retrieve the official Start of Authority (SOA) record, containing vital information about the domain. This information includes the email address of the administrator and DNS parameters such as refresh time. Use -type=soa to search for this information.

      nslookup -type=soa wikipedia.org
      
      Server:		127.0.0.53
      Address:	127.0.0.53#53
      
      Non-authoritative answer:
      wikipedia.org
          origin = ns0.wikimedia.org
          mail addr = hostmaster.wikimedia.org
          serial = 2022030414
          refresh = 43200
          retry = 7200
          expire = 1209600
          minimum = 3600
      
      Authoritative answers can be found from:

      It is often useful to compare SOA records between sites. The SOA record for amazon.com has much lower refresh and retry numbers, suggesting the domain information might change more frequently.

      nslookup -type=soa amazon.com
      
      Server:		127.0.0.53
      Address:	127.0.0.53#53
      
      Non-authoritative answer:
      amazon.com
          origin = dns-external-master.amazon.com
          mail addr = root.amazon.com
          serial = 2010161662
          refresh = 180
          retry = 60
          expire = 3024000
          minimum = 60
      
      Authoritative answers can be found from:

      The TXT records are used to validate domain information. Use -type=txt to retrieve this information.

      nslookup -type=txt wikipedia.org
      
      Server:		127.0.0.53
      Address:	127.0.0.53#53
      
      Non-authoritative answer:
      wikipedia.org	text = "google-site-verification=AMHkgs-4ViEvIJf5znZle-BSE2EPNFqM1nDJGRyn2qk"
      wikipedia.org	text = "yandex-verification: 35c08d23099dc863"
      wikipedia.org	text = "v=spf1 include:wikimedia.org ~all"
      
      Authoritative answers can be found from:

      Use the option -type=any to view the full DNS records for a domain.

      nslookup -type=any google.com
      
      Server:		127.0.0.53
      Address:	127.0.0.53#53
      
      Non-authoritative answer:
      Name:	google.com
      Address: 216.58.212.206
      Name:	google.com
      Address: 2a00:1450:4009:81e::200e
      google.com	mail exchanger = 10 smtp.google.com.
      google.com	nameserver = ns4.google.com.
      google.com	nameserver = ns3.google.com.
      google.com	nameserver = ns1.google.com.
      google.com	nameserver = ns2.google.com.
      
      Authoritative answers can be found from:

      Note

      Some domains are not configured to return all information in response to this request, and only return the name servers. In this case, you must request each type of record separately.

      It’s also possible to ask for information about a particular name server. Use nslookup and the name of the domain, along with the canonical name of the name server. This example demonstrates how to find out details about Wikipedia’s ns0.wikimedia.org name server.

      nslookup wikipedia.org ns0.wikimedia.org
      
      Server:		ns0.wikimedia.org
      Address:	208.80.154.238#53
      
      Name:	wikipedia.org
      Address: 91.198.174.192
      Name:	wikipedia.org
      Address: 2620:0:862:ed1a::1

      To debug the information from nslookup, use the -debug flag. Debug mode displays the queries sent to the DNS server along with the replies received in response.

      nslookup -debug wikipedia.org
      
      Server:		127.0.0.53
      Address:	127.0.0.53#53
      
      ------------
          QUESTIONS:
          wikipedia.org, type = A, class = IN
          ANSWERS:
          ->  wikipedia.org
          internet address = 91.198.174.192
          ttl = 600
          AUTHORITY RECORDS:
          ADDITIONAL RECORDS:
      ------------
      Non-authoritative answer:
      Name:	wikipedia.org
      Address: 91.198.174.192
      ------------
          QUESTIONS:
          wikipedia.org, type = AAAA, class = IN
          ANSWERS:
          ->  wikipedia.org
          has AAAA address 2620:0:862:ed1a::1
          ttl = 600
          AUTHORITY RECORDS:
          ADDITIONAL RECORDS:
      ------------
      Name: wikipedia.org
      Address: 2620:0:862:ed1a::1

      For more information on the list of available nslookup options, consult the
      Linux man page.

      Note

      Most DNS requests are sent and received using TCP port 53. To request DNS information from a different port, use the -port flag, for example nslookup -port=55 wikipedia.org. In most cases DNS servers are configured to refuse these requests, resulting in the error message communications error to 127.0.0.53#55: connection refused.

      How to Use nslookup for Reverse Lookups

      Although nslookup can find the IP address for a domain, it can also reveal the domain mapped to an IP address. This is referred to as a reverse DNS lookup. To perform a reverse lookup, apply the nslookup command to the IP address under investigation. The following example illustrates how to find the domain that is mapped to the address 91.198.174.192.

      Note

      The output displays the IP address in reverse order, so 91.198.174.192 is transposed to 192.174.198.91 in the display. The octets are presented in reverse order due to complex technical reasons involving the in-addr.arpa domain tree specification.

      nslookup 91.198.174.192
      
      192.174.198.91.in-addr.arpa	name = text-lb.esams.wikimedia.org.
      
      Authoritative answers can be found from:

      A second alternative is to use the -type=ptr option and the address in reverse order to find the domain. The pointer record confirms the domain owns the address in question.

      nslookup -type=ptr 192.174.198.91.in-addr.arpa
      
      Server:		127.0.0.53
      Address:	127.0.0.53#53
      
      Non-authoritative answer:
      192.174.198.91.in-addr.arpa	name = text-lb.esams.wikimedia.org.
      
      Authoritative answers can be found from:

      Conclusion

      The nslookup command is used to discover DNS information about a domain. It can work in either interactive or non-interactive mode, and is available for Linux, macOS, and Windows servers. nslookup can return the IP address for a domain, along with information about its nameservers, mail servers, and State of Authority record. It can also handle reverse DNS lookups for translating an IP address into a domain. For more information, see the
      Linux nslookup man page.

      More Information

      You may wish to consult the following resources for additional information
      on this topic. While these are provided in the hope that they will be
      useful, please note that we cannot vouch for the accuracy or timeliness of
      externally hosted materials.



      Source link

      Connect to a MySQL Database Using the mysql Command


      Updated
      , by Linode

      Traducciones al Español

      Estamos traduciendo nuestros guías y tutoriales al Español. Es
      posible que usted esté viendo una traducción generada
      automáticamente. Estamos trabajando con traductores profesionales
      para verificar las traducciones de nuestro sitio web. Este proyecto
      es un trabajo en curso.

      Create a Linode account
      to try this guide with a $100 credit.

      This credit will be applied to any valid services used during your first 60 days.

      This guide shows you how to connect to a MySQL database using
      mysql, the MySQL command-line client. This opens up a simple SQL shell environment, allowing you to perform
      SQL queries and commands on your database. If you require more advanced capabilities, consider using the
      MySQL Shell.

      Note

      If you wish to connect to a Linode MySQL Managed Database, review the
      Connect to a MySQL Managed Database guide instead.

      Before You Begin

      • Obtain the connection details for the MySQL instance you wish to use. If you do not have a MySQL instance yet, you can
        create a Managed Database,
        deploy the MySQL Marketplace App, or
        install MySQL server (or MariaDB) on a Compute Instance. This instance must allow remote connections or you must run the mysql command from within same system.

      • Ensure mysql is installed and is compatible with the MySQL version on your database server. Run the following command on the system you intend on using to verify that mysql is installed.

        mysql --version
        

        This should inform you which version you are using. If the command is not found or you are not on a compatible version, see the
        Installing MySQL guide.

      Note

      The steps in this guide are written for a non-root user. Commands that require elevated privileges are prefixed with sudo. If you’re not familiar with the sudo command, see the
      Linux Users and Groups guide.

      General mysql Syntax

      The main purpose of the mysql utility is to connect to a MySQL database server and open a simple SQL shell environment. The mysql command can be used to connect to either a local or remote database server. In the commands provided below, see the
      Common Command Options for information on each of the available options.

      • Local database server: Use this command when connecting to a MySQL Server instance running on the same machine you are using.

        mysql -u [username] -p
        
      • Remote database server: In many cases, the database server is not on the same system you are using. In these cases, you can SSH in to the remote system (if permitted) and run the command above to connect to a local MySQL instance. Alternatively, you can use the mysql command to remotely connect to the database. If your MySQL server does not allow remote connections or your user cannot connect remotely, see
        Configure the Database Server to Allow Remote Connections.

        mysql -h [host] -p [port] -u [username] -p
        

        Note

        If you wish to connect to a Linode MySQL Managed Database, review the
        Connect to a MySQL Managed Database guide instead.

      Common Command Options

      The following list is a collection of common options used with the mysqldump command. At minimum, the username and password is required. When connecting to a remote database server, the host (and perhaps the port) should be provided. For a full list of available options, reference the
      Command Options for Connecting to the Server documentation.

      • Username (--user=[] or -u []): The username of your MySQL user. This user must have proper grants to access the database.

      • Password (--password=[] or -p[]): Specifies that the user’s password is required for the connection. The password can be entered directly in the command itself (though that is not recommended due to security concerns) or the password can be omitted (by just using the --password option with no value). In the password is omitted, mysql prompts you for the password before connecting to the database. For more details about password security, see MySQL’s
        End-User Guidelines for Password Security.

      • Host (--host=[] or -h []): The IP address or FQDN (fully qualified domain name) of the remote database server. You can omit this option from the command if you are connecting to a local MySQL instance on your same system.

      • Port (--port=[] or -P []): The port number of that the MySQL database instance uses. This can be omitted if your MySQL instance uses the default port of 3306.

      • SSL Settings (--ssl-mode): This controls if the connection should be encrypted. This can be set to DISABLED (unencrypted – not recommended), PREFERRED (tries an encrypted connection first before falling back to unencrypted), or REQUIRED (fails if an encrypted connection can’t be established. If omitted, this option is automatically set to PREFERRED. You can also set this to VERIFY_CA or VERIFY_IDENTITY to require an encrypted connection and either verify the CA certificate or both verify the CA certificate and the host name identity.

      If you are frequently connecting to the same database, you can securely store many of these options (including the password). See the
      Securely Storing Credentials guide. Other options can be stored in an
      option file.

      Configure the Database Server to Allow Remote Connections

      If you have installed the MySQL server yourself (not through a managed service) and wish to connect to a database remotely without first logging in to the database server through SSH, you may need to modify a few settings. This can be useful if you want to limit SSH access but still permit database access.

      Refer to our
      Create an SSH Tunnel for MySQL Remote Access to learn how to connect to your database using an SSH tunnel.

      1. Make sure your database has a user set up to allow connections from your local machine’s IP address.

        The example below displays a series of commands to create a new MySQL/MariaDB user named example_user. The user accepts connections from 192.0.2.0 and has SELECT, INSERT, UPDATE, and DELETE permissions on the example_db database:

        CREATE user 'example_user'@'192.0.2.0' IDENTIFIED BY 'password';
        GRANT SELECT,INSERT,UPDATE,DELETE ON example-db.* TO 'example_user' IDENTIFIED BY 'password';
        
      2. Locate you database’s configuration files using the command below. The following command lists the files’ default locations. The locations returned by the command may be different than those in the example shown below:

        sudo mysql --help
        
        ...
        Default options are read from the following files in the given order:
        /etc/my.cnf /etc/mysql/my.cnf ~/.my.cnf
        ...
      3. Using your preferred text editor, locate the [mysqld] section and a bind-address parameter.

        If you see any !includedir parameters in the files, you may also need to check the files in the locations those parameters designate.

      4. Once you locate the bind-address parameter, change it from the default 127.0.0.1 to 0.0.0.0. This enables external connections on the database.

        Also, if the file contains a skip-networking parameter, comment it out with a #.

        File: /etc/mysql/mysql.conf.d/mysqld.conf
        1
        2
        3
        4
        5
        6
        7
        8
        
        ...
        [mysqld]
        
        ...
        # skip-networking
        
        bind-address = 0.0.0.0
        ...
      5. Restart the MySQL service.

        sudo systemctl restart mysqld
        

      Follow our
      Install MySQL Workbench for Database Administration guide for steps to install the MySQL Workbench tool on your local machine. This guide also shows you how to connect to a remote database via MySQL Workbench. These steps work whether your target database server is MySQL or MariaDB.

      For more information, take a look at the
      official MySQL Workbench manual. You may also refer to MariaDB’s documentation on
      using the MySQL Workbench with MariaDB.

      Conclusion

      Now that you have your remote database connection, you may want to learn more about using MySQL/MariaDB and working with more advanced database operations. You can refer to our extensive
      list of MySQL guides and specific
      MariaDB guides to build your database management skills.

      More Information

      You may wish to consult the following resources for additional information
      on this topic. While these are provided in the hope that they will be
      useful, please note that we cannot vouch for the accuracy or timeliness of
      externally hosted materials.

      This page was originally published on



      Join the conversation.
      Read other comments or post your own below. Comments must be respectful,
      constructive, and relevant to the topic of the guide. Do not post external
      links or advertisements. Before posting, consider if your comment would be
      better addressed by contacting our
      Support team or asking on
      our
      Community Site.



      Source link

      How To Install and Use the Visual Studio Code (VS Code) Command Line Interface


      Introduction

      Visual Studio Code is a free, open-source, and cross-platform text editor developed primarily by Microsoft. It uses web technologies such as JavaScript and CSS, which has helped facilitate a large ecosystem of community-created plugins to extend its functionality into many different programming languages and features.

      In this tutorial, you’ll install the Visual Studio Code command line interface and learn how to use it to open files and directories, compare changes between files, and install extensions.

      Prerequisites

      To complete this tutorial, you’ll need to have Visual Studio Code installed. Please refer to the official Setting up Visual Studio Code documentation to find out how to install Code for your platform.

      Installing the Visual Studio Code Command Line Interface

      You may need to install the Visual Studio Code command line interface before using it. To do so, first launch the normal Visual Studio Code graphical interface. If this is your first time opening the app, the default screen will have a icon bar along the left, and a default welcome tab:

      A screenshot of the default

      Visual Studio Code provides a built-in command to install its command line interface. Bring up Code’s Command Palette by typing Command+Shift+P on Mac, or Control+Shift+P on Windows and Linux:

      A screenshot of the Visual Studio Code interface with the Command Palette activated, waiting for input to be entered after its '>' prompt

      This will open a prompt near the top of your Code window. Type shell command into the prompt. It should autocomplete to the correct command which will read Shell Command: Install 'code' command in PATH:

      A screenshot of the Visual Studio Code interface, with the Command Palette activated and the "Install 'code' command in PATH" command highlighted

      Press ENTER to run the highlighted command. You may be prompted to enter your administrator credentials to finish the installation process.

      You now have the code command line command installed.

      Verify that the install was successful by running code with the --version flag:

      Output

      1.62.1 f4af3cbf5a99787542e2a30fe1fd37cd644cc31f x64

      If your output includes a version string, you’ve successfully installed the Visual Studio Code command line interface. The next few sections will show you a few ways to use it.

      Opening Files with the code Command

      Running the code command with one or more filenames will open those files in the Visual Studio Code GUI:

      This will open the file1 file in Code.

      This will open all markdown (.md) files in the current directory in Code.

      By default, the files will be opened in an existing Code window if one is available. Use the --new-window flag to force Visual Studio Code to open a new window for the specified files.

      Opening a Directory with the code Command

      Use the code command followed by one or more directory names to open the directories in a new Visual Studio Code window:

      • code directory1 directory2

      Code will open a new window for the directories. Use the --reuse-window flag to tell Code to reuse the existing frontmost window instead.

      Opening a .code-workspace Workspace File with the code Command

      Opening a workspace file with the code command works similar to opening directories:

      • code example.code-workspace

      This will open the example workspace in a new window, unless you reuse an existing window by adding the --reuse-window flag.

      Installing an Extension Using the code Command

      You can install Visual Studio Code extensions using the code command line tool as well. To do so, you’ll first need to know the extension’s unique identifier. To find this information, first navigate to the extension’s page on the Visual Studio Marketplace.

      For instance, here is the page for the Jupyter Notebook extension:

      https://marketplace.visualstudio.com/items?itemName=ms-toolsai.jupyter

      Notice the itemName parameter in the address. This parameter’s value, ms-toolsai.jupyter, is this extension’s unique identifier.

      You can also find this information on the Marketplace page itself, towards the bottom of the right-hand column in the More info section:

      A screenshot of the Jupyter extension's page on the Visual Studio Marketplace, highlighting the 'Unique Identifier ms-toosai.jupyter' unique id information in the page's right-hand column

      Once you have this unique id, you can use it with code --install-extension to install the extension:

      • code --install-extension ms-toolsai.jupyter

      Output

      Installing extension 'ms-toolsai.jupyter'... Extension 'ms-toolsai.jupyter' v2021.11.1001489384 was successfully installed.

      Use the same id with the --uninstall-extension flag to uninstall the extension.

      Showing the Differences Between Two Files Using the code Command

      To show a standard split-screen diff that will highlight the additions, deletions, and changes between two files, use the --diff flag:

      A screenshot of the Visual Studio Code diff interface, with two files side by side, and the second line highlighted, showing a few words have changed between the two versions

      Similar to opening files, this will reuse the frontmost window by default, if one exists. To force a new window to open, use the --new-window flag.

      Piping stdin Into Visual Studio Code Using the code Command

      An important feature of most command line shells is the ability to pipe (or send) the output of one command to the input of the next. In the following command line, notice the | pipe character connecting the ls ~ command to code -:

      This will execute the ls command on the ~ directory, which is a shortcut for the current user’s home directory. The output from ls will be a list of files and directories in your home directory. This will be sent to the code command, where the single - indicates that it should read the piped in text instead of a file.

      code will output some information about the temporary file that it has created to hold the input:

      Output

      Reading from stdin via: /var/folders/dw/ncv0fr3x0xg7tg0c_cvfynvh0000gn/T/code-stdin-jfa

      Then this file will open up in the Code GUI interface:

      A screenshot of Visual Studio Code with a text file open, displaying the text piped in from the ls command. The text is standard directories such as Desktop and Documents, along with file1 and file2 used in the previous section

      This command will continue to wait indefinitely for more input. Press CTRL+C to have code stop listening and return you to your shell.

      Add the --new-window flag to force Code to open a new window for the input.

      Conclusion

      In this tutorial you installed Visual Studio Code’s code command line tool, and used it to open files and directories, compare files, and install extensions.

      To learn more about the code command, you can run its --help function:

      You can also refer to the official Visual Studio Code command line documentation or take a look at our VS Code tag page for more Visual Studio Code tutorials, tech talks, and Q&A.



      Source link