Basic Shell Command 2

Source: Internet
Author: User

2. process file 2.1 Create file Touch

If you want to change the access time only, you can use the-a parameter.
$ ls-l Test_one
-rw-rw-r--1 Christine Christine 0 may 14:35 Test_one
$ touch-a Test_one
$ ls-l Test_one
-rw-rw-r--1 Christine Christine 0 may 14:35 Test_one

Note that if you use only the Ls–l command, the access time is not displayed. This is because the default is to display the modification time. To view the access time of a file, you need to add another parameter:--time=atime. Yes
This parameter, you will be able to display the file access time that has been changed.
$ ls-l--time=atime Test_one
-rw-rw-r--1 Christine Christine 0 may 14:55 test_on

2.2 Copying Files CP

-I forces the shell to ask if an existing file needs to be overwritten.

-R copies the contents of the entire directory recursively.

In the most basic usage, the CP command requires two parameters-the source object and the target object:
CP Source Destination

The single dot (.) is a good fit for the CP command. Remember, the single dot represents the current working directory. If you need to copy a file with a long source object name into the current working directory, a single dot can simplify the task.

$ cp-i/etc/networkmanager/networkmanager.conf.
$
$ ls-l networkmanager.conf


-rw-r--r--1 Christine Christine 15:55 networkmanager.conf

2.3 Link Files Ln

Linked files are an advantage of the Linux file system. If you need to maintain two or more copies of the same file on your system, you can save a copy of a physical file and multiple virtual copies in addition to saving multiple copies of a separate physical file. This virtual copy is called a link. A link is a placeholder in the directory that points to the real location of the file. There are two different kinds of file links in Linux:
Symbolic Link Ln-s
Hard Link Ln

2.4 Renaming files: Moving moving

$ MV Fall Fzll
$
$ Ls-li F?ll
296717-rw-rw-r--1 Christine Christine 0 may 13:44 fell
294561-rw-rw-r--1 Christine Christine 0 may 13:44 fill
296742-rw-rw-r--1 Christine Christine 0 13:44 full
296730-rw-rw-r--1 Christine Christine 0 may 13:44 Fzll

Note that moving the file changes the filename from fall to Fzll, but the inode number and timestamp remain the same. This is because the MV
Affects only the file name.

2.5 Deleting files rm (removing)

-I asks if confirmation continues

-F Force Delete

-R Recursive Delete

2.6 Creating a directory (mkdir)

-P Create multiple directories and subdirectories at the same time

2.7 Delete directory (RMDIR)

Delete Empty directory by default

Rm-rf

View file contents view File types

The file command is a handy tool that you can easily get. It detects the inside of a file and determines what type of file it is:
$ file My_file
My_file:ascii text

$ file New_dir
New_dir:directory

The last example is a binary executable program. The file command is able to determine which platform the program was compiled for and
What type of library you want. This can be a very useful feature if you have binary files that you have never known from sources:
$ file/bin/ls
/bin/ls:elf 64-bit LSB executable, x86-64, version 1 (SYSV),
Dynamically linked (uses shared libs), for Gnu/linux 2.6.24,

View entire file

1. Cat commands
The Cat command is a powerful tool for displaying all the data in a text file.

The-n parameter adds a line number to all rows.

The-b parameter adds a line number to the line with the text.

-T parameter does not want tabs to appear

2. More Commands

The more command displays the contents of the text file, but stops after each page of data is displayed.

3. Less command

The name of the less command is actually a word game (derived from the saying "less was more"), which is an upgraded version of the more command. It provides some very useful features that enable you to turn back and forth in a text file, and there are some advanced search features.

- b <缓冲区大小> 设置缓冲区的大小 - e 当文件显示结束后,自动离开 - f 强迫打开特殊文件,例如外围设备代号、目录和二进制文件 - g 只标志最后搜索的关键词 - i 忽略搜索时的大小写 - m 显示类似more命令的百分比 - N 显示每行的行号 - o <文件名> 将less 输出的内容在指定文件中保存起来 - Q 不使用警告音 - s 显示连续空行为一行 - S 行过长时间将超出部分舍弃 - x <数字> 将 "tab" 键显示为规定的数字空格 / 字符串:向下搜索 "字符串" 的功能 ?字符串:向上搜索 "字符串" 的功能View some files

1. Tail command
The tail command displays the contents of the last few lines of the file (the "tail" of the file). By default, it displays the end of the file
Tail 10 lines.

-n Specifies the number of rows to view

-F keeps the tail active and displays the content added to the file continuously. This is a wonderful way to monitor system logs in real time.

2. Head command
The head command, as the name implies, displays the contents of those lines at the beginning of the file. By default, it displays the text of the first 10 lines of the file

-n Specifies the number of rows to view

Basic Shell Command 2

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.