Basic shell commands 2

2. Process the file

2.1 Create a file touch

If you only want to change the access time, use the -a parameter.
$ ls -l test_one
-rw-rw-r-- 1 christine christine 0 May 21 14:35 test_one
$ touch -a test_one
$ ls -l test_one
-rw-rw-r-- 1 christine christine 0 May 21 14:35 test_one

It should be noted that if you only use the ls -l command, the access time will not be displayed. This is because the modification time is displayed by default. To see the access time of the file, you need to add another parameter: --time=atime . With
this parameter, it is possible to display the file access time that has been changed.
$ ls -l --time=atime test_one
-rw-rw-r-- 1 christine christine 0 May 21 14:55 test_on

2.2 Copy the file cp

 -i Force the shell to ask if it needs to overwrite existing files.

 -R Recursively copies the contents of an entire directory.

 

In its most basic usage, the cp command takes two arguments - a source object and a destination object:
cp source destination

The single dot (.) is very suitable for the cp command. Remember, the single dot signifies the current working directory. If you need to copy a file with a long source object name into the current working directory, the single dot character can simplify the task.

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


-rw-r--r-- 1 christine christine 76 May 21 15:55 NetworkManager.conf

2.3 Link file ln

Linked files are an advantage of the Linux filesystem. If two or more copies of the same file need to be maintained on a system, in addition to multiple separate physical copies of the file, one physical copy of the file and multiple virtual copies can be used. This virtual copy is called a link. A link is a placeholder in a directory that points to the actual location of the file. There are two different types of file links in Linux:
symbolic links ln -s
hard links ln

2.4 Rename files: move moving

$ mv fall fzll
$
$ ls -li f?ll
296717 -rw-rw-r-- 1 christine christine 0 May 21 13:44 fell
294561 -rw-rw-r-- 1 christine christine 0 May 21 13:44 fill
296742 -rw-rw-r-- 1 christine christine 0 May 21 13:44 full
296730 -rw-rw-r-- 1 christine christine 0 May 21 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 mv
only affects filenames.

2.5 Delete file rm (removing)

-i ask for confirmation to continue

-f force delete

-r delete recursively

2.6 Create a directory (mkdir)

-p creates multiple directories and subdirectories simultaneously

2.7 Delete a directory ( rmdir )

Delete empty directories by default

rm -rf  

View file contents

View file types

The file command is a handy tool at your fingertips. It can probe the inside of the file and decide what type the file 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 can determine what platform the program was compiled for and what type of library is
required . This is a very useful feature if you have binaries from unknown 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 command
The cat command is a powerful tool for displaying all data in a text file.

The -n parameter will add line numbers to all lines.        

The -b parameter adds line numbers to lines with text.

The -T parameter does not want tabs to appear

2. more command

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

3. less command

The naming of the less command is actually a play on words (from the saying "less is more"), and it is an upgraded version of the more command. It offers some extremely useful features, the ability to flip back and forth in text files, and some advanced search capabilities.

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

View some documents

1. The tail command
The tail command displays the last few lines of a file (the "tail" of the file). By default it will display the
last .

-n specifies the number of lines to view

-f keeps tail alive and keeps showing what is added to the file. This is a great way to monitor system logs in real time.

 2. head command The
head command, as the name suggests, displays the contents of the lines at the beginning of the file. By default it will display the first 10 lines of text in the file

-n specifies the number of lines to view

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325006864&siteId=291194637
Recommended