Linux Learning Essays

Source: Internet
Author: User
Tags disk usage

Recently took a breath of Hanshunping teacher to read the Linux video tutorial, oneself also in the process of learning to do some notes, recorded as follows, hope to help some students like to study Linux, but also in the cloud back up notes it, in order to avoid the computer appear uncontrolled factors and lost their efforts.

First of all, this note is not written according to the order of the teacher, may be a bit messy, but I believe that you can always find the information you want:

Linux must-see books:
Brother Bird's private cuisine
Linux programming from beginner to proficient
Linux Kernel security Profiling


Command:
Shutdown-h now immediately shuts down the machine
Shutdown-r now restart
Reboot restart
StartX into the graphical interface
Logout user logoff


Attention:
Log in as little as possible with the root account login, because it is the system administrator, the maximum permissions to avoid operational errors.
can use the ordinary user login, and then use the "Su-" command to switch to the system administrator identity.


C programs are compiled and run under Linux:
1. GCC hello.c or gcc-o newName hello.c
2../a.out


In brief, the Linux file system is a hierarchical tree-like structure, in which the topmost layer of the structure is the root "/", and then another directory is created in this directory.


The files under the root directory "/" are:
Bin: Various commands for application tools in Linux, such as C + +, g++, GCC, Chdrv, diff, Dig, Du, eject, elm, free, gnome*, gzip, htpasswd, KFM, Ktop, last, less , Locale, M4, make, man, Mcopy, NcFTP, newaliases, nslookup passwd, quota, smb*, wget, etc.
Sbin: A variety of commands for system management in Linux, such as Cfdisk, DHCPCD, Dump, E2FSCK, Fdisk, Halt, Ifconfig, Ifup, Ifdown, Init, Insmod, Lilo, Lsmod, MKE2FS, Modprobe, Quotacheck, reboot, Rmmod, Runlevelshutdown and so on.
Boot: Store the kernel and boot the required files.
Dev: Store the device files.
ETC: Store the configuration file of the system.
Home: The home directory of the user's files, where the user data resides in their home directory.
LIB: Store the necessary runtime libraries.
MNT: Storing temporary mapping file systems, we often mount the floppy drive and CD drive in the floppy and CDROM subdirectories here.
Proc: Storing stored process and system Information
Root: Superuser's home directory
TMP: directory where temporary files are stored
USR: Contains applications that do not normally need to be modified, command program files, libraries, manuals, and other documents.
var: contains frequently changing files generated by the system, such as printers, mail, news and other spool directories, log files, formatted hand albums, data files for some applications, and so on. It is recommended to place a separate partition.


Use of the VI Editor:
In edit mode, esc+ ": Wq" to save Exit, ": q!" To force exit (do not save)
": Set nu" displays line numbers at each line of the file
": Set Nonu" Cancel line number
": + number" jumps to the line marked by the number, such as ": 4" to jump to line fourth
":/+ string" To find a specific string, if the search string is not desired, you can press the "n" key to continue to find. such as ":/main" to find the "main" string position.
":? + string" Usage same as above ":/+ string"


User Management for Linux:
Useradd userName Add User userName
passwd userName Modify password for user UserName
Userdel userName Delete User UserName
Userdel-r userName Delete user and user home directory

Linux operating level:
Command init "012356"
Operating level: 0 shutdown
1 Single User
2 Multi-user status No NETWORK service
3 multi-user status with network service
4 system not used reserved to user
5 graphical interface
6 System restart
The common run level is 3 and 5, to modify the default RunLevel to modify the Id:5:initdefault of the file/etc/inittab: The number in this row.


Linux commands:
PWD Displays the current working directory
CD Switch Directory
LS Lists files and directories
Ls-a Show hidden files
Ls-l Display long list format
Ls-la Show hidden files and display them in long list format
mkdir New Directory
RmDir Delete Empty directories (you cannot delete directories with files, you can use "RM-RF" to forcibly delete directories with files)


Touch New Empty file
CP Copy File
Cp-r dir1 dir2 Recursive copy command (copy subdirectory information)
MV move file or change file name
RM Delete file (cannot delete directory directly)
RM-RF Force Delete all content (including directories and files)


ln establishes a symbolic connection, like Windows, which creates a shortcut to a file.
Ln-s source target such as Ln-s/etc/inittab Inittab (inittab pointing to actual file/etc/inittab)


More displays the contents of the file when the paging display
Less displays the contents of the file with pagination
grep queries the text for content such as "grep main Hello.java", "Grep-n main Hello.java" Displays the line number of the row
| Pipeline command
The man command is the equivalent of Windows Help


Find search files and directories
1. Search for and display files and directories of the specified name in a specific directory
Find/-name Hello.java
2. Search for files or directories that have been accessed/changed over time:
FIND/HOME-AMIN-10 files or directories accessed within 10min
FIND/HOME-ATIME-10 files or directories accessed within 10h
FIND/HOME-CMIN-10 files or directories that have changed within 10min
Find/home-ctime +10 files or directories that were changed before 10h
3. Search for files of the specified size
Find/home-size +10k to find files of size 10K in the/home directory

REDIRECT command:
Ls-l > A.txt The contents of the list are written to the file A.txt (overwrite write)
Ls-la >> Aa.txt The contents of the list are appended to the end of the file Aa.txt
Enter information from a file Database_program < Database_data


Each user in Linux must belong to a group and cannot be independent of the group.
In Linux, each file has the concept of owner, group, and other groups.


When a user creates a file, the group in which the file is located is the group that the user is in.
All groups of files can be seen with the command Ls-ahl
Command CHGRP group name file name to modify the group in which the file resides.


Add Group in Linux: Groupadd groupName
When you add a user, you can specify which group to add the user to,
The same root admin permission can change a user's group: USERMOD-G Group name User name
You can also change the initial directory that the user logged in with the usermod-d directory name User name


Fixed the Redhat command line in English garbled situation:
vi/etc/sysconfig/i18n back to normal display after adding Lc_all=posix logout.


To back up and restore the MySQL database using the command line:
Backup: mysqldump-u root-p password database name >data.bak
Recovery: mysql-u root-p Password database name <data.bak


Add Group in Linux: Groupadd groupName
View all group information in Linux: Vi/etc/group or Cat/etc/group


Create a user and specify which group to assign the user to: Useradd-g groupName userName
View all user information in Linux: VI/ETC/PASSWD or CAT/ETC/PASSWD


Commands to change permissions:
chmod changing the permissions of a file or directory
such as: chmod 777 abc.txt give Abc.txt permission-rwxrwxrwx (4+2+1)
Three groups of rwx belong to: File owner access, user group permissions, and other user rights.


Change the file owner (chown) and user Group (CHGRP) commands:
such as: Chown Xiaowang abc.txt Change abc.txt owner for Xiaowang
CHGRP Root ABC changes the group owned by ABC to root
Chown root./abc change the owner of the ABC directory to root
Chown-r root./ABC change the ABC directory and the owner of all files and directories below it root


Steps to install the JDK on Linux:
1. Package all the installation files into an. iso file and mount it on the Linux operating system:
Mount/mnt/cdrom
2. Copy the installation files to/home
CP File/Home
3.cd/home (switch directory to/home)
4. Installation
./xxxxx.bin
5. Look at a file/etc/profile (Environment config file)
Configure environment variables: as shown



Linux partitions:
Overview: First of all, we want to do some preliminary understanding of the basic concept of hard disk partitioning, the partition of the hard disk is divided into basic partition and extended partition two kinds,
The sum of the number of base and extended partitions cannot be greater than 4. and basic partitions can be used immediately but cannot be partitioned. The extended partition must be partitioned before it can be used.
This means that it must also be partitioned two times. So what does it take to divide the extended partition down? It is a logical partition, and there is no limit on the number of logical partitions.


For Windows users, several partitions have several drives, and each partition obtains an alphabetic identifier, which can then be used to specify
Files and directories on this partition. Their file structures are independent and very well understood. But for these users to start the Redhat Linux, can be a bit annoying. Because for Redhat Linux users, regardless of the number of partitions that are assigned to which directory to use, it boils down to a single root directory, a separate and unique file structure. Each partition in Redhat Linux is used to form part of the entire file system because it uses a processing method called "Loading", which contains a full set of files and directories in the entire file system, and links a partition to a directory. At this point a partition to be loaded will make its storage space available in one directory. Let's take a look at how the Redhat Linux drive is labeled.
For IDE hard drives, the drive identifier is "hdx~", where "HD" indicates the type of device on which the partition is located, which refers to the IDE hard disk. "X" is the disk number (A is the basic disk, B is the base slave disk, C is the secondary primary disk, D is the secondary slave disk), "~" represents the partition, the first four partitions are represented by the numbers 1 to 4, they are the primary partition or the extended partition. Starting with 5 is the logical partition. For example, Hda3 is represented as the third primary or extended partition on the first IDE hard disk, and HDB2 is represented as the second primary or extended partition on the second IDE hard disk. The SCSI hard drive is labeled "sdx~", the SCSI hard disk is "SD" to indicate the type of device the partition is on, and the rest is the same as the representation of the IDE hard disk.


Mount command mount [parameter] [device name] [Mount Point]
Special note: When mounting the optical drive, you can use the Mount/mnt/cdrom directly
Uninstall command Umount [device name]
View disk usage df [parameters]
such as: Df-l
See where a directory is in which partition DF [directory full path]
View Linux system partition specifics Fdisk-l




Linux Task Scheduler:
Set up Task Scheduler file/etc/crontab
Set up a personal task schedule. Executes the CRONTAB-E command.
Then enter the task into the dispatch file such as: 5 * * * * ls-l/etc/>/tmp/to.txt (five minutes per hour to execute ls-l/etc/>/tmp/to.txt command)


Rules for time representation in the dispatch file:



How to dispatch multiple tasks?
1. Write directly in the CRONTAB-E. (Not recommended)
2. All tasks can be written to an executable file (Shell programming). (Very good)


To terminate a task schedule:
Crontab-r terminating task scheduling
CRONTAB-L lists which tasks are currently scheduled


1.date command: Displays the time of the system. You can enter the "date" command directly from the command line. To view the time of the system.
2. Use the date command to change the time of the system.
Date Mmddhhmmccyy. SS: means: The day and day of the month are divided annually. seconds seconds
3. View calendar:
Cal 9 2014: View the September 2014 calendar.
4. View Annual calendar:
Cal 2014: View the 2014 year calendar


Linux Monitoring network status information:
command to display network statistics netstat
This command is used to display the current network condition of the entire system. For example, current connections, packet-passing data, or routing table content.
This command can be used directly by typing. such as: Netstat-an
Test host connection Command ping:
is a network detection tool, which is mainly used to detect whether the remote host is normal, or whether the media between the two hosts is disconnected,
Whether the network cable is off or the NIC is faulty. Such as: Ping the other IP address or URL


Show Packet history Command: traceroute
This command can be used directly to detect the process of packet transmission over the network. The full path from the local to the remote host to help the administrator resolve the issue.
Route
Routing refers to the operation of sending data from a source network to a destination network, where routing is very complex in a large network, as packets arrive at their destination,
There are a number of possible nodes, and the routing table is a form that is stored on the router or some other link settings. The network path to the specified destination is recorded, along with the associated values for those paths.




Linux compression and decompression issues:
Processing. zip files in zip and unzip
Basic use of the 1.zip command:
Zip File.zip *:zip followed by the compressed file name, after which you enter the file to be compressed.
2. Automatically delete the original file after compression
Zip-m File.zip to.txt: means to compress the To.txt files into file.zip files, To.txt will be automatically deleted.
3. Compress the sub-directories together:
Zip-r File.zip *: Compresses subdirectories in the current directory together.
4. Ignore the contents of the subdirectory:
Zip-j File.zip *
5. Remove the compressed or unnecessary files:
Zip-n. MPG:. jpg:. gif: The middle of the first file is separated by ":".
6. Compress files after one day:
Zip-t 102002 File.zip: Compresses files in the current directory after October 20, 2002.
7. Do not compress the original file of the linked file:
Zip-y File.zip *
8. Compression Ratio problem:-1 to-9 (-9 compression rate is highest)
Zip-9 File.zip *
9. Exclude files that do not need to be compressed.
Zip File.zip *-x file2.txt: Excludes file2.txt files in the current directory when compressing.


Unzip the. zip file with the unzip command
1. Extracting files directly
Unzip File.zip
2. exclude files that do not need to be decompressed
Unzip file.zip-x File2: Except for the File2 file, all other files are uncompressed.
3. View the contents of a compressed package
Unzip-z file.zip: View the contents of the File.zip compressed package. You can also use "-L", "-V" to view the contents of a compressed package



Configure the. bashrc file to specify that some programs will start automatically when the user logs on.


Alias usage (aliases a command):
Alias Llh= ' ls-l/home '




Shell uses:
Wildcard character: * represents multiple letters or numbers
? Represents a letter or a number
LS A * ls a? ls? at?
LS f080[1-6].tif




RunLevel command, you can view the current RunLevel


The Linux system boot process is as follows:
A) BIOS self-test
b) Start Grub/lilo
c) Run the Linux kernel and detect the hardware
D) The first process of running the system init
e) Init reads the information from the system boot configuration file/etc/inittab
f)/etc/rc.d/rc.sysinit system init script
g)/etc/rc.d/rcx.d/[ks]*-Configure services based on RunLevel X
Terminating services that begin with "K"
Start a service that begins with "S"
h)/etc/rc.d/rc.local perform local special configuration
i) other special services




Linux under Shell Introduction:


See what kind of shell is currently in use:
Env

Under Linux, we may sometimes want to know or use recently executed commands, and history may be a big help.
1.history 5: Shows the 5 most recently used commands.
2.! 5: Perform a command with a history number of 5.
3.! LS: Executes the last command that starts with "LS".

Trace route: tracert target ip/domain name
Test two IP is unblocked: Ping destination IP
View IP status under Windows command: ipconfig
Check the IP status under linux/unix command: ifconfig


Linux Network Environment configuration:
Method One: (1) log in as root and run the Setup command into the text mode Setup Utiliy to configure the network, which can be
IP, subnet mask, default gateway, DNS settings.
(2) The configuration of the network card is not in effect, run/etc/rc.d/init.d/network Restart command, we just made the settings to take effect.
Method Two: (1) ifconfig eth0 x.x.x.x to set the network card
(2) Ifconfig eh0 network x.x.x.x subnet mask settings.
Use the default for broadcast addresses and DNS
Note: This configures the network to take effect immediately, but is temporarily in effect.
Method Three: (1) Modify/etc/sysconfig/network-scripts/ifcfg-eth0 the various properties in this file can be modified, including IP, subnet mask, broadcast address, default gateway.
(2) The configuration of the NIC does not take effect at this time. Run the/etc/rc.d/init.d/network Restart command and the modification settings we just made will take effect. Method
This method is the lowest level of modification


In Linux, all the devices are files.


Concepts and management of Linux processes:
1. In Linux, each executed program is called a process. Each process is assigned an ID number.
2. Each process corresponds to a parent process, and the parent process can replicate multiple child processes. For example WWW server.
3. Each process can exist in two ways. Front desk and backstage. The so-called foreground process is the user's current screen can be manipulated.
The background process is actually in action, but because the process is not visible on the screen, it is usually performed in the background.
4. The services of the general system are in the form of a background process and will reside in the system until the shutdown is over.


The PS command is used to view what is currently being performed in the system, and what the status of their execution is. It is possible to add no parameters.
To display detailed process information:
1. Ps-a: Displays all process information for the current terminal.
2. Display process information in user's format: ps-u.
3. Show background process run parameters: Ps-x
Pa-aux: See comprehensive, information is also comprehensive.


Consider stopping a process if half of it needs to be stopped, or if it has consumed large system resources, use the KILL command
To complete this task.
Terminate a process: kill process number such as: Kill 12345
Kill-9 12345: Because some processes capture certain signals, the process can use "-9" to transmit information (force kill) if it cannot be terminated directly.


Linux Learning Essays

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.