20 useful commands for beginners of CentOS

Source: Internet
Author: User
Tags touch command

20 useful commands for beginners of CentOS

Are you planning to switch from Windows to Linux, or are you just switching to Linux? Alas !!! What am I talking about? Why are you in my world. From my past experience, I was shocked when I first started using Linux, commands, terminals, and so on. I am worried about how many commands I should remember to help me complete all the tasks. Without a doubt, online documents, books, man pages, and communities have helped me a lot, but I still firmly believe that there is an article that records how to learn and understand commands in a simple way. This inspires me to master Linux and make it easy to use. This article is the ladder to it.

1. ls command

The ls command is used to List Directory Contents (List Directory Contents. Running it is to list the content in the folder, which may be a file or a folder.

root@tecmint:~# lsAndroid-Games                     MusicPictures                          PublicDesktop                           Tecmint.comDocuments                         TecMint-SyncDownloads                         Templates

The "ls-l" command lists the contents of folders in detail mode (long listing fashion.

root@tecmint:~# ls -ltotal 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 all contents in the folder, including hidden files starting.

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, files starting with "." are hidden files, and each file, folder, device, or command is treated as files. Ls-l command output:

  1. D (indicates a directory ).
  2. Rwxr-xr-x is the permission of the user to which the file or directory belongs, the same group of users and other users.
  3. In the preceding example, the first ravisaive indicates that the file belongs to the user ravisaive.
  4. In the preceding example, the second ravisaive represents the file that belongs to the user group ravisaive.
  5. 4096 indicates that the file size is 4096 bytes.
  6. May 8 represents the last modification date and time of the file.
  7. The last step is the file/folder name.

For more "ls" examples, refer to the ls command instance in linux 15.

2. lsblk command

Lsblk is used to list Block devices. In addition to RAM, Block devices are displayed neatly in the standard tree output format.

root@tecmint:~# lsblkNAME   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 the List format (instead of in the tree format ).

root@tecmint:~# lsblk -lNAME 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 /bootsda6   8:6    0   3.7G  0 part [SWAP]sda7   8:7    0  93.1G  0 part /datasda8   8:8    0  89.2G  0 part /personalsr0   11:0    1  1024M  0 rom

Note: lsblk is the most useful and simple way to understand the name of the newly inserted USB device, especially when you process disks/Block devices on the terminal.

3. md5sum command

"Md5sum" is used to calculate and verify the MD5 information signature. Md5 checksum (usually called hash) uses to match or verify the integrity of the file, because the file may change due to transmission errors, disk errors, or malicious interference.

root@tecmint:~# md5sum teamviewer_linux.deb 47790ed345a7b7970fc1f2ac50c97002  teamviewer_linux.deb

Note: You can use the official and md5sum pairs to generate signature information to check whether the file has changed. Md5sum does not have sha1sum security, which we will discuss later.

4. dd command

The "dd" command represents the conversion and copying of files. It can be used to convert and copy files. Most of the time it is used to copy iso files (or any other files) to a usb device (or any other place), so it can be used to create a USB initiator.

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 disk name with caution.

The dd command consumes several seconds to several minutes according to the file size and type, as well as the read/write speed of the usb device.

5. uname command

The "uname" command is short for Unix Name. Displays the machine name, operating system, and kernel details.

root@tecmint:~# uname -aLinux tecmint 3.8.0-19-generic #30-Ubuntu SMP Wed May 1 16:36:13 UTC 2013 i686 i686 i686 GNU/Linux

Note: uname indicates the kernel category, and uname-a indicates the details. The above output details the uname-

  1. "Linux": the kernel name of the machine
  2. "Tecmint": the node name of the machine
  3. "3.8.0-19-generic": kernel version released
  4. "# 30-Ubuntu SMP": kernel version
  5. "I686": Processor Architecture
  6. "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.

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: press CTRL + R to search for executed commands, which can be automatically completed when you write commands.

(reverse-i-search)`if': ifconfi
7. sudo command

The "sudo" (super user do) command allows authorized users to execute commands of super users or other users. You can specify the security policy in the sudoers list.

root@tecmint:~# sudo add-apt-repository ppa:tualatrix/ppa

Note: sudo allows users to borrow superuser permissions. However, the "su" Command actually allows users to log on as superusers. Therefore, sudo is safer than su.
We do not recommend that you use sudo or su to handle routine usage, because it may cause serious errors. If you accidentally do something wrong, this is why a popular sentence is in the linux community:

"To err is human, but to really foul up everything, you need root password ."

"No one can beat it, but having a root password is a real battle ." # Translation
8. mkdir command

The "mkdir" (Make directory) command creates a new directory under the named path. However, if the directory already exists, it will return an error message "folder cannot be created and folder already exists" ("cannot create folder, folder already exists ")

root@tecmint:~# mkdir tecmint

Note: A directory can only be created under a directory with write permission. Mkdir: you cannot create the 'cmint' directory because the file already exists. (The above output should not be confused by files. You should remember what I said at the beginning-in linux, files, folders, drivers, commands, and scripts are regarded as files)

9. touch command

The "touch" command updates the file access and modification time to the current time. The touch command creates a file only when the file does not exist. If the file already exists, it updates the timestamp but does not change the file content.

root@tecmint:~# touch tecmintfile

Note: touch can be used to create a non-existent file in a directory with write permission.

10. chmod command

The "chmod" command is to change the mode bit of the file. Chmod changes the file mode (permission) of each given file, folder, script, and so on according to the required mode ).

In the file (folder or other, for simplicity, we use the file), there are three types of permissions.

Read (r)=4Write(w)=2Execute(x)=1

Therefore, if you want to grant the File Read-Only permission, set it to '4'; write-only permission, set it to '2'; execute-only permission, set it to 1; read-write permission, 4 + 2 = 6, and so on.

Now you need to set three types of user and user group permissions. The first is the owner, the group where the user is located, and the last is other users.

rwxr-x--x   abc.sh

Here, the root permission is rwx (read/write and execution permissions ),
The User Group permission is r-x (only read and execution permissions, no write permission ),
For other users, the permission is-x (only the execution permission is allowed)

To change its permissions, read, write, and execute permissions are granted to the owner, user group, and other users.

root@tecmint:~# chmod 777 abc.sh

All three methods have read and write permissions.

root@tecmint:~# chmod 666 abc.sh

The owner user has the read/write and execution permissions. the user's group and other users only have the executable permissions.

root@tecmint:~# chmod 711 abc.sh

Note: This command is one of the most useful commands for System Administrators and Users. For a user in a multi-user environment or server, if the file is set to inaccessible, this command can be solved. If the wrong permission is set, therefore, authorized access is provided.

11. chown command

The "chown" command is to change the file owner and user group. Each file belongs to one user group and one user. Using "ls-l" in your directory, you will see something like this.

root@tecmint:~# ls -l drwxr-xr-x 3 server root 4096 May 10 11:14 Binary drwxr-xr-x 2 server server 4096 May 13 09:42 Desktop

Here, the directory Binary belongs to the user "server", and the user group "root", while the directory "Desktop" belongs to the user "server" and user group "server"

The "chown" command is used to change the ownership of a file, so it is only used to manage and provide file users and user group authorization.

root@tecmint:~# chown server:server Binarydrwxr-xr-x 3 server server 4096 May 10 11:14 Binary drwxr-xr-x 2 server server 4096 May 13 09:42 Desktop

Note: The file "chown" changes the ownership of users and groups to the new owner or existing users or user groups.

12. 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 Debian systems (Ubuntu, Kubuntu, and so on). On Gnu/Linux systems, APT automatically and intelligently searches and installs packages, upgrade and resolve dependencies.

root@tecmint:~# apt-get install mplayerReading package lists... DoneBuilding dependency tree       Reading state information... DoneThe following package was automatically installed and is no longer required:  java-wrappersUse 'apt-get autoremove' to remove 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 to remove and 8 not upgraded.Need to get 3,567 kB of archives.After this operation, 7,772 kB of additional disk space will be used.Do you want to continue [Y/n]? y
root@tecmint:~# apt-get updateHit 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 change the overall system, so the root password is required (check the prompt as "#" instead of "$ "). apt is more advanced and intelligent than yum commands.

As you can see, apt-cache is used to search for whether the package contains the sub-package mplayer. apt-get is used to install and upgrade all installed packages to the latest version.

For more information about apt-get and apt-cache commands, see 25 APT-GET and APT-CACHE commands.

13. tar command

The "tar" command is a Tape Archive (Tape Archive), which is useful for archiving and extracting some files.

Root @ tecmint :~ # Tar-zxvf abc.tar.gz ('z' represents .tar.gz)
Root @ tecmint :~ # Tar-jxvf abc.tar.bz2 ('j' represents .tar.bz2)
root@tecmint:~# tar -cvf archieve.tar.gz(.bz2) /path/to/folder/abc

Note: "tar.gz" indicates the use of gziparchive, because bar.bz2 "is compressed using bzip, which is better but slower.

For more examples of "tar commands", refer to the 18 Tar naming example.

14. cal command

Calender 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            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, January 1, February 1835

root@tecmint:~# 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

Shows the month to come, January 1, July 2145.

root@tecmint:~# 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 adjust the calendar for 50 years. You do not need to calculate the date of birth or the date of your birthday, because the minimum unit is month, instead of day].


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.