Summary of common Linux commands and shortcut keys

Source: Internet
Author: User
Tags gz file

Summary of common Linux commands

LS command:
1. ls // list the files and folders in the current directory
2. ls-A // list the files and folders in the current directory, including hidden files
3. ls-l // list details
4. ls directory // list files under a directory


PWD command // view the current location

Du command

1. Du directory // view the total capacity of the Directory and the capacity of the subdirectory
2. Du-s directory // view the total directory capacity


CD command
1. CD .. // go back to the upper-level directory
2. CD // return to the root directory
3. CD // return to the user's home directory
4. CD directory path // go to a directory

Mkdir directory name // create directory
Rmdir empty directory name // Delete empty directory
RM file name // delete the file
Rm-RF directory name // Delete the Directory and all files in the directory
Mount command
1. Mount/dev/CDROM/mnt/CDROM // mount the optical drive to the/mnt/CDROM directory.
2. Mount-T vfat/dev/sda1/mnt/u // mount the USB flash disk to the/mnt/u directory.
3. umount/mnt/CDROM // uninstall the optical drive
Fdisk-l // view local storage devices
File Name // view the file type
Find directory name-name "*. c" // find the file *. C in a directory

Whereis file name // find the directory in which the file is located
Cat file name // display file content
Cat file name | grep text // only displays text-related content
Cat file name | more // display the file content by PAGE
Tail file name // view the end Of the file
Head file name // view the file from the beginning

CP command:
CP file 1 file 2 // copy file 1 to file 2
CP file 1 directory 1 // copy file 1 to directory 1
CP directory 1/file 1 directory 2 // copy file 1 under directory 1 to directory 2
CP-r directory 1 directory 2 // copy all contents under directory 1 to directory 2

MV command:
MV file 1 file 2 // rename file 1 to file 2
MV file 1 directory 1 // move file 1 to directory 1
MV directory 1/file 1 directory 2 // move file 1 under directory 1 to directory 2
MV-r directory 1 directory 2 // move all contents under directory 1 to directory 2

Chmod command:
Chmod U + x g + R o-w file name // Set permissions for the file (user, group, other persons)
Chmod 744 file name // Set permissions for the file (1-execution, 2-write, 4-read)

CHOWN command:
Chown User File Name // change the file to all
Chown-r user directory name // change all files in the directory

Chgrp command:
Chgrp group name file name // change the file to all
Chgrp-R group name directory name // change all files in the directory to all

Ln command:
Ln file name Link name // create a hard link for the file
Ln-s file name Link name // create a soft link for the file

Useradd command:
Useradd username // create an account
Useradd-d directory username // create an account and specify the main directory
Useradd-r username // create a system account
Useradd-G group name username // create a user that belongs to a group

Passwd command:
Passwd user name // set a password for the user
Passwd-s user name // view account status
Passwd-l user name // lock account password
Passwd-u user name // unlock Password
Passwd-D username // Delete Password

Userdel command
Userdel username // Delete account
Userdel-r user name // Delete the account and its home directory

Usermod command:
Usermod-l old username/rename User Name
Usermod-l user name // lock the account
Usermod-u username // unlock account
Usermod-G group name username // Add User to a group

Groupadd group name // create a group
Groupdel group name // Delete Group

Groupmod command
Groupmod-G group ID group name // modify the group ID
Groupmod-N new group name old group name // modify group name

Gpasswd command
Gpasswd-a username group name // Add the user to the group
Gpasswd-D username group name // delete a user from the group
Gpasswd-a username group name // set the user as the Group Administrator

Groups user name // view the group to which the user belongs
Id username // view User uid Information

VI file name // edit file content

Output redirection:
Cat a.txt> B .txt // view the content of file a and output the result to file B.
>>/// Indicates the redirection of append write.
2> // error output redirection

MPs queue:
Command 1 | command 2: CAT a.txt | grep ABC | more

Script editing steps:
1. Use the VI command to edit a. Sh
2. Test the script through bash a. Sh or. A. Sh.
3. Modify the. Sh attribute to Executable
4../A. Sh run the script

Rpm command:
Rpm-IVH installation package name // install software
Rpm-E Software name // uninstall software
Rpm-u installation package name // upgrade software
Rpm-Qa | more // query all installed software
Rpm-Q software name // query whether the software is installed
Rpm-Qi software name // query software details
Rpm-QL software name // query the Software Installation File List
Rpm-QF command name (absolute path of the command) // queries the software of a command
Rpm-QPI full name of the installation package // learn the installation package information before installation
Full name of the rpm-qpl installation package // list of files contained in the installation package before installation

Source code compilation and installation process:
The system must have a C ++ development environment. Select a graphical interface to install the development tool.
1. Download the source code package to a directory, which is generally a compressed file with a suffix of .bz2.
2. Tar-jxf compressed file name // decompress it to a directory
3. Go to the source code directory.
4. Configure the source code. For example, set the installation directory./configure -- prefix = directory name.
5. Compile after configuration. Execute make
6. Install make install after compilation.

Init command:
Init 0 // Shutdown
Init 6 // restart
Init 3 // multi-user command mode
Init 5 // multi-user graphics mode

Runlevel // view the current running level

Chkconfig command
Chkconfig--list // view the service startup status
Chkconfig--list service name // view the startup status of a service
Chkconfig--level 35 service name on (off) // sets whether an independent service is enabled (disabled) at level 3 and 5)
Chkconfig service name on (off) // set the non-independent service to enable and disable

PS-Aux // view the process
Top // view system information
Kill process number // stop a process
Kill-9 process no. // forcibly stop a process by process no.
Killall process name // forcibly stop a process by process name
CTRL + C // stop a process

Jobs // view the background program running
FG job no. // call the background command back to the foreground
CTRL + z // call the foreground command back to the background
BG job no. // call the command back to the background

At // set the scheduled task
ATQ // view the unexecuted plan
Atrm at No. // delete a plan

Service Command
Service name status // view service status
Service name stop // stop the service
Service name start // start the service
Service name restart // restart the service

Crontab command
Crontab-l // view the current cron task list
Crontab // create a task that overwrites the original task
Crontab-E // Add a task
Crontab-r // delete a task
Crontab-u user name-r // delete a user's task

To configure a disk quota, follow these steps:
1. Modify the/etc/fstab file // make the partition support the disk quota
2. Reboot // restart
3. quotacheck-cmug // create a quota file for/partition
4. quotacheck-mfvug // check the quota consistency of/partition
5. edquota-u user name // set disk quota for a user
6. edquota-G group name // set disk quota for a group
7. quotaon-avug // make the settings take effect immediately
8. Quota-u user name // view the disk quota of a user
9. Quota-G group name // view the disk quota of a group

Tar command
Tar-CVF a.tar file name or directory // pack the file or directory as a.tar
Tar-czvf a.tar.gz file name or directory // compress the file or directory into a.tar.gz
Tar-xvf a.tar // unlock a.tar
Tar-xvf a.tar-C directory // unbind a.tar to a directory
Tar-xzvf a.tar.gz // extract a.tar.gz
Tar-jxf a.bz2 // extract a.bz2
Tar-TF a.tar // list of files in the.a.tar package before unpacking
Tar-tzf a.tar.gz // uncompress the list of files in the former a.tar.gz package

To configure an NFS server
1. Check that NFS and Portmap packages are installed.
2. Edit the/etc/exports file and set the shared folder (created in advance) and corresponding permissions.
3. Check that the NFS and Portmap services are started.
4. Run the showmount-e command to view the shared directory.

To configure an NFS client
1. Set the IP address and ping the server
2. Use the showmount-e NFS server IP address to view the shared directory of the server.
3. Mount the shared directory to the specified folder using mount.
4. Access the folder content
5. Use umount to uninstall a folder

For Windows clients, you must install third-party software (omni-lite)

Exportfs-RV reads the newly configured shared directory to the NFS service.
Exportfs
Exportfs-AV enable all shared directories

Shortcut Key

[CTRL] + [alt] + [backspace] = kill your current X session. Kill the graphic desktop session and return you to the logon screen. If the exit step does not work, you can use this method.


[CTRL] + [alt] + [delete] = shut down and reboot Red Hat Linux. Close your current session and reboot the OS. This method is used only when the normal shutdown step does not work.

[CTRL] + [alt] + [FN] = switch the screen. [CTRL] + [alt] + one of the function keys will display a new screen. According to the default settings, from [F1] to [F6] is a shell prompt screen, and [F7] is a graphical screen.

[Alt] + [Tab] = switch tasks in a graphical desktop environment. If you open more than one application at the same time, you can use [alt] + [Tab] to switch between the opened task and application.

[CTRL] + [a] = move the cursor to the beginning of the line. It can be used in most text editors and Mozilla URL fields.

[CTRL] + [d] = log out (and close) from the shell prompt ). You do not need to enter exit or logout.

[CTRL] + [e] = move the cursor to the end of the row. It can be used in most text editors and Mozilla URL fields.

[CTRL] + [l] = clear the terminal. This shortcut works the same as typing clear in the command line.

[CTRL] + [u] = clear the current row. If you work in a terminal, use this shortcut to clear the characters from the cursor to the beginning of the line.

[Intermediate mouse key] = paste the highlighted text. Use the left mouse button to highlight the text. Point the cursor to the place where you want to paste the text. Click the middle key to paste it. In the two-Key mouse system, if you configure the mouse to simulate the third key, you can click both the left and right keys of the mouse to paste them.

[Tab] = command line auto-completion. Use this command when prompted by shell. Type the first few characters of the command or file name, and press the [Tab] key. It will automatically complete the command or display all commands that match the characters you typed.

[Up] and [Down] arrows = show command history. When you use shell prompts, press the [Up] or [Down] arrow to view the command history you typed in the current directory. When you see the command you want to use, press the [enter] key.

Clear = clear the shell prompt screen. Type it in the command line to clear all the data displayed on the shell prompt screen.

Exit = logout. In the shell prompt, type it to log out of the current user or root user account.

History = displays the command history. In the shell prompt, type it to display the first 1000 commands you have typed. To display a short command history, enter history F and enter a number. For example, history 20.

Reset = Refresh the shell prompt screen. If the characters are not clear or garbled, type this command at the shell prompt to refresh the screen.

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.