Touch command
The touch command is used to create empty files, such as when an application wants a log file to exist before they can write to the data. You can create an empty file with the touch command: touch test1
;
The touch command can also be used to change the access time and modification time of the existing file, without changing the contents of the file, for example, if the file is already in existence, when it is test1
executed again touch test1
, the time of creation of the file is the current time, and the parameter is followed by a timestamp to -t
change the file creation time to the specified time;
CP command
This command is used to copy files or directories, the CP command requires two parameters, the source object and the target object, the most basic usage is:
cp source destination
When source
and destination
both are files, the new file is destination
named, source
and destination
also can be a catalog file
Several common parameters of CP command are introduced emphatically:
- -P: Preserve the source file's access time and modification time for the destination file
- -V: Verbose mode explaining what happened during replication (available for Shell program logging)
- -R: Recursive replication for copying directories and their subdirectories
- -B: Create a backup without overwriting
- -F: forced override without asking
MV Command
The MV is moving, which is used to move files and directories to another location, with the following basic usage:
mv source destination
Use the MV command to rename the file, it will be changed to a destination
new name.
Note that moving a file with a soft link will invalidate the soft connection file
RM command
The RM command is used to delete a file, either in the RM followed by a file or directory name
- -I: Ask for confirmation before deleting a file
- -r: Recursively delete directory files and their subdirectories
- -F: Mandatory deletion of files without any queries (e.g. deleting files with git repositories)
Note that because the RM command does not recycle the file to the dumpster, it completely disappears, so be rm -rf destination
careful when executing this command, with a few days of painstaking effort, and the system you are using is all erased.
I draw on the experience of the network predecessors, attached to delete to Recycle Bin code (added in the. zshrc file)
alias rmtrash=trash alias lltrash=‘ll /.Trash’ trash() { mv -v [email protected] /.Trash/ }
In this case, the command can be executed instead of the command rmtrash
rm
to lltrash
view the files in the bin
mkdir command
Create Directory command,-p parameter for recursive creation
File command
View File type commands
The file command divides the files into 3 classes
- Text file: A file that contains printable characters
- Executable files: Files that can be run on the system
- Data files: Files that contain non-printable binary characters and that cannot be run on the system
View entire file
- Cat command
The cat command simply displays the contents of the file, which is easy to understand and describes the next few parameters
- -N: Add line numbers to the displayed content
- -B: Add line numbers only to lines with text
- -S: Compress multiple blank rows into a single blank line
- More commands
The flaw with the Cat command is that once the cat command is run, for very many files, it will continue to print until it finishes, so that no additional commands will be made during the printing process unless you force the current command to exit. To solve this problem, the developer wrote the more command. The more command displays the contents of the text file, but stops after each page of data is displayed, waiting for the operator to enter commands for follow-up activities.
- Less command
The name of less command is actually a word game-"not more", it should be said to view the contents of the file with less command, will not print the file content to the terminal, and support many commands and the direction key to view the contents of the file, so that you have full control when viewing the contents of the file.
View some files
- Head command
Displays the contents of the first few lines of the file, displaying 10 rows By default, to roughly know the contents of the file without loading all the files. Parameters are similar to the tail command, followed by the tail command
- Tail command
The tail command displays the contents of the end of the file. The default is to display the end of the file 10 lines, but also with parameters control
- -C Bytes: Displays the last bytes bytes of a file
- -N lines: Displays the last lines line of the file
- -F: Let the tail program remain active, if new content is displayed at the end of the file
- -pid=pid: Along with the-f parameter, keeps track of a file until the process with the ID PID ends
- -S SEC: with the-f parameter, sleep sec seconds between each loop output
The-f parameter is a prominent feature of the tail command, which allows you to view the contents of a file while other processes are using it. The tail command remains active and continuously displays the content that is added to the file. is a wonderful way to monitor system logs in real time.
Shell programming-common file handling commands