Linux common commands (Must SEE)

Source: Internet
Author: User
Tags create directory gpg touch command android games

1. ls command
The LS command is the meaning of listing directory contents (list directory Contents). Running it is to list the contents of a folder, possibly a file or a folder.
[Email protected]:~# ls
Android-games Music
Pictures Public
Desktop tecmint.com
Documents Tecmint-sync
Downloads Templates

The "ls-l" command lists the contents of the folder in detail mode (long listing fashion).
[Email protected]:~# ls-l
Total 40588
Drwxrwxr-x 2 ravisaive ravisaive 4096 8 01:06 Android Games
Drwxr-xr-x 2 ravisaive ravisaive 4096 may 10:50 Desktop
Drwxr-xr-x 2 ravisaive ravisaive 4096 may 16:45 Documents
Drwxr-xr-x 6 ravisaive ravisaive 4096 14:34 Downloads
Drwxr-xr-x 2 ravisaive ravisaive 4096 APR 20:50 Music
Drwxr-xr-x 2 ravisaive ravisaive 4096 May 9 17:54 Pictures
Drwxrwxr-x 5 ravisaive ravisaive 4096 May 3 18:44 tecmint.com
Drwxr-xr-x 2 ravisaive ravisaive 4096 APR 20:50 Templates

The "ls-a" command lists everything in the folder, including the following "." The hidden file at the beginning.
[Email protected]:~# 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 files are "." The beginning is the hidden file, and each file, folder, device or command is treated as a file. ls-l command output:
D (represented by the directory).
Rwxr-xr-x is the permission of a file or directory to the owning user, the same set of users, and other users.
The first ravisaive in the above example indicates that the file belongs to the user ravisaive
The second ravisaive in the above example indicates 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.
The last one is the name of the file/folder
2. lsblk command
"Lsblk" is the list of block devices. In addition to RAM, the block device is displayed neatly in a standard tree-like output format.
[Email protected]:~# lsblk
NAME maj:min RM SIZE RO TYPE mountpoint
SDA 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/personal
Sr0 11:0 1 1024M 0 rom

The "lsblk-l" command displays block devices in list format (not tree format).
[Email protected]:~# lsblk-l
NAME maj:min RM SIZE RO TYPE mountpoint
SDA 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/personal
Sr0 11:0 1 1024M 0 rom
Note: LSBLK is the most useful and easiest way to learn the name of a newly inserted USB device, especially when you are working on a disk/block device on a terminal.
3. md5sum command
"Md5sum" is to calculate and verify the MD5 information signature. MD5 checksum (often called hashing) uses the integrity of files that match or validate files, because files can change due to transmission errors, disk errors, or non-malicious interference.
[Email protected]:~# md5sum Teamviewer_linux.deb

47790ed345a7b7970fc1f2ac50c97002 Teamviewer_linux.deb
Note: Users can use the official provided and md5sum to generate signature information to detect whether the file has changed. Md5sum is not sha1sum safe, we will discuss this later.
4. DD Command
The "DD" command represents the conversion and copying of files. can be used to convert and copy files, most of the time is used to copy the ISO file (or any other file) to a USB device (or any other place) to go, so can be used to make USB launcher.
[Email protected]:~# 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, avoid.
The DD command consumes a few seconds to a few minutes 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 shorthand for UNIX name. Displays the machine name, operating system, and kernel details.
[Email protected]:~# uname-a
Linux tecmint 3.8.0-19-generic #30-ubuntu SMP Wed May 1 16:36:13 UTC a i686 i686 i686 gnu/linux
Note: uname displays the kernel category, Uname-a displays details. The above output details the Uname-a
"Linux": the 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 a historical record. It shows the history of all commands executed in the terminal.
[Email protected]:~# 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
Ten pwd
CD && sudo cp-r unity/6/usr/share/unity/
cd/usr/share/unity/icons/
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 ': ifconfig
7. sudo command
The "sudo" (Super User Do) command allows authorized users to execute commands from Superuser or other users. specified by the security policy in the Sudoers list.
[Email protected]:~# sudo add-apt-repository ppa:tualatrix/ppa
Note: sudo allows users to borrow superuser privileges, whereas the "su" command actually allows the user to log on as a superuser. So sudo is more secure than Su.
It is not recommended to use sudo or su for everyday use, as it can cause serious errors if you accidentally do something wrong, which is why the Linux community is popular with a word:
"To err are human, but to really foul up everything, you need root password."
"Err can have no, but the root password is really a hopeless." ”
8. mkdir command
The Make Directory command creates a new directory under the named Path (mkdir). However, if the directory already exists, it will return an error message "Cannot create a folder, the folder already exists" ("Cannot create folder, folders already exists")
[Email protected]:~# mkdir Tecmint
Note: A directory can only be created if the user has write access to the directory. mkdir: Could not create directory ' Tecmint ' because the file already exists. (The above output is not to be confused by the file, you should remember what I said at the beginning-in Linux, files, folders, drivers, commands, scripts are treated as files)
9. Touch Command
The "Touch" command represents the update of the file's access and modification times to the current time. The touch command will only be created when the file does not exist. If the file already exists, it updates the timestamp, but does not change the contents of the file.
[Email protected]:~# Touch Tecmintfile
Note: Touch can be used to create a nonexistent file in a directory where the user has write permissions.
chmod Command
The "chmod" command is to change the file's mode bit. 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 the file (folder or other, for simplicity, we use the file)
Read (R) =4
Write (W) =2
Execute (x) =1
So if you want to give the file read-only permission, set to ' 4 '; write-only permission, set the permission to ' 2 '; Execute permission only, set to 1; Read and Write permissions, that is 4+2 = 6, and so on.
Now you need to set up 3 user and user group permissions. The first one is the owner, then the user's group, and finally the other user.
Rwxr-x--x abc.sh
The root privilege here is rwx (read and write and Execute permissions),
The owning user group permission is r-x (only read and execute permissions, no write permission),
For other user rights is-X (only Execute permissions)
In order to change its permissions, the owner, the user group and other users to provide read, write, execute permissions.
[Email protected]:~# chmod 777 abc.sh
Three are only read and write access
[Email protected]:~# chmod 666 abc.sh
The owner user has read-write and Execute permissions, and the user's group and other users have only executable permissions
[Email protected]:~# chmod 711 abc.sh
Note: This command is one of the most useful commands for system administrators and users. In a multiuser environment or server, for a user, if the file is set is not accessible, then this command can be resolved, if the wrong permissions are set, then provides for authorized access.
One . chown command
The "chown" command changes the owner of the file and the user group. Each file belongs to one user group and one user. In your directory, use "Ls-l" and you will see something like this.
[Email protected]:~# ls-l
Drwxr-xr-x 3 server root 4096 11:14 Binary
Drwxr-xr-x 2 Server server 4096 may 09:42 Desktop
Here, the directory binary belongs to the user "server", and the user group "root", and the Directory "Desktop" belongs to the user "server" and the user group "server"
The "chown" command is used to change the ownership of a file, so only the user and user groups that administer and provide the files are authorized.
[Email protected]:~# chown server:server Binary
Drwxr-xr-x 3 Server server 4096 may 11:14 Binary
Drwxr-xr-x 2 Server server 4096 may 09:42 Desktop
Note: The files given by "Chown" change the ownership of users and groups to new owners or existing users or groups of users.
apt Command
The Debian series is based on the "apt" command and "Apt" represents the advanced package Tool. APT is an advanced Package manager developed for the Debian series system (Ubuntu,kubuntu, etc.), on the Gnu/linux system, which automatically and intelligently searches, installs, upgrades and resolves dependencies for packages
[Email protected]:~# apt-get Install MPlayer
Reading Package Lists ... Done
Building Dependency Tree
Reading state information ... Done
The following package were automatically installed and is no longer required:
Java-wrappers
Use the ' Apt-get autoremove ' to remove it.
The following extra packages'll be installed:
Esound-common libaudiofile1 libesd0 libopenal-data libopenal1 libsvga1 libvdpau1 Libxvidcore4
Suggested Packages:
Pulseaudio-esound-compat libroar-compat2 nvidia-vdpau-driver vdpau-driver mplayer-doc netselect fping
The following NEW packages'll be installed:
Esound-common libaudiofile1 libesd0 libopenal-data libopenal1 libsvga1 libvdpau1 libxvidcore4 mplayer
0 upgraded, 9 newly installed, 0 to remove and 8 not upgraded.
Need to get 3,567 KB of archives.
After this operation, 7,772 KB of additional disk space would be used.
Want to continue [y/n]? Y

[Email protected]:~# apt-get Update
Hit Http://ppa.launchpad.net raring RELEASE.GPG
Hit Http://ppa.launchpad.net raring RELEASE.GPG
Hit Http://ppa.launchpad.net raring RELEASE.GPG
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 cause a change in the system as a whole, so you need the root password (check the prompt for "#" instead of "$"). Apt is more advanced and intelligent than Yum commands.
See Apt-cache, which is used to search whether packages contain child packages MPlayer, Apt-get is used to install, upgrade all installed packages to the latest version.
For more information about the Apt-get and Apt-cache commands, see the Apt-get and Apt-cache commands
tar command
The "tar" command is a tape archive (Tape Archive), which is useful for archiving and extracting files that are created.
[Email protected]:~# tar-zxvf abc.tar.gz (remember ' Z ' stands for. tar.gz)
[Email protected]:~# tar-jxvf abc.tar.bz2 (Remember ' j ' stands for. tar.bz2)
[Email protected]:~# tar-cvf archieve.tar.gz (. bz2)/PATH/TO/FOLDER/ABC
Note: "tar.gz" represents the use of gzip archive, "bar.bz2" is compressed using bzip, it compresses better but also slower.
To learn more about the tar command example, see the example tar name
The . Cal Command
Cal (Calender), which is used to display the month in the current month or in the future or any year in the past.
[Email protected]:~# cal
May 2013
Su Mo Tu We Th Fr Sa
1 2 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
Show the past month, February 1835
[Email protected]:~# cal 02 1835

February 1835
Su Mo Tu We Th Fr Sa
1 2 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
Show the next month, July 2145.

[Email protected]:~# cal 07 2145
July 2145
Su Mo Tu We Th Fr Sa
1 2 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
Note: You do not need to back-tune the calendar 50, neither to calculate the day of your birth, nor to calculate the day when your birthday arrives, [because its smallest unit is the month, not the day].
The . Date command
The "date" command prints the current date and time using standard output, or it can be set in depth.
[Email protected]:~# Date
Fri 14:13:29 IST 2013
[Email protected]:~# date--set= ' 2013 13:57 '
Mon May 13:57:00 IST 2013
Note: This command is useful in scripting and is more perfect for time-and date-based scripting. Change the date and time in the terminal to make you more professional! (You need root privileges to operate this, because it is a whole system change)
. Cat Commands
"Cat" stands for Nexus (concatenation), connects two or more text files, or prints the contents of a file in standard output form.
[Email protected]:~# cat a.txt b.txt c.txt d.txt abcd.txt
[Email protected]:~# cat Abcd.txt
....
Contents of file ABCD
...
Note: ">>" and ">" Call the Append symbol. They are used to append to the file instead of being displayed on the standard output. The > symbol deletes the existing file and then creates a new file. So for security reasons, it is recommended to use ">>", which will be written to the file instead of overwritten or deleted.
Before delving deeper, I must let you know the wildcard character (you should know the wildcard character, which appears in most TV draft). Wildcards are a feature of the shell, and it makes 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. It may seem simple, but in fact, it's frustrating!
For example, if you have a directory with lots and lots of different types of files and subdirectories, then you decide to move all the HTML files that contain the word "Linux" in the file name to another directory. How to do this in a simple way? If the directory contains a large number of different names of HTML files, your task is huge, not simple.
In the Linux CLI, this task is simple, just like moving only one HTML file, because there are shell wildcard characters, it is so simple. These are special characters that allow you to choose a file name that matches a certain character pattern. It helps you to choose, even if there are only a few characters in a large number of filenames, and in most cases it is easier than using the mouse to select files.
Here is a list of common wildcard characters:
Wildcard Matches
* 0 or more characters
? Exactly one character
[ABCDE] Exactly one of the characters in the enumeration
[A-e] exactly one character in the given range
[!ABCDE] Any character is not listed
[!A-E] Any character is not in the given range
{Debian,linux} exactly one whole word in the given option
! It's called non-band '! ' The inverse string is true
. CP Command
"Copy" is the copy. It copies one file from one place to another.
[Email protected]:~# cp/home/user/downloads abc.tar.gz/home/user/desktop (Return 0 when sucess)
NOTE: CP, which is the most common command in a shell script, can be used to customize the copy of the required files using wildcards (described in the previous section).
MV Command
The "MV" command moves a local file to another location.
[Email protected]:~# mv/home/user/downloads abc.tar.gz/home/user/desktop (Return 0 when sucess)
Note: The MV command can be used with wildcard characters. The MV needs to be used with caution because moving or unauthorized files can lead to security issues and may crash the system.
. PWD command
"PWD" (print working directory), which displays the full path of the current working directory in the terminal.
[Email protected]:~# pwd
/home/user/desktop
Note: This command is not used frequently in scripts, but for beginners, it is definitely a lifesaver when you get lost in the terminal after a long time from connecting to Nux.
. CD command
Finally, the frequently used "CD" command represents a change of directory. It changes the working directory in the terminal to perform, copy, move, read, write, and so on.
[Email protected]:~# cd/home/user/desktop
[Email protected]:~$ pwd
/home/user/desktop

Note: When you switch directories in the terminal, the CD is on. "CD ~" Changes the working directory to the user's home directory, and is useful when users find themselves missing a path in the terminal. "CD.." Switches from the current working directory to the parent directory (the current working directory).

21st.


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.