Home  >  Article  >  System Tutorial  >  10 basic commands that newbies to Linux should master

10 basic commands that newbies to Linux should master

WBOY
WBOYforward
2024-02-05 11:40:03892browse

When we discuss Linux commands, we are actually discussing the Linux operating system itself. Just knowing these ten basic Linux commands does not make you a genius or Linux expert. For those experienced users, these commands may be very simple and basic, but for those new to Linux, these commands can help them complete basic daily tasks.

Linux 入门新手应掌握的 10个 基本命令

Now, let us introduce these ten basic Linux commands one by one.

1.sudo

This SuperUserDo is the most important command for Linux newbies to use. Every command that requires root privileges requires this sudo command. You can use sudo before every command that requires root privileges.

$ sudo su

2.ls(list)

With the list command, the terminal will display all the files and folders in the directory you are working on. Suppose I am in the /home folder and want to view the directories and files in /home.

/home$ ls

ls in/home returns the following results:

imad lost+found

3.cd

Change directory (cd) is the main command always used in the terminal. It is one of the most basic Linux commands. Using this command is simple. Just enter the name of the folder you want to access from the current directory. If you want to return to the previous level, just pass a double dot (..) as a parameter.

Suppose I am in the /home directory and want to enter the usr directory that is always in /home. Here's how I can use the cd command:

/home $ cd usr
/home/usr $

4.mkdir

仅仅更改目录还不全面。有时候,你想要创建一个新的文件夹或子文件夹。可以使用mkdir命令来做到这一点。只要在终端中将你的文件夹名称放在mkdir命令的后面即可。

$ mkdir folderName

5.cp

拷贝粘贴是我们为了组织整理文件而需要完成的重要任务。使用cp将帮助你从终端拷贝粘贴文件。首先,你确定想要拷贝的那个文件,然后输入目的地位置,即可粘贴文件。

$ cp src des

注意:如果你将文件拷贝到任何新文件都需要根权限的目录,那么你就需要使用sudo命令。

6.rm

rm这个命令可以移除你的文件,甚至移除你的目录。如果文件需要根权限才能移除,可以使用-f。你还可以使用-r来进行递归移除,从而移除你的文件夹。

$ rm myfile.txt

7.apt-get

就不同的发行版而言,这个命令各不相同。在基于Debian的Linux发行版中,想安装、移除和升级任何软件包,我们可以使用高级包装工具(APT)软件包管理器。apt-get命令可帮助你安装需要在Linux中运行的软件。这是个功能强大的命令行工具,可以执行安装、升级、甚至移除软件这类任务。

在其他发行版(比如Fedora和Centos)中,有不同的软件包管理器。Fedora过去有yum,但现在它有dnf。

$ sudo apt-get update
$sudo dnf update

8.grep

你需要找到一个文件,但是又记不得它的确切位置或路径。grep可以帮助你解决这个问题。你可以使用grep命令,根据给定的关键字帮助找到文件。

$ grep user /etc/passwd

9.cat

作为用户,你常常需要查看来自脚本的一些文档或代码。同样,其中一个Linux基本命令是cat命令。它会为你显示文件里面的文本。

$ cat CMakeLists.txt

10.poweroff

有时候,你需要直接从终端来关机。这个命令就能完成这项任务。别忘了在命令的开头添加sudo,因为它需要根权限才能执行poweroff。

$ sudo poweroff

结束语

正如我在文章开头提到:这10个基本的Linux命令不会立马让你变成Linux极客。它会帮助你在这个早期阶段开始使用Linux。借助这些基本的Linux命令,开始使用Linux,并且定个目标:每天学会使用1个至3个命令。这就是本文的目的,但愿对你有所帮助。

The above is the detailed content of 10 basic commands that newbies to Linux should master. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:lxlinux.net. If there is any infringement, please contact admin@php.cn delete