Getting started with Linux

Source: Internet
Author: User
Tags touch command
Linux entry-general Linux technology-Linux technology and application information. For more information, see the following section. 1-column directory command --- ls
Command Format: ls [OPTION]... [FILE]...
Example:
$ Ls (password)
Afile Desktop (the directory listed)
Ls-a shows all file packages including hidden files
By default, the ls command displays the file and directory information in short format, that is, only the file and directory information is displayed. The corresponding information cannot be obtained through short format display, therefore, ls is usually used with-l.
Example:
$ Ls-l
Total 12
-Rw-r -- 1 teacher 0 Mar 29 20:21 afile [jjh6]
When the ls command uses a file as a parameter, only the specified file information is displayed, and other file or directory information is not displayed, which is helpful for locating and querying the required information.
Example:
$ Ls-l afile
-Rw-r -- 1 teacher 0 Mar 29 20:21 afile
When the ls command uses a directory as a parameter, the content in the specified directory is displayed, that is, the list of files and directories included in the directory, rather than the information of the directory file itself.
Example:
$ Ls-l Desktop
-Rw-r -- 1 teacher 0 Mar 29 20:44 test
Show current directory --- pwd

Pwd is used for the current directory of the real user.
Example:
$ Pwd
/Home/teacher

Directory change command --- cd
The cd command changes the user's current directory to another directory. The cd command can use the directory name as the parameter.
Cd [OPTION] [dir]
Example:
$ Pwd
/Home/teacher
$ Cd/
$ Pwd
/

Create directory command -- mkdir
Mkdir is used to create an empty name command.
Mkdir [OPTION] DIRECTORY...
Example:
$ Mkdir test
$ Ls
Afile Desktop test
$ Cd test
$ Pwd
/Home/teacher/test
Mkdir can also create multiple directories at the same time.

Delete directory command --- rmdir
The rmdir command is used to delete a specified empty command.
Rmdir [OPTION]... DIRECTORY
The rmdir command uses the directory name as the parameter and specifies that the directory name must be a space-time directory (the directory does not contain any files and their folders). Otherwise, the deletion will fail. you need to first delete the files or subdirectories in the directory, and then delete the Directory
Example:
$ Mkdir dira/dira1
$ Ls dira
Dira1
$ Rmdir dira
Rmdir: 'dia': Directory not empty
$ Rmdir dira/dira1/
$ Rmdir dira
Similar to the command at the door to create multiple directories, The rmdir command can also accept multiple directory parameters, that is, delete multiple empty directories in the same rmdir.
Example:
$ Ls
Dirb dirc
$ Rmdir dirb dirc
$ Ls-l
Total 0

2. File Operation commands

File type view command-file

The file command is used to view the file type. You can use the file name as a parameter to automatically identify and display the type of the specified file.

File [OPTION]... [FILE]...

The file command can identify the types of most files in Linux (text files, binary executable files, compressed files, etc)

Example:

$ File/etc/passwd

/Etc/passwd: ASCLL text

Because the file extension (such as ". mp3") is not forcibly used in Linux, this command is used when the file type is not determined.

Create FILE command -- touch

The touch command is used to create an empty file of a specified file. The file name is used as a parameter.

Touch [OPTION]... [FILE]

When the file specified by the parameter in the touch command does not exist, the touch command creates a file according to the file name in the parameter.

Example:

$ Ls-l

Total 0

$ Touch myfile

$ Ls-l

Total 4

-Rw-r -- 1 teacher 0 Mar 29 22:43 myfile

When the file specified by the parameter in the touch command exists, the touch command updates the time attribute of the file.

Example:

$ Ls-l

Total 4

-Rw-r -- 1 teacher 0 Mar 29 22:43 myfile

$ Touch myfile

$ Ls-l

Total 4

-Rw-r -- 1 teacher 0 Mar 29 22:45 myfile

Copy a file -- cp

The cp command is used to copy a file (directory) and copy the original address file (directory) to the target address.

Cp [OPTION]... SOURCE DEST

Cp [OPTION]... SOURCE... DIRECTORY

Copy the source file as the target file in the first format of the cp command.

Example:

$ Touch file1

$ Ls

File1

$ Cp file1 file2

$ Ls

File1 file2

In the second format of the cp command, copy one or more specified files to the specified directory. Among all the parameters of the cp command, there is only the directory name when the last parameter is used, all parameters before the directory name are the names of the files to be copied.

Example:

$ Mkdir backup

$ Cp file1 filr2 backup

$ Ls backup

File1 file2

Delete a file -- rm

The rm command is used to delete files. Because files in Linux cannot be restored when they are deleted, use them with caution.

Rm [OPTION]... FILE...

Example:

$ Ls

Backup fule1 fulr2

$ Rm fule1 fulr2

$ Ls

Backup
Related Article

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.