Basic Linux command usage example

When you enter the world of Linux, after installing a certain Linux distribution, experiencing the Linux desktop and installing some software you love and need, you should understand the real charm of Linux [command line]. Every Linux command is actually a program. With these commands, we can do a lot of things. The following small series of Brothers Education www.lampbrother.net will introduce some common basic commands to you. 

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

poweroff
poweroff is the shutdown command.
# poweroff ### Shut down immediately

ping
ping is mainly used to test network connectivity, by sending data packets to the target machine to test whether the two hosts are connected, and the delay.
$ ping locez.com ### Ping through the domain name, if DNS is not set, it may not be able to ping
$ ping linux.cn
PING 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 ms
64 bytes from 211.157.2.94.static.in-addr.arpa (211.157.2.94): icmp_seq=2 ttl=53 time=40.4 ms
64 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 2002ms
rtt min/avg/max/mdev = 40.406/41.287/ 41.931/0.644 ms
$ ping 211.157.2.94 ### Ping by IP address. If the ping fails, 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 ### Returns all lines containing PATTERN
$ grep zh_CN /etc/locale.gen ### Returns all lines containing 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, a file system can be created on the partition, and a mount point is to provide an access 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, if a hard disk is represented as /dev/sda in Linux, the partitions on it should be represented as /dev/sda1 and /dev/sda2.
# mount ### Output the current mount information of the system
# mount /dev/sda1 /mnt ### Mount sda1 to /mnt
# cd /mnt ### Access content directly through /mnt
# mount -o remount, rw /mnt ### Remount sda1 to /mnt and set it to read-write
# mount -a ### Mount the file system configured by the fstab file

umount
umount is the opposite of mount, it unmounts a mount point, that is, cancels the entrance.
# umount /mnt ### Unmount the file system of this mount point /mnt
# umount -a ### Unmount all mounted file systems

tar
tar is mainly used to create archive files, and decompress archive files, which itself is not Compression function, but can call gzip, bzip2 for compression.

Parameter explanation:
-c create archive
-x decompress archive
-v display process
-f target file, which must be followed by target file
-j call bzip2 for decompression
-z call gzip to decompress
-t list the files in the archive
$ tar -cvf filename.tar . ### Archive all files in the current directory, but do not compress, note that there is a '.' behind, which cannot be omitted, representing the current The meaning of the directory
$ tar -xvf filename.tar ### Extract filename.tar to the current folder
$ tar -cvjf filename.tar.bz2 . ### Compress using bzip2
$ tar -xvjf filename.tar.bz2 ### Extract filename.tar.bz2 to current folder
$ tar -cvzf filename.tar.gz ### Compress with gzip
$ tar -xvzf filename.tar.gz ### Extract filename.tar.gz to current folder
$ tar -tf filename ### Only view the files in the filename archive, not decompress

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), among which the default To create a hard link, use the -s parameter to specify the creation of a soft link.

Hard links are mainly to increase the number of links of a file. As long as the number of links of the file is not 0, the file will not be physically deleted. Therefore, to delete a file with multiple hard links, all its hard links must be deleted. Can be deleted.
A soft link simply creates a shortcut-like thing for a file, through which the file can be accessed and modified, but the number of links in the file will not be increased. Deleting a soft link will not delete the source file, even if the source The file is deleted, and the soft link exists. 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, and 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 named dest for source

chown
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 group to group
# chown -R root folder ### Change the folder and its subfolders The owner of the file is root

chmod
chmod changes the permissions of a file forever, there are mainly three permissions: read, write, execute, of which the owner, user group, and others each occupy three, so ls -l can see as follows info
-rwxr--r-- 1 locez users 154 Aug 30 18:09 filename
where r=read, w=write, x=execute
# chmod +x filename ### Add execute permission for user, group, others
# chmod -x filename ### Cancel the execution permission of user, group, others
# chmod +w filename ### Add write permission for user
# chmod ugo=rwx filename ### Set user, group, others to have read, write and execute permissions
# chmod ug=rw filename ### Set user, group to 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 creates the home directory, -g is the main group to which it belongs, -G specifies which additional groups the user is in, -s sets the default shell, newuser is the new user name

passwd
passwd is used to change the user login password.
$ passwd ### Change the current user password without parameters
# passwd newuser ### Change the user password of the new user above

whereis
whereis is used to find files, manuals, etc.
$ whereis bash
bash: /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 only binary
bash: /usr/bin/bash /etc/bash.bashrc /etc/bash.bash_logout
$ whereis -m bash ### Find only manual
bash: /usr/share/man/ man1/bash.1.gz /usr/share/info/bash.info.gz

find
find is also used to find files, but is more powerful, supports regular expressions, and can pass find results 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 the /home file and send them to ls for 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 README file and rename to newname.md
$ wget -c url ### Download url and open Continuing from a Breakpoint

Congratulations , you have learned the basic Linux commands with Xiaobian. Although these are just some of the most basic commands, mastering these commands will take your first step from a Linux novice to a Linux expert!

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326692375&siteId=291194637