Linux Command learning notes
Basic File Operations
Ls, rm, mv, ln
Ls
Ls [option] [files]
List the contents of the current working directory without Parameters
$ Ls
Lists the contents of a specified directory.
Ls dir1
Or a few files
Ls file1
Option
-A: List all files, including hidden files and directories (starting)
-L Display object name attributes and details in long format
-H replace byte with units k, m, and other suitable for user reading
-F: Specifies a file name with a symbolic drum.
/Directory
* Executable files
@ Symbolic links)
L command pipeline (named pipes)
= Communication Pipeline (sockets)
After the symbols are attached to the file name, you can see their type at a Glance. These symbols are not one of the file names.
Is added when ls is displayed.
-I add the inode Number of the file before the price name
-S: the number of parts occupied by the file added before the file name (1 block is generally 1024 bytes)
-R recursively lists directory content
-D: list the directory itself, not its content.
Cp [option] files (file | dir)
If no parameter is added, a file is copied.
$ Cp srcfile destfile
Copy multiple files to a directory
$ Cp file1 fle2 file3 dir
-A or-R option to recursively copy the entire subdirectory
-P, along with the access mode and timestamp of the source file, is also copied to the new file. If your permissions permit, the owner and group of the new file are the same as those of the old file. If this item cannot be specified, the new file owner is you, and the knee Time is the current time, while the access mode is the intersection of the source file access mode and your umask.
-A copies the entire directory tree and retains the relationships between special files, access modes, symbolic connections, and hard links.
This option is equivalent to specifying-R (recursive replication including special files),-p (Access Mode)
-D (Link)
-I: The interaction mode. Before overwriting the target file, ask for your comments.
-F force copy: the target file already exists in a timely manner, and all files are rewritten unconditionally.
Mv [option] sources target
Moving and renaming are actually the same thing. The move command can also change the file name.
Mv file1 file2
Move files or directories to another directory
Mv file1 file2 dir3 dir4 dest_dir
-I Interaction Mode
-F force move
Rm [options] files | dirs
The rm (remove) command can delete objects.
Rm file1 file2 file3
You can also delete the entire directory.
Rm-r dir1 dir3
-I Interaction Mode
-F force Delete, ignore any congratulation error or warning
-R recursively calls out the Directory and its content,
Ln [options] source target
Link is a reference to another file, which is created using the ln command. The link is divided into two types:
Symbolic link represents another file by "path ".
Shorcut or the alias of the macintosh
$ Ln-s myfile softlink
If the source file is deleted, the symbolic link file becomes invalid because only the path does not exist. On the other hand, hard link is the second name of a physical file on the disk (in terms of terms, hard link only needs the same inode ). Deleting a source file does not cause a link failure. You can still access the content of the source file through the excellent link.
$ Ln myfile softlink
Symbolic Links can span Disk Partitions because they only reference the source file path. However, hard links are not allowed because inode on one partition is meaningless to other partitions. Objects with symbolic links can make directories, but hard links cannot. Unless you are a superuser and use the-d option.
Common options
-S: Create a symbolic link (hard link is created by default)
-I Interaction Mode
-F mandatory mode, unconditionally Overwriting
-D allows superuser to create hard links to directories
You can use one of the following commands to easily find out the object of the symbolic link
$ Readlink linkname
$ Ls-l linkname
Directory operations
Cd changes the current working directory
Pwd displays the name of the current working directory
Basename: display the end part of the file path
Dirname is like a part outside the end Of the file path.
Mkdir create directory
Rmdir Delete empty directory
Rm-r deletes non-empty directories and their contents
Cd [directory] bash
Shell built-in commands
This article permanently updates the link address: