In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >
Share
Shulou(Shulou.com)06/01 Report--
Editor to share with you what are the 20 commands commonly used in linux. I hope you will get something after reading this article. Let's discuss it together.
What is Linux system Linux is a free-to-use and free-spread UNIX-like operating system, is a POSIX-based multi-user, multi-task, multi-threaded and multi-CPU operating system, using Linux can run major Unix tools, applications and network protocols.
20 commonly used commands: ls, lsblk, md5sum, dd, uname, history, sudo, mkdir, touch, chmod, chown, apt, tar, cal, date, cat, cp, mv, pwd, cd.
The operating environment of this tutorial: Red Hat Enterprise Linux 6.1 system, Dell G3 computer.
1. Ls command
The ls command means to list the contents of the directory (List Directory Contents). To run it is to list the contents of a folder, either a file or a folder.
Root@tecmint:~# ls Android-Games MusicPictures PublicDesktop Tecmint.comDocuments TecMint-SyncDownloads Templates
The "ls-l" command lists the contents of the folder in long listing fashion mode.
Root@tecmint:~# ls-l total 40588drwxrwxr-x 2 ravisaive ravisaive 4096 May 8 01:06 Android Gamesdrwxr-xr-x 2 ravisaive ravisaive 4096 May 15 10:50 Desktopdrwxr-xr-x 2 ravisaive ravisaive 4096 May 16 16:45 Documentsdrwxr-xr-x 6 ravisaive ravisaive 4096 May 16 14:34 Downloadsdrwxr-xr-x 2 ravisaive ravisaive 4096 Apr 30 20:50 Musicdrwxr-xr-x 2 ravisaive ravisaive 4096 May 9 17:54 Picturesdrwxrwxr-x 5 ravisaive ravisaive 4096 May 3 18:44 Tecmint .comdrwxr-xr-x 2 ravisaive ravisaive 4096 Apr 30 20:50 Templates
The "ls-a" command lists everything in the folder, including "." The hidden file at the beginning.
Root@tecmint:~# ls-a. .gnupg .dbus. Goutputstream-PI5VVW. Mission-control.adobe deja-dup .grsync .mozilla .themes.Gstreamer-0.10 .mtpaint .thumbnails. Gtk-bookmarks .thunderbird.HotShots .mysql _ history .htaccess. Apport-ignore.xml .ICEauthority .profile .bash _ history .icons .bash _ logout .fbmessenger.jedit .pulse .bashrc .liferea _ 1.8 . pulse-cookie .Xauthority .gconf .local .Xauthority.HGHVWW .cache.gftp .macromedia .remmina .cinnamon. Gimp-2.8.ssh. Xsession-errors .compiz .gnome teamviewer_linux.deb. Xsession-errors.old .config .gnome2 .zoncolor
Note: in Linux, the file is "." The beginning is to hide the file, and each file, folder, device or command is treated as a file. The output of the ls-l command:
D (represents a catalog).
Rwxr-xr-x is the permission of a file or directory to its own user, the same group of users, and other users.
In the above example, the first ravisaive represents that the file belongs to the user ravisaive
The second ravisaive in the above example represents that the file belongs to the user group ravisaive
4096 represents a file size of 4096 bytes.
May 8 01:06 represents the date and time when the file was last modified.
At the end is the name of the file / folder
For more "ls" examples, please see the ls command example in 15 linux.
2. Lsblk command
"lsblk" is a list of block devices. Display block devices neatly in a standard tree output format, except for RAM.
Root@tecmint:~# lsblk NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0 232.9G 0 disk ├─ sda1 8:1 0 46.6G 0 part / ├─ sda2 8:2 0 1K 0 part ├─ sda5 8:5 0 190M 0 part / boot ├─ sda6 8:6 0 3.7G 0 part [SWAP] ├─ sda7 8:7 0 93.1G 0 part / data └─ sda8 8:8 0 89.2G 0 part / personalsr0 11:0 1 1024M 0 rom
The "lsblk-l" command displays block devices in list format (instead of tree format).
Root@tecmint:~# lsblk-l NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINTsda 8:0 0232.9G 0 disksda1 8:1 046.6G 0 part / sda2 8:2 0 1K 0 partsda5 8:5 0190M 0 part / bootsda6 8:6 03.7G 0 part [SWAP] sda7 8:7 093.1G 0 part / datasda8 8:8 089.2G 0 part / personalsr0 11:0 1 1024M 0 rom
Note: lsblk is the most useful and easiest way to know the name of a newly inserted USB device, especially if you are dealing with disk / block devices on the terminal.
3. Md5sum command
"md5sum" is to calculate and verify the signature of MD5 information. Md5 checksum (often called hashing) uses to match or verify the integrity of a file, because the file may change due to transmission errors, disk errors, or no malicious interference.
Root@tecmint:~# md5sum teamviewer_linux.deb 47790ed345a7b7970fc1f2ac50c97002 teamviewer_linux.deb
Note: users can use the official and md5sum generated signature information pairs to detect whether the file has changed. Md5sum is not as secure as sha1sum, which we will discuss later.
4. Dd command
The "dd" command represents converting and copying files. Can be used to convert and copy files, most of the time is spent copying iso files (or any other file) to a usb device (or anywhere else), so it can be used to make USB initiators.
Root@tecmint:~# dd if=/home/user/Downloads/debian.iso of=/dev/sdb1 bs=512M; sync
Note: in the above example, the usb device is sdb1 (you should use the lsblk command to verify it, otherwise you will rewrite your disk or system), please use the name of the disk carefully.
The dd command takes from a few seconds to a few minutes to execute depending on the size and type of the file and the read and write speed of the usb device.
5. Uname command
The "uname" command is an abbreviation for Unix Name. Displays the machine name, operating system and kernel details.
Root@tecmint:~# uname-a Linux tecmint 3.8.0-19-generic # 30-Ubuntu SMP Wed May 1 16:36:13 UTC 2013 i686 i686 i686 GNU/Linux
Note: uname displays kernel categories and uname-a shows details. The above output details uname-a
"Linux": kernel name of the machine
"tecmint": the node name of the machine
"3.8.0-19-generic": kernel release version
"# 30-Ubuntu SMP": kernel version
"i686": processor architecture
"GNU/Linux": operating system name
6. History command
The "history" command is history. It shows the history of all commands executed in the terminal.
Root@tecmint:~# history 1 sudo add-apt-repository ppa:tualatrix/ppa 2 sudo apt-get update 3 sudo apt-get install ubuntu-tweak 4 sudo add-apt-repository ppa:diesch/testing 5 sudo apt-get update 6 sudo apt-get install indicator-privacy 7 sudo add-apt-repository ppa:atareao/atareao 8 sudo apt-get update 9 sudo apt-get install my-weather-indicator 10 pwd 11 cd & & sudo cp-r unity/6 / usr/share/unity/ 12 cd / usr/share/unity/icons/ 13 cd / usr/share/unity
Note: hold down "CTRL + R" to search for commands that have been executed, which can be automatically completed when you write commands.
(reverse-i-search) `if': ifconfig7. Sudo command
The "sudo" (super user do) command allows authorized users to execute commands from superusers or other users. Specified by the security policy in the sudoers list.
Root@tecmint:~# sudo add-apt-repository ppa:tualatrix/ppa
Note: sudo allows the user to borrow superuser permissions, while the "su" command actually allows the user to log in as superuser. So sudo is safer than su.
It is not recommended to use sudo or su for everyday use, as it can lead to serious errors if you accidentally do something wrong, which is why the saying is popular in the linux community:
"To err is human, but to really foul up everything, you need root password = people who are not saints are infallible, but if you have a root password, you will be doomed."
8. Mkdir command
The "mkdir" (Make directory) command creates a new directory under the named path. However, if the directory already exists, it returns an error message "cannot create folder, folder already exists" ("cannot create folder, folder already exists")
Root@tecmint:~# mkdir tecmint
Note: directories can only be created in directories where the user has write permissions. Mkdir: the directory `tecmint` cannot be created because the file already exists. (don't be confused by files in the output above, you should remember what I said at the beginning-in linux, files, folders, drivers, commands, scripts are all treated as files.)
9. Touch command
The "touch" command represents updating the access and modification time of the file to the current time. The touch command creates a file only if it does not exist. If the file already exists, it updates the timestamp, but does not change the contents of the file.
Root@tecmint:~# touch tecmintfile
Note: touch can be used to create files that do not exist in a directory where the user has write permissions.
10. Chmod command
The "chmod" command changes the mode bits of the file. Chmod will change the file mode (permissions) of each given file, folder, script, etc., according to the required mode.
There are 3 types of permissions in files (folders or other, let's use files for simplicity).
Read (r) = 4Write (w) = 2Execute (x) = 1
So if you want to give read-only permission to the file, set it to '4permission; write-only permission, set permission to' 2permission; execute-only permission, set to 1; read-write permission, which is 4percent 2 = 6, and so on.
Now you need to set up three kinds of user and group permissions. The first is the owner, then the group in which the user belongs, and finally the other users.
Rwxr-x--x abc.sh
Here the permission of root is rwx (read, write and execute permissions)
The permission of the user group is rmurx (only read and execute permissions, no write permissions)
For other users, the permission is-x (only execute permissions)
To change its permissions, read, write, and execute permissions are provided to the owner, the user's group, and other users.
Root@tecmint:~# chmod 777 abc.sh
All three have only read and write access.
Root@tecmint:~# chmod 666 abc.sh
The owner user has read, write and execute permissions, and the group in which the user belongs and other users only have executable permissions
Root@tecmint:~# chmod 711 abc.sh
Note: this command is one of the most useful commands for system administrators and users. In a multi-user environment or server, for a user, if the file is set to be inaccessible, then this command can solve the problem, and if the wrong permission is set, then authorized access is provided.
11. Chown command
The "chown" command is to change the owner and user group of the file. Each file belongs to a user group and a user. In your directory, use "ls-l" and you will see something like this.
Root@tecmint:~# ls-l drwxr-xr-x 3 server root 4096 May 10 11:14 Binarydrwxr-xr-x 2 server server 4096 May 13 09:42 Desktop
Here, the directory Binary belongs to user "server" and user group "root", while directory "Desktop" belongs to user "server" and user group "server"
The "chown" command is used to change the ownership of the file, so it is only used to manage and provide user and user group authorization for the file.
Root@tecmint:~# chown server:server Binarydrwxr-xr-x 3 server server 4096 May 10 11:14 Binarydrwxr-xr-x 2 server server 4096 May 13 09:42 Desktop
Note: the files given by "chown" change the ownership of users and groups to new owners or existing users or user groups.
12. Apt command
The Debian series is based on the "apt" command, and "apt" stands for Advanced Package Tool. APT is an advanced package manager developed for Debian series systems (Ubuntu,Kubuntu, etc.). On Gnu/Linux systems, it automatically and intelligently searches, installs, upgrades, and resolves dependencies for packages.
Root@tecmint:~# apt-get install mplayer Reading package lists... DoneBuilding dependency tree Reading state information... DoneThe following package was automatically installed and is no longer required: java-wrappersUse 'apt-get autoremove' toremove it.The following extra packages will be installed: esound-common libaudiofile1 libesd0 libopenal-data libopenal1 libsvga1 libvdpau1 libxvidcore4Suggested packages: pulseaudio-esound-compat libroar-compat2 nvidia-vdpau-driver vdpau-driver mplayer-doc netselect fpingThe following NEW packages will be installed: esound-common libaudiofile1 libesd0 libopenal-data libopenal1 libsvga1 libvdpau1 libxvidcore4 mplayer0 upgraded, 9 newly installed, 0 toremove and 8 not upgraded.Need to get 3567 kB of archives.After this operation 7772 kB of additional disk space will be used.Do you want to continue [Y/n]? Yroot@tecmint:~# apt-get update Hit http://ppa.launchpad.net raring Release.gpg Get:1 http://security.ubuntu.com raring-security Release.gpg [933 B] Hit http://in.archive.ubuntu.com raring Release.gpg Hit http://ppa.launchpad.net raring Release.gpg Get:2 http://security.ubuntu.com raring-security Release [40.8 kB] Ign http:// Ppa.launchpad.net raring Release.gpg Get:3 http://in.archive.ubuntu.com raring-updates Release.gpg [933 B] Hit http://ppa.launchpad.net raring Release.gpg Hit http:// In.archive.ubuntu.com raring-backports Release.gpg
Note: the above command will change the system as a whole, so the root password is required (see the prompt as "#" instead of "$"). Apt is more advanced and intelligent than the yum command.
See the meaning of the name, apt-cache is used to search whether the package contains the subpackage mplayer, and apt-get is used to install and upgrade all installed packages to the latest version.
For more information about the apt-get and apt-cache commands, see the 25 APT-GET and APT-CACHE commands
13. Tar command
The "tar" command is tape archiving (Tape Archive), which is useful for creating archives of files and decompressing them.
Root@tecmint:~# tar-zxvf abc.tar.gz (remember'z 'stands for .tar.gz) root@tecmint:~# tar-jxvf abc.tar.bz2 (remember' j' represents .tar.bz2) root@tecmint:~# tar-cvf archieve.tar.gz (.bz2) / path/to/folder/abc
Note: "tar.gz" represents the use of gzip archiving, and "bar.bz2" uses bzip compression, which compresses better but slower.
For more examples of "tar commands", please see 18 Tar naming examples
14. Cal command
"cal" (Calender), which is used to display the current month or the month in the future or any past year.
Root@tecmint:~# cal May 2013 Su Mo Tu We Th Fr Sa 12 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Shows the past month, February 1835
Root@tecmint:~# cal 02 1835 February 1835 Su Mo Tu We Th Fr Sa 12 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
Shows the future month, July 2145.
Root@tecmint:~# cal 07 2145 July 2145 Su Mo Tu We Th Fr Sa 12 3 45 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
Note: you don't have to go back and adjust the calendar for 50 years. You don't have to calculate the date of your birth or the date of your birthday, [because its smallest unit is the month, not the day].
15. Date command
The "date" command prints the current date and time using standard output, or you can set it in depth.
Root@tecmint:~# date Fri May 17 14:13:29 IST 2013root@tecmint:~# date-- set='14 may 2013 13 set='14 may 57 'Mon May 13 13:57:00 IST 2013
Note: this command is useful in scripts, and time-and date-based scripts are more perfect. And change the date and time in the terminal to make you more professional! (of course you need root permission to operate this, because it is a change in the system as a whole)
16. Cat command
"cat" stands for a Concatenation, connecting two or more text files or printing the contents of a file in standard output.
Root@tecmint:~# cat a.txt b.txt c.txt d.txt abcd.txtroot@tecmint:~# cat abcd.txt....contents of file abcd...
Note: ">" and ">" call the append symbol. They are used to append to the file rather than appear on the standard output. The ">" symbol deletes the existing file and then creates a new one. Therefore, for security reasons, it is recommended to use ">", which will be written to the file rather than overwritten or deleted.
Before I go any further, I have to let you know the wildcard (you should know the wildcard, which appears in most TV drafts). Wildcards are a feature of shell and make the command line more powerful than any GUI file manager! As you can see, in a graphics file manager, you want to select a large set of files, and you usually have to use your mouse to select them. This may seem simple, but in fact, it's very frustrating!
For example, suppose you have a directory with many, many types of files and subdirectories, and then you decide to move all HTML files with the word "Linux" in their filenames to another directory. How to do this simply? If the directory contains a large number of HTML files with different names, your task is huge, not simple.
In LInux CLI, this task is as simple as moving only one HTML file, which is so simple because of the wildcards of shell. These are special characters that allow you to choose a file name that matches a certain character pattern. It helps you choose, even if there are only a few characters in a large number of file names, and in most cases, it is easier than selecting files with the mouse.
Here is a list of common wildcards:
Wildcard Matches * zero or more characters? Exactly one character [abcde] A character in the enumeration [amure] happens to be a character in the given range [! abcde] none of the characters is in the enumeration [! Amure] any character is not in the given range {debian,linux} happens to be an entire word in the given option
! It's called Fei, with'!' The reverse string of is true
For more information, please read the instance of Linux cat command 13 in Linux cat command instance
17. Cp command
"copy" means copying. It copies a file from one place to another.
Root@tecmint:~# cp / home/user/Downloads abc.tar.gz / home/user/Desktop (Return 0 when sucess)
Note: cp is the most commonly used command in shell scripts, and it can use wildcards (described in the previous block) to customize the copy of the required files.
18. Mv command
The "mv" command moves files from one place to another.
Root@tecmint:~# mv / home/user/Downloads abc.tar.gz / home/user/Desktop (Return 0 when sucess)
Note: the mv command can use wildcards. Mv should be used with caution, because moving system or unauthorized files can not only cause security problems, but also cause system crashes.
19. Pwd command
"pwd" (print working directory), which displays the full path of the current working directory in the terminal.
Root@tecmint:~# pwd / home/user/Desktop
Note: this command is not often used in scripts, but for beginners, it is definitely a lifesaver when you lose your path in the terminal long after connecting to nux.
20. Cd command
Finally, the frequently used "cd" command represents changing directories. It changes the working directory in the terminal to perform, copy, move, read, write, and so on.
Root@tecmint:~# cd / home/user/Desktopserver@localhost:~$ pwd / home/user/Desktop
Note: cd is very good at switching directories in the terminal. "cd ~" changes the working directory to the user's home directory, and is very useful when the user finds that he has lost his path in the terminal. "cd." Change from the current working directory to the parent directory of the current working directory.
After reading this article, I believe you have a certain understanding of "what are the 20 commands commonly used in linux". If you want to know more about it, you are welcome to follow the industry information channel. Thank you for reading!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.