Common commands for Linux beginners

Source: Internet
Author: User

Common commands for Linux beginners

Use dnf on Fedora to manage system updates

The most amazing thing about a Linux-based system is that you can use the command line in the terminal to manage the entire system. The advantage of using command line is that you can use the same knowledge and skills to manage any Linux release.

For each release and desktop environment (DE), it is almost impossible to use graphical user interfaces (GUI) in a consistent manner because they provide their own user interfaces. It should be clear that in some cases different releases require different commands to execute certain specific tasks. However, their ideas and objectives are basically the same.

In this article, we plan to discuss some basic commands that Linux users should master. I will show you how to use the command line to update the system, manage software, operate files, and switch to root. These operations will be performed on the three major releases: ubuntu (also including its customized and derivative versions, as well as Debian), openSUSE, and Fedora.

Let's get started!

 

Keep the system secure and up-to-date

Linux is designed based on security, but in fact, any software has defects, which may lead to security vulnerabilities. Therefore, it is very important to keep your system updated to the latest version. Think about it: an outdated operating system is like sitting in a fully armed tank, but the door is unlocked. Will weapons protect you? Anyone can access the Open Door and cause harm to you. Likewise, there are no patch vulnerabilities in your system, which may harm your system. The open-source community, unlike the patent world, responds very quickly in terms of vulnerability patches. Therefore, if you keep the system up-to-date, you also get security assurance.

Pay attention to news sites and learn about security vulnerabilities. If a vulnerability is detected, understand it and update it as soon as the patch is released. In a production environment, you must run the update command at least once a week. If you are running a complex server, you need to be careful. Read the change log carefully to ensure that the update will not break your custom service.

Ubuntu: You must refresh the repository (repos) Before upgrading the system or installing any software ). On Ubuntu, you can use the following command to update the system. The first command is used to refresh the Repository:

  1. sudo apt-get update

After the repository is updated, you can now run the system update command:

  1. sudo apt-get upgrade

However, this command does not update the kernel and other packages, so you must also run the following command:

  1. sudo apt-get dist-upgrade

OpenSUSE: if you are using openSUSE, you can use the following command to update the system (as shown in the following example, the first command indicates updating the repository ):

  1. sudo zypper refresh
  2. sudo zypper up

Fedora: If you are on Fedora, you can use the 'dnf 'command, which is 'similar' of zypper and apt-get ':

  1. sudo dnf update
  2. sudo dnf upgrade

 

Software installation and removal

You can only install the packages available in the repositories enabled on your system. Each release has some official or third-party repositories installed by default.

Ubuntu: to install the package on Ubuntu, first update the repository and then use the following statement:

  1. sudo apt-get install [package_name]

Example:

  1. sudo apt-get install gimp

OpenSUSE: The command is as follows:

  1. sudo zypper install [package_name]

Fedora: Fedora has replaced 'yum 'with 'dnf', so the command is as follows:

  1. sudo dnf install [package_name]

The process of removing software is the same. You only need to change 'install' to 'delete '.

Ubuntu:

  1. sudo apt-get remove [package_name]

OpenSUSE:

  1. sudo zypper remove [package_name]

Fedora:

  1. sudo dnf remove [package_name]

 

How to manage third-party software?

In a huge developer community, these developers provide users with a lot of software. Different releases have different mechanisms to provide these third-party software to users. Of course, it also depends on how developers provide these software to users. Some developers provide Binary packages, while others release the software to the repository.

Ubuntu uses PPA (Personal package archiving) in many places, but unfortunately it does not provide a built-in tool to help search for these PPA repositories. Before installing the software, you need to search for PPA by Google and then manually add the repository. The following describes how to add a PPA to the system:

  1. sudo add-apt-repository ppa:<repository-name>

Example: for example, I want to add LibreOffice PPA to my system. I should Google the PPA and get the repository name from Launchpad. In this example, it is "libreoffice/ppa ". Then, use the following command to add the PPA:

  1. sudo add-apt-repository ppa:libreoffice/ppa

It requires you to press the Enter key to import the key. Then, run the 'update' command to refresh the repository and install the package.

OpenSUSE has an elegant solution for third-party applications. You can access software.opensuse.org and click one-click Search and install the corresponding package. It will automatically add the corresponding repository to your system. To manually add a repository, run the following command:

  1. sudo zypper ar -f url_of_the_repo name_of_repo
  2. sudo zypper ar -f http://download.opensuse.org/repositories/LibreOffice:Factory/openSUSE_13.2/LibreOffice:Factory.repo LOF

Then, refresh the repository and install the software:

  1. sudo zypper refresh
  2. sudo zypper install libreoffice

The Fedora user only needs to add RPMFusion (including free software and non-free software warehouse), which contains a large number of applications. To add the repository, run the following command:

  1. dnf config-manager --add-repo http://www.example.com/example.repo

 

Some basic commands

I have written some articles about using CLI to manage files on your system. The following describes some basic commands that are frequently used in all releases.

Copy a file or directory to a new location:

  1. cp path_of_file_1 path_of_the_directory_where_you_want_to_copy/

Copy all files in a directory to a new location (note that the slash and star number indicate all files in the directory ):

  1. cp path_of_files/* path_of_the_directory_where_you_want_to_copy/

Move a file from one location to another (the tail slash is used to put the file in this directory ):

  1. mv path_of_file_1 path_of_the_directory_where_you_want_to_move/

Move all files from one location to another:

  1. mv path_of_directory_where_files_are/* path_of_the_directory_where_you_want_to_move/

Delete an object:

  1. rm path_of_file

Delete a directory:

  1. rm -r path_of_directory

Remove all contents from the directory and keep the directory folder intact:

  1. rm -r path_of_directory/*

 

Create a new directory

To create a new directory, first go to the location where you want to create the directory. For example, you want to create a folder named 'Foundation 'in your Documents directory. Let's use the cd (change directory, change directory) command to change the directory:

  1. cd /home/swapnil/Documents

(Replace 'swapi' with your username in the system)

Then, run the mkdir command to create the directory:

  1. mkdir foundation

You can also create a directory from anywhere by specifying the directory path. For example:

  1. mdkir /home/swapnil/Documents/foundation

If you want to create a parent directory, you can use the-p option. It creates all directories in the specified path:

  1. mdkir -p /home/swapnil/Documents/linux/foundation

 

Become root

You may need to be the root user or a user with sudo power to implement some management tasks, such as managing software packages or modifying the files under or under the root directory. One example is to edit the 'fstab' file, which records the mounted hard drive. It is in The 'etc 'directory, and the directory is in the root directory. You can only modify the file as a Super User. In most releases, you can use 'su 'to become the root. For example, in openSUSE, you can use one of the following commands to become root because I want to work in the root directory:

  1. sudo su -

Or

  1. su -

This command requires a password, and then you have the root privilege. Remember: Never run the system as a root user unless you know what you are doing. It is also important to note that after you modify the directory or file as root, their ownership relationships will be changed from this user or a specific service to root. You must restore the ownership of these files, otherwise the service or user will not be able to access or write to those files. To change the user, run the following command:

  1. Sudo chown-R user: group file or directory name

This operation is often required when you mount partitions on other releases to the system. When you try to access files in these partitions, you may encounter a permission denial error. You only need to change the ownership of these partitions to access them. Be careful not to change the root directory permissions or relationships.

These are the basic commands required by Linux beginners. If you have any questions or want to cover a specific topic, please let us know in the following comments.

Via: Must-Know Linux Commands For New Users

Author: Swapnil Bhartiya Translator: GOLinux Proofreader: wxy

This article was originally translated by LCTT and launched with the Linux honor in China

This article permanently updates the link address:

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.