Summary of common Linux commands: cd, ls, mkdir, cp, mv, touch, vim, chown, find, tar and other Linux commands

1. Experimental environment

Operating system: Ubuntu64 bit
Hadoop version: Hadoop 2.7.1
Jdk version: jdk-8u241-linux-x64

Two, use common commands of Linux system

1. Switch to the directory /usr/bin;

cd /usr/bin

Insert picture description here

Linux "cd" command syntax:

cd [target working file directory]

Linux absolute path and relative path:

Absolute path: The path must be written from the root directory/, such as /usr/local/mysql;

Relative path: The path is not written from the root directory /, for example: first the user enters /home, and then enters test, the executed command is ">cd /home,>cd test". At this time, the path where the user is located is /home/test. The first cd command is immediately followed by /home with a slash in front; the second cd command is immediately followed by test without a slash in front. This test is relative to the /home directory, so it is called a relative path.

2. View all files in the directory /usr/local

cd /usr/local
ls

Insert picture description here
or:

ls /usr/local

Insert picture description here
Insert picture description here

Linux "ls" command syntax:

ls [options] [directory name]

ls common parameters:

-a: Display all files and directories (hidden files starting with. will not be listed)
-l: In addition to the file name, the file type, permissions, owner, file size and other information are also listed in detail
-r: the file Display in reverse order (originally in alphabetical order)
-t: List the files in the order of creation time
-A: Same as -a, but do not list "." (current directory) and "..." (parent directory) )
-F: Add a symbol after the listed file name; for example, add "*" to the executable file, and add "/" to the
directory -R: If there are files in the directory, the following files are also listed in sequence

3. Enter the /usr directory, create a directory named test, and check how many directories exist

cd /usr
sudo mkdir test

Insert picture description here

or:

sudo mkdir /usr/test

Insert picture description here

Linux "mkdir" command format:

mkdir [options] directory

Options:

-m: mode=mode, set permissions <mode> (similar to chmod)
-p: parents, can be a path name. At this time, if some directories in the path do not exist yet, after adding this option, the system will automatically create those directories that do not exist yet, that is, multiple directories can be created at a time;
-v: verbose, every time a new directory is created Display information

4. Create a new directory test1 under /usr, and copy the contents of this directory to /tmp

sudo mkdir test1
cp -r /usr/test1 /tmp

Insert picture description here

Linux "cp" command format:

cp [options] [parameters]

Options:

-a: The effect of this parameter is the same as specifying the "-dpR" parameter at the same time;
-d: when copying a symbolic link, the target file or directory is also established as a symbolic link and points to the original file or directory connected to the source file or directory ;
-F: Forcibly copy files or directories, regardless of whether the target file or directory already exists;
-i: ask the user before overwriting existing files;
-l: establish a hard link to the source file instead of copying the file;
-p: keep The attributes of the source file or directory;
-R/r: recursive processing, all files in the specified directory and subdirectories are processed together;
-s: to establish a symbolic link to the source file instead of copying the file;
-u: use this After the parameter, the file will be copied only when the change time of the source file is newer than the target file or when the target file with the corresponding name does not exist;
-S: When backing up the file, replace the file with the specified suffix "SUFFIX" The default suffix;
-b: backup the target file before overwriting the existing file target;
-v: display the operation performed by the command in detail.

parameter:

Source files: Develop a list of source files. By default, the cp command cannot copy directories. If you want to copy directories, you must use the -R option;

Target file: Specify the target file. When the "source file" is multiple files, the "target file" is required to be the specified directory.

5. Rename the /tmp/test1 directory in 4 to test2

mv /tmp/test1/ /tmp/test2/

Insert picture description here

Linux "mv" command format:

mv [options] source file or directory target file or directory

mv command parameters (options):

-b: If the file needs to be overwritten, back up before overwriting.
-f: force means that if the target file already exists, it will overwrite without asking;
-i: if the target file already exists, it will ask whether to overwrite!
-u: If the target file already exists and the source file is relatively new, it will be updated
-t: Specify the target directory of mv. This option is suitable for moving multiple source files to one directory. At this time, the target directory is first, the source The file is behind.

6. Create a new word.txt file in the /tmp/test2 directory and enter some strings, save and exit

touch /tmp/test2/word.txt
vim /tmp/test2/word.txt

Click "i" to insert content, "esc> :wq" to save and exit

Insert picture description here
Insert picture description here

7. View the content of word.txt

vim /tmp/test2/word.txt

Insert picture description here

8. Change the owner of the word.txt file to the root account and view the properties

sudo chown root /tmp/test2/word.txt

Insert picture description here

linux“chown”命令格式:
chown [选项] [参数]

Options:

-c or-changes: the effect is similar to the "-v" parameter, but only the changed part is reported;
-f or -quite or -silent: no error message is displayed;
-h or -no-dereference: only for symbolic links The file is modified without changing any other related files;
-R or --recursive: recursive processing, all files and subdirectories in the specified directory will be processed together;
-v or --version: display the instruction execution process;
--dereference : The effect is the same as the "-h" parameter;
–help: online help;
–reference=<reference file or directory>: set the owner of the specified file or directory and the group to which it belongs, and the owner of the reference file or directory The same group belongs to;
--version: Display version information.

parameter:

User: Group: Specify the owner and workgroup to which it belongs. When ": group" is omitted, only the file owner is changed;
file: specify the file list to change the owner and work group. Supports multiple files and targets, and supports shell wildcards.

9. Find the file named test2 in the /tmp directory

sudo find /tmp -name test2

Insert picture description here

Linux "find" command format:

find [Search directory] [Search rules] [Operation after searching]

parameter:

-mount, -xdev: only check files in the same file system as the specified directory, avoid listing files in other file systems
-amin n: have been read in the past n minutes
-anewer file: more than file file Files read late
-atime n: files that have been read in the past n days
-cmin n: modified in the past n minutes
-cnewer file: files newer than the file file
-ctime n: in the past n days were modified files
-empty: empty file -gid n or -group name: gid or group name is n is the name
-ipath p, -path p: p line with the path name of the file, ipath ignores case
- name name, -iname name: The file whose name matches the name. iname ignores case-
size n: the file size is in units of n, b represents a block of 512 bytes, c represents the number of characters, k represents kilo bytes, and w is two bytes.
-type c: The file type is c.

10. Create a new folder test in the / directory, and then package it as test.tar.gz in the / directory

Sudo mkdir test
Tar -czvf test.tar.gz test
# tar -czvf 打包压缩后文件 被打包压缩的文件夹

Insert picture description here

Linux "tar" command format:

tar[Required parameter][Select parameter][File]

parameter:

The necessary parameters are as follows:

-A Add compressed files to existing compression
-B Set block size
-c Create new compressed files
-d Record file differences
-r Add files to compressed files
-u Add changed and existing files to Existing compressed files
-x extract files from compressed files
-t display the contents of compressed files
-z support gzip decompression files
-j support bzip2 decompression files
-Z support compress decompression files
-v display operation process
-l file system boundary settings
-k keep the original file without overwriting
-m keep the file from being overwritten
-W confirm the correctness of the compressed file

The optional parameters are as follows:

-b set the number of blocks
-C switch to the specified directory
-f specify the compressed file
-help display help information
-version display version information

11. Unzip test.tar.gz to the /tmp directory

tar -xzvf test.tar.gz -C /tmp
# tar -xzvf 压缩文件 -C 被解压到的目录

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_45154565/article/details/109209914