Detailed Explanation of Linux Common Commands and Parameters (Xunfei Spark Large Model Internal Beta Production)

  1. cd: change directory

Usage: cd [directory path]

For example: to enter the /home directory, the command is: cd /home

  1. ls: list files and subdirectories in the current directory

Usage: ls [options] [file or directory]

Commonly used options:
-l: list detailed information of files and directories in long format
-a: list all files and directories, including hidden files and directories
-d: list only directories, do not display file content
-t: by modification time Sorting, the most recently modified files or directories come first
-r: reverse sorting

For example: to list all files and directories in the current directory, the command is: ls -al

  1. pwd: display the path of the current working directory

Usage: pwd

For example: the path to display the current working directory is /home/user

  1. mkdir: create a new directory

Usage: mkdir [directory path]

For example: to create a directory named test, the command is: mkdir test

  1. rmdir: delete empty directory

Usage: rmdir [directory path]

For example: to delete an empty directory named test, the command is: rmdir test

  1. touch: create a new file or update the timestamp of a file

Usage: touch [filename]

For example: to create a new file named test.txt, the command is: touch test.txt or to update the timestamp of test.txt, the command is: touch
test.txt

  1. cp: copy a file or directory

Usage: cp [source file or directory path] [destination file or directory path]

For example: copy /home/user1/file1 to /home/user2/file2, the command is: cp /home/user1/file1 /
home/user2/file2 or copy the entire directory src to the target directory dst, the command is: cp - r src dst

  1. mv: move or rename a file or directory

Usage: mv [source file or directory path] [destination file or directory path]

For example: to move the file file1 to the directory dir1 and rename it to file2, the command is: mv file1 dir1/file2
or to rename the directory dir1 to dir2, the command is: mv dir1 dir2

  1. rm: delete a file or directory

Usage: rm [file or directory path]

For example: to delete the file file1, the command is: rm file1 or to delete the directory dir1 and all its subdirectories and files, the command is: rm -r dir1

  1. cat: output the contents of the file to the terminal

Usage: cat [filename]

For example: to output the content of the file file1 to the terminal, the command is: cat file1

  1. grep: Search for a specified string in a file

Usage: grep [options] [string] [filepath]

Commonly used options:
-i: case-insensitive search string
-v: output only unmatched strings, do not output matched strings
-r: recursively search for files in subdirectories

For example: to search for lines containing the string hello in the file file1, the command is: grep hello file1

  1. find: Find a file or directory

Usage: find [start directory] [end directory] [search criteria]

Commonly used options:
-name: search by file name
-type: search by file type (such as f for ordinary files, d for directories)
-mtime: search by modification time
-size: search by file size
-depth: search Depth limit for directories (default is 4 layers)
-print: only output search results without doing anything
-exec: execute specified commands on search results (such as mv, rm, etc.)

For example: to find all files with the extension txt in the current directory and its subdirectories, the command is: find . -name "*.txt"
or to find files whose modification time is within 7 days and delete them, the command is: find . - type f -mtime +7 -exec rm {} ;

  1. tar: pack and compress files and directories

Usage: tar [option] [file or directory] [compression method] [compressed output path]

Commonly used options:
-c: Create a new compressed file
-t: Specify the compressed file type (such as gz means gzip compression, bz2 means bzip2 compression)
-z: Specify the compression level (such as 9 means the highest compression level)
-v: Display detailed information (such as displaying the operation of each file when packaging)
-f: Specify the compressed output path and file name

For example: to package the directory dir1 and all its subdirectories and files into a compressed package in tar.gz format, the command is: tar -czvf dir1.tar.gz dir1/

  1. gunzip: decompresses files in gzip format

Usage: gunzip [compressed file path]

For example: to decompress a compressed file named file.gz, the command is: gunzip file.gz

  1. unzip: unzip files in zip format

Usage: unzip [compressed file path]

For example: to decompress a compressed file named file.zip, the command is: unzip file.zip

  1. tar: pack and compress files and directories

Usage: tar [option] [file or directory] [compression method] [compressed output path]

Commonly used options:
-c: Create a new compressed file
-t: Specify the compressed file type (such as gz means gzip compression, bz2 means bzip2 compression)
-z: Specify the compression level (such as 9 means the highest compression level)
-v: Display detailed information (such as displaying the operation of each file when packaging)
-f: Specify the compressed output path and file name

For example: to package the directory dir1 and all its subdirectories and files into a compressed package in tar.gz format, the command is: tar -czvf dir1.tar.gz dir1/
or package all files in the current directory into a tar.bz2 format Compressed package, the command is: tar -cjvf file.tar.bz2 *

  1. gzip: Compress files or directories in gzip format

Usage: gzip [options] [file or directory]

Commonly used options:
-c: Create a new compressed file
-d: Delete the original file (only valid for a single file)
-k: Keep the source file (do nothing)
-v: Display detailed information (such as displaying each file when compressing operation)
-f: Specify the compressed output path and file name

For example: to compress the directory dir1 and all its subdirectories and files into gzip format, the command is: gzip -cvf dir1.tar.gz dir1/

  1. bzip2: Compress files or directories in bzip2 format

Usage: bzip2 [options] [file or directory]

Commonly used options:
-c: Create a new compressed file
-d: Delete the original file (only valid for a single file)
-k: Keep the source file (do nothing)
-v: Display detailed information (such as displaying each file when compressing operation)
-f: Specify the compressed output path and file name

For example: to compress the directory dir1 and all its subdirectories and files into bzip2 format, the command is: bzip2 -cvf dir1.tar.gz dir1/

  1. tar.gz: Pack and compress files and directories in gzip format

用法:tar -czvf file.tar.gz file1 file2 … fileN

Commonly used options:
-c: Create a new compressed file
-z: Specify the compression level (such as 9 means the highest compression level)
-v: Display detailed information (such as displaying the operation of each file when packaging)
-f: Specify the compressed output path and filename

For example: to package the directory dir1 and all its subdirectories and files into a compressed package in tar.gz format, the command is: tar -czvf dir1.tar.gz dir1/

  1. tar.bz2: Pack and compress files and directories in bzip2 format

用法:tar -cjvf file.tar.bz2 file1 file2 … fileN

Commonly used options:
-c: Create a new compressed file
-j: Specify the bzip2 algorithm for compression
-v: Display detailed information (such as displaying the operation of each file when packaging)
-f: Specify the compressed output path and file name

For example: to package the directory dir1 and all its subdirectories and files into a compressed package in tar.bz2 format, the command is: tar -cjvf dir1.tar.bz2 dir1/

  1. cpio: pack files into cpio format

Usage: cpio [options] [inputfile] [outputfile]

Commonly used options:
-a: retain all file attributes (such as permissions, time, etc.)
-r: recursively process directories
-v: display detailed information (such as displaying the operation of each file when packaging)
-f: specify the compressed output path and file name

For example: to package all files in the current directory into cpio format, the command is: cpio -ovf file.cpio *

Guess you like

Origin blog.csdn.net/weixin_47834823/article/details/130767413