Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the necessary Linux commands for beginners?

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly introduces the relevant knowledge of "what are the necessary Linux commands for beginners". The editor shows you the operation process through actual cases, the method of operation is simple and fast, and it is practical. I hope this article "what are the necessary Linux commands for beginners" can help you solve the problem.

How to ask for help?

When you encounter problems under Linux, the most important thing is to ask for help yourself. here are three ways to ask for help.

Man

Man is the help manual for Linux, or manual. Because most programs come with their own manuals, you can get help through the man command. After execution, press Q on the man page page to exit.

Get help from ls

$man ls

Check how many manuals of the same name (for different aspects)

$man-f lsls (1)-list directory contentsls (1p)-list directory contents

View specific manuals

$man 1p lsinfo

Unlike man, you can jump through each node like browsing a web page.

Start browsing from the front page of the document

$info

Get help from a specific program

$info programhelp

In addition to the above two methods, there is a simple method to use, that is, the-help parameter, the general program will have this parameter, will output the most simple and useful introduction.

$man-- help # get help for man $info-- help # get help for info $ls-- help # how to get help for ls?

There are many operating skills in Terminal (terminal). Here are a few simple ones.

Cursor up (on the arrow key) can call up the input history execution record, quickly execute the command down (under the arrow key) with up select the history execution record Home move the cursor to the beginning of the line End move the cursor to the end of the line PgUp turn the page up PaDN turn the page down ctrl + c to terminate the current program Tab completion

Tab completion is a very useful feature that can be used to automatically complete commands or file names, saving time and accuracy.

Without input state, press Tab twice to list all available commands have entered part of the command name or file name, press Tab for automatic completion, multi-use you will certainly like it. Common command

The following commands are arranged according to the usual frequency of use.

Cd

Cd is a command to open a path, that is, to open a folder and jump to it.

$cd path # # path is the path you want to open.

Path can be divided into absolute path and relative path, and the absolute path emphasizes from / to the path. Relative path relative to the current path, assume that the current home directory has an etc folder (the absolute path should be / home/username/etc), if directly cd etc then enter this folder, but if cd / etc/ is to enter the system etc, you can understand it by thinking about it. In addition, in Linux, Represents the current directory. Represents the parent directory, so returning to the parent directory can be cd.. .

Ls

Ls, or list, lists the files.

$ls # list only visible files in the current directory $ls-l # list details of visible files in the current directory $ls-hl # list details and display file size in readable size $ls-al # list details of all files (including hidden)

Note: in Linux with. The files or folders at the beginning are hidden files or hidden folders.

Pwd

Pwd is used to return the name of the current working directory, which is the absolute pathname.

$pwd/homemkdir

Mkdir is used to create a new folder.

The parameter $mkdir folder$ mkdir-p folder/subfolder #-p is ignored when the parent directory exists, and is created if it does not exist. Use this parameter to create a multi-level folder rm

Rm, or remove, deletes the file.

$rm filename # Delete filename$ rm-I filename # prompt before deleting filename. If there are multiple files, prompt $rm-rf folder/subfolder/ # recursively delete all files and folders under subfolder, including subfolder itself $rm-d folder # Delete empty folder cp

Cp, or copy, copies the file.

$cp source dest # copy source to dest$ cp folder/* dest # # copy all files under folder (excluding files in subfolders) to dest$ cp-r folder dest # copy all files under folder (including all files in subfolders) to destmv

Mv, or move, moves files.

$mv source folder # # move source to folder, then folder/source$ mv-i source folder # # when moved, prompt * * whether to overwrite * * $mv source dest # # if the file already exists, rename source to destcat on the premise that source is not a directory

Cat is used to output the contents of the file to Terminal.

$cat / etc/locale.gen # output the contents of locale.gen $cat-n / etc/locale.gen # output the contents of locale.gen and display the line number more

More is similar to cat in that you can view the contents of a file, except that when a document is too long, cat can only display the content that finally fills the screen, and the previous content is not visible. At this point, you can use more to display the content line by line.

$more / etc/locale.gen$ more + 100 / etc/locale.gen # display less from 100 lines

Less is similar to more, except that less supports scrolling up and down, while more only supports line-by-line display.

$less / etc/locale.gen$ less + 100 / etc/locale.gennano

Nano is a simple and practical text editor that is easy to use.

Edit the filename file $nano filename # #. If the file does not exist, open a new file. If you save it when you exit, create the file.

After editing, ctrl + X prompts you whether to save or not, press y to confirm saving.

Note: you can use ctrl + G to get help during use.

Reboot

Reboot is the restart command.

# reboot # the difference between'$'and' #'is that'$'can be executed by ordinary users # while' # 'can only be executed by root users, or ordinary users use' sudo'poweroff'

Poweroff is the shutdown command.

# poweroff # turn off the ping immediately

Ping is mainly used to test network connectivity, by sending packets to the target machine to test whether the two hosts are connected and the delay.

$ping locez.com # through the domain name ping, if DNS is not set up May not be able to ping $ping linux.cnPING linux.cn (211.157.2.94) 56 (84) bytes of data.64 bytes from 211.157.2.94.static.in-addr.arpa (211.157.2.94): icmp_seq=1 ttl=53 time=41.5 ms64 bytes from 211.157.2.94.static.in-addr.arpa (211.157.2.94): icmp_seq=2 ttl=53 time=40.4 ms64 bytes from 211.157.2.94.static.in-addr.arpa 211.157.2.94): icmp_seq=3 ttl=53 time=41.9 Ms ^ C-linux.cn ping statistics-3 packets transmitted 3 received, 0% packet loss, time 2002msrtt min/avg/max/mdev = 40.406 time 2002msrtt min/avg/max/mdev 41.287 + 41.931 + + 0.644 ms$ ping 211.157.2.94 # through the IP address ping If you can't ping, there may be a problem with the network connection, grep.

Grep is mainly used to return matching items and supports regular expressions.

$grep PATTERN filename # return all lines with PATTERN $grep zh_CN / etc/locale.gen # return all lines with zh_CN mount

Mount is used to mount a file system and needs to be executed by the root user. A disk can be divided into several partitions, on which a file system can be created, and a mount point provides an entry to mount the file system of a partition to a directory, which is called a mount point. and the contents of the file system can be accessed through this mount point.

For example, a hard disk is represented as / dev/sda in Linux, then the partition on it should be represented as / dev/sda1, / dev/sda2.

# mount # output the current mount information of the system # mount / dev/sda1 / mnt # Mount the sda1 to / mnt # cd / mnt # access the content # mount-o remount directly through / mnt Rw / mnt # Mount sda1 to / mnt and set it to read / write # mount-a # mount the file system configured by the fstab file

Umount

Umount, in contrast to mount, unloads a mount point, that is, cancels the entry.

# umount / mnt # unmount the file system at the mount point / mnt # umount-a # unmount all mounted file systems tar

Tar is mainly used to create and decompress archive files. It has no compression function, but it can be compressed by calling gzip and bzip2. Parameter explanation:

-c create archive-x extract archive-v display process-f target file, followed by target file-j call bzip2 to extract-z call gzip to extract-t list the file $tar-cvf filename.tar in the archive. # Archive all files in the current directory, but do not compress them. Note that there is a'. 'after it, which cannot be omitted, which represents the meaning of the current directory $tar-xvf filename.tar # decompress filename.tar to the current folder $tar-cvjf filename.tar.bz2. # use bzip2 to compress $tar-xvjf filename.tar.bz2 # extract filename.tar.bz2 to the current folder $tar-cvzf filename.tar.gz # use gzip to compress $tar-xvzf filename.tar.gz # extract filename.tar.gz to the current folder $tar-tf filename # only view files in the filename archive, not ln

Ln is mainly used to create links in two files, which are divided into Hard Links (hard links) and Symbolic Links (symbolic links or soft links), where the default is to create hard links and the-s parameter is used to specify soft links.

Hard links are mainly to increase the number of links to a file, as long as the number of links in the file is not 0, the file will not be physically deleted, so delete a file with multiple hard links, must delete all its hard links can be deleted. To put it simply, a soft link creates a similar shortcut to a file, through which you can access the file and modify it, but it does not increase the number of links to the file, and deleting a soft link does not delete the source file. even if the source file is deleted, the soft link exists, and when a source file with the same name is recreated, the soft link points to the newly created file. Hard links can only link two files, not directories, while soft links can link directories, so soft links are very flexible. $ln source dest # create a hard link named dest for source $ln-s source dest # create a soft link chown named dest for source

Chown is used to change the owner and group of a file.

# chown user filename # change the owner of filename to user# chown user:group filename # change the owner of filename to user, and change the group to group# chown-R root folder # change the owner of folder folder and its child files to rootchmod

Chmod always changes the permissions of a file, mainly read, write, execute, three of which are owner, user group, and others, so ls-l can see the following information

-rwxr--r-- 1 locez users 154 Aug 30 18:09 filename

Among them r=read, w=write, x=execute

# chmod + x filename # add execution permissions for user, group, others # chmod-x filename # cancel execution permissions for user, group, others # chmod + w filename # add write permissions for user # chmod ugo=rwx filename # set user, group, others with read, write and execute permissions # chmod ug=rw filename # set user Group add read and write permissions # chmod ugo=--- filename # cancel all permissions useradd

Useradd is used to add a normal user.

# useradd-m-g users-G audio-s / usr/bin/bash newuser #-m create the home directory,-g belongs to the main group,-G specifies the additional groups in which the user belongs,-s sets the default shell, and newuser is the new user name passwd

Passwd is used to change the user's login password.

$passwd # change the current user password without parameters # passwd newuser # change the user password whereis of the above newly created newuser

Whereis is used to find files, manuals, and so on.

$whereis bashbash: / usr/bin/bash / etc/bash.bashrc / etc/bash.bash_logout / usr/share/man/man1/bash.1.gz / usr/share/info/bash.info.gz$ whereis-b bash # find binarybash: / usr/bin/bash / etc/bash.bashrc / etc/bash.bash_logout$ whereis-m bash # find manualbash: / usr/share/man/man1/bash.1.gz / usr/share/info/bash.info.gzfind only

Find is also used to find files, but it is more powerful, supports regularity, and can pass the results of the search to other commands.

$find. -name PATTERN # # find PATTERN-compliant files from the current directory $find / home-name PATTERN-exec ls-l {} /; # find all PATTERN-compliant files from / home file and ask ls to output details wget

Wget is a download tool, simple and powerful.

$wget-O newname.md https://github.com/LCTT/TranslateProject/blob/master/README.md # download the README file and rename it to newname.md$ wget-c url # # download url and open the breakpoint to resume upload on "what are the necessary Linux commands for beginners". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report