Linux (1)

Source: Internet
Author: User
This is a learning note for linux! In fact, there is a big difference between linux and windows. when learning linux, we need to clear our own windows thinking. Otherwise, it will be easy to get to the forefront. After learning C, I learned JAVA. I always use C's thinking to look at JAVA, so it is difficult to get started. Because one is... this article is a study note for linux! In fact, there is a big difference between linux and windows. when learning linux, we need to clear our own windows thinking. Otherwise, it will be easy to get to the forefront. After learning C, I learned JAVA. I always use C's thinking to look at JAVA, so it is difficult to get started. Because one is process-oriented and the other is object-oriented. If you leave the idea of windows to learn linux From Scratch, it is not as difficult as you think. When I touch it every day, I naturally get familiar with it. File operation www.2cto.com master the following command is the most basic Oh! That is the most basic operation of a system. Have you ever played dos? in fact, file operations in linux are similar to those in dos. There is no difficulty. remember to do more exercises. If you have the following conditions, please do the same as me! Hundreds of things are not the same. You don't have to remember, every day, you will naturally remember [root @ localhost test] # ls to display all files and folders in the current directory [root @ localhost test] # ll to display all files and folders in detail. (Equivalent to the ls-l Command) [root @ localhost test] # cd/user open the user folder. if you do not know the full name or name of the folder to be opened is too long, you can press the tab keyboard to automatically complete it, for example, the cd/u + table key is automatically merged into/user [root @ localhost test] # cd .. (followed by spaces and two points) return to the upper-level Directory [root @ localhost test] # pwd to display the current directory path. it's super easy to remember that the above several jumps between folders are okay. File addition, deletion, query, and migration [root @ localhost test] # mkdir test create folder [root @ localhost test] # touch test.txt create file [root @ localhost test] # cp test.txt test2.txt copies test2.txt [root @ localhost test] # cp test.txt/hzh/test copies test.txt to the/hzh/test Directory [root @ localhost test] # rm aa.txt deletes the aa.txt file [root @ localhost test] # rm-r bb delete the bb Directory (including all files in the directory) [root @ localhost test] # rm-rf bb delete the bb Directory (delete every file in the directory without reminder) [root @ localho St test] # mv dd.txt .. move the dd.txt file to the upper-level Directory (note the two points at the end) [root @ localhost test] # mv bb.txt/hzh/test/move the bb.txt file to the [root @ localhost test] # mv dd.txt dd2.txt rename dd.txtto dd2.txt file search in the hzh/test/directory? * Same as in windows, [root @ localhost bin] # find/etc-name ini? Find the file whose header is ini and whose name is next to the/etc directory, [root @ localhost bin] # find/etc-name ini * [root @ localhost test] # locate aa.txt check the aa.txt file in the entire system. The locate \ slocate command is followed by the file or folder. However, this command is being executed.
To update the database, run the updatedb command. Www.2cto.com user permissions are actually complicated for new users, but not difficult. you just need to remember the rules. You can enter at least one file or folder in a folder, and then run the ll command. [Root @ localhost test] # ll total usage 24rwx ------ 2 root 16384 February 22 04:31 lost + foundrwxr-xr-x 2 root 4096 March 18 14:43 test so the "drwxr-xr" in front of the file -x indicates the permission! In linux, there are three types of users: u owner g owner group o and others. we divide "rwxr-xr-x" into three parts and three groups. The following rwx r-x owner belongs to the permission type of another person in the group: note that the permission has a different meaning for files and directories.
Modify the permission symbol: + add permissions-minus permissions = equal to what permissions when we want to modify the permission of a file (or directory: [root @ localhost hzh] # chmod u + w a adds the write permission to the owner of file a (chmod is the command to modify the permission). In fact, we generally do not write this write permission when modifying the user permission, so how to write it? it is represented by numbers. R-4 w-2 x-1rwx -- r-wxr + w + x = 7r = 1 w + x = 3 believe the following two of you understand: rw-r-x-w-652754 rwxr-xr -- for example, [root @ localhost hzh] # chmod 641 a641 rw-r ---- the x owner has read and write permissions, the group has the read permission, while others have the execution permission for the soft link www.2cto.com and hard link soft connection: the soft connection is similar to the "shortcut" of our windows system. Therefore, you must set a shortcut in windows, because some files are not easy to locate, we will create a shortcut on the desktop. In linux, the main reason is that the file name is too long to be input. In linux, file-to-file operations generally require a file name. Unlike windows, the file name length does not matter. you can click the mouse to complete the operations. Create a soft link [root @ localhost test] # ln-s ruanlianjie. abc/hzh/test/rlj. soft for the ruanlianjie under the current directory. abc File. create a soft link named rlj in the/hzh/test/directory. soft [root @ localhost test] # ll total usage 36 lrwxrwxrwx 1 root 15 March 19 20:57 rlj. soft-> ruanlianjie. abc-rw-r -- 1 root 28 March 19 20:57 ruanlianjie. abc can now operate on the software link, [root @ localhost test] # vi rlj. soft edit rlj. soft file, that is, edit ruanlianjie. abc File hard connection: hard connection is equivalent to copying the original file. the only special difference is that two Files are synchronized. When you modify one of the files, the other files will update your modifications at the same time. What are the benefits, you know! The following is a hard link: [root @ localhost test] # ln yinglianjie. abc/hzh/test/ylj. hard for yinglianjie. create a hard link file ylj in the/hzh/test/directory. hard [root @ localhost test] # ll-rw-r -- 2 root 0 March 19 21:08 yinglianjie. abc-rw-r -- 2 root 0 March 19 21:08 ylj. hard www.2cto.com [root @ localhost test] # vi ylj. hard for hard link ylj. modify and save the hard file [root @ localhost test] # ll-rw-r -- 2 root 14 March 19 21:09 yinglianjie. abc, we will find yin Glianjie. abc has also been modified synchronously-rw-r -- 2 root 14 March 19 21:09 ylj. hard file compression and decompression are also common operations in our daily life. for example, we often download various files from the Internet for installation, most files are compressed. The following describes four common compression commands. Gzip features: 1. only files can be compressed, but directories cannot be compressed. do not keep the source file [root @ localhost test] # gzip aaa to compress the aaa file [root @ localhost test] # gunzip aaa.gz to decompress the aaa.gz file [root @ localhost test] # gzip-d aaa.gz is most common for compressed files of the same type as tartar, A lot of software on the Internet is in this format. Parameters:-x unpackage. tar file-v display details-f specifies to decompress the file-z decompress [root @ localhost test] # tar-zcvf tatga.tar.gz tatgz compressed tatgzfile folder for tatga.tar.gz compressed file note: in linux, the extension is not the attribute [root @ localhost test] # file [file name] to identify the file type. [root @ localhost test] # tar-cf tatga.tar tatgz for tatgz [root @ localhost test] # gzip tatga.tar compresses the tatga.tar package [root @ localhost test] # tar-zxvf tatga.tar.gz to decompress the compressed file. zip function: files and directories can be compressed. it is a common compression format for windows and linux: www.2cto. c Om [root @ localhost test] # zip a.zip a: compress the file into a.zip [root @ localhost test] # zip-r tatgz.zip tatgz folder [root @ localhost test] # unzip tatgz.zip: decompress the bzip2 and gzip files. basically the same, only compressed files can be retained using the-k command. the original file can be retained [root @ localhost bzip2] # bzip2-k fnngj file compression [root @ localhost bzip2] # bunzip2 fnngj.bz2 decompress communication commands. we all know that linux is a feature different from windows, multi-user operating system. Multiple users are allowed to perform operations on the system. So how do users communicate with each other? Here are two interesting communication commands. Write to a user [root @ localhost ~] # Write [user name]

For example: [root @ localhost ~] # Write fnngj send the message hello fnngj to the fnngj user !! I like you !! The content sent by xixi ctrl + D ends the wall and sends it to all users using the system [root @ localhost ~] # Wall [information content] [root @ localhost ~] # Wall hello china ping www.2cto.com test the connection between the local machine and a certain address [root @ localhost ~] # Ping 192.168.203.128 [root @ localhost ~] # Ping www.baidu.com [root @ localhost ~] # Ping-c 4 192.168.203.1-c is equivalent to the default situation in windows (dos) (the row test is performed when four data requests are sent). In fact, we can set the number of data packets sent [root @ localhost ~] # Ping-s 5000 192.168.203.1 set the number of ping packets to 5000. The maximum value is 65507 ifconfig. This command is similar to ipconfig [root @ localhost ~] in dos. # Ifconfig command link operator used to view the detailed information of the local IP address. sometimes, we can put multiple commands together for input convenience. It is similar to the batch processing in dos. Is a set of commands. Let's take a look at all the symbols used for the connection between commands. ------------------------------------------------------------------------------- Pipeline: transfers the output of one command to another command as the input of another command. Usage: Command 1 | Command 2 | Command 3... | command n for example: [root @ localhost test] # ls-l/etc | more displays all files in the/etc directory, display all files in the/etc directory by page in the form of more [root @ localhost test] # ls-l/etc | grep init | wc-l and find the init file, displays the number of search results. -----------------------------------------------------------------------------; (Use commas); run the commands at intervals in sequence [root @ localhost ~] # Pwd; ll; data Pipeline & www.2cto.com command1 & command2 successful execution failure not to execute [root @ localhost ~] # Lskk & pwd if the first command fails to be executed, the second command will not be executed. There is a logic and relationship between the execution of the front and back commands. only after & the preceding command is successfully executed can the subsequent commands be executed. | [root @ localhost ~] # Lskk | pwd if the first command fails to be executed, the second command is executed. Command1 | the execution of commands before and after the successful execution of command2 does not fail has a logic or relationship. only | after the previous command fails to be executed, the subsequent commands are executed. In fact, for our computers, our standard input device is a keyboard and the standard input device is a display. If I tell you that the input does not use a keyboard, the output is not displayed. How do you say this? Even people who have been using computers for many years are confused. Haha! After reading the following operations, you will understand. Like standard I/O, Shell predefines a file description (0, 1, 2) for each process ). Corresponding to: 0 (stdin) standard input 1 (stdout) standard output; 2 (stderr) standard error output. Output redirection: you can save the information of an input to a file. [Root @ localhost ~] # Ls-l/tmp>/tmp. msg: save the information of the tmp directory to the/tmp. msg file. No results are displayed on the screen. [Root @ localhost test] # vi/tmp. msg View/tmp. total msg file information usage 8srwxr-xr-x 1 root 0 February 22 19:36 mapping-rootsrwxrwxrwx 1 mysql 0 February 27 22:35 mysql. sock [root @ localhost ~] # Data>/tmp. msg ">" indicates appending, and append some new information to/tmp. msg. You can also save an input to a file. We learned a wall command above. the following information can be broadcast to other online users in the table. of course, we can save the information to be broadcast to a file. of course, if you are interested, we can also set the time for sending. Www.2cto.com [root @ localhost ~] # Wall </etc/motd broadcasts the information in the motd file. Error output redirection if I want to back up a directory (/usr) to/backup/usr. under the bak directory, it takes a long time to back up data. I don't want to keep staring at the screen. now I can set it. if an error occurs during backup, save the error information to/bak. error file. In this way, I can find a friend to have tea, chat, and read the error message. [Root @ localhost ~] # Cp-R/usr/backup/usr. bak 2>/author of bak. error

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.