Linux Notes

Published 2026-08-17 22:38 1648 words 9 min read

Linux common commands notes

Common Commands

Syntax

less

Similar to more, it lets you browse files freely and supports paging and searching Format: less [options] file Option description:

  • -b Set the size of the buffer
  • -e Automatically quit when the file has been displayed
  • -f Force opening special files, such as peripheral device designators, directories, and binary files
  • -g Only highlight the last searched keyword
  • -i Ignore case when searching
  • -m Show a percentage similar to the more command
  • -N Show the line number of each line
  • -o Save the content output by less in the specified file
  • -Q Do not use warning sounds
  • -s Display consecutive blank lines as a single line
  • -S When a line is too long, discard the overflow portion
  • -x Display the “tab” key as the specified number of spaces
  • /string: The function of searching downward for “string”
  • ?string: The function of searching upward for “string”
  • n: Repeat the previous search (related to / or ?)
  • N: Repeat the previous search in reverse (related to / or ?)
  • b Scroll up one page
  • d Scroll down half a page
  • h Show the help screen
  • Q Quit the less command
  • u Scroll forward half a page
  • y Scroll forward one line
  • Space key Scroll one page
  • Enter key Scroll one line
  • [Page Down]: Scroll down one page
  • [Page Up]: Scroll up one page

Used to view the beginning of a file Format: head [options] [file] Options:

  • -q Hide the file name
  • -v Show the file name
  • -c The number of bytes to display.
  • -n The number of lines to display.
tail

View the content of a file Format: tail options file Options:

  • -f Loop reading
  • -q Do not display processing information
  • -v Display detailed processing information
  • -c The number of bytes to display
  • -n Display the last n lines of the file
  • —pid=PID Used together with -f, meaning it ends after the process with the ID, PID, dies
  • -q, —quiet, —silent Never output headers giving the file names
  • -s, —sleep-interval=S Used together with -f, meaning it sleeps S seconds between each repetition
file

Used to identify the type of a file Format: file -bcLvz -f -m … file or directory Options:

  • -b  When listing the identification results, do not display the file name.
  • -c  Display the command execution process in detail, for troubleshooting or analyzing the program execution.
  • -f  Specify a name file; when its content has one or more file names, let file identify these files in sequence, with one file name per line as the format.
  • -L  Directly display the category of the file that the symbolic link points to.
  • -m  Specify the magic number file.
  • -v  Display version information.
  • -z  Try to interpret the content of compressed files.
  • file or directory…: The list of files whose type is to be determined; separate multiple files with spaces, and shell wildcards can be used to match multiple files.
In

Full name: link files — creates a synchronized link for a file at another location Format: in options source file or directory target file or directory Command options Required options:

  • —backup[=CONTROL] Back up existing target files
  • -b Similar to —backup, but does not accept parameters
  • -d Allow the superuser to make hard links to directories
  • -f Force execution
  • -i Interactive mode; if the file exists, prompt the user whether to overwrite
  • -n Treat symbolic links as ordinary directories
  • -s Soft link (symbolic link)
  • -v Display the detailed processing process

Optional options:

  • -S “-S ” or “—suffix=”
  • -V “-V” or “—version-control=”
  • —help Display help information
  • —version Display version information
tar

Full name: tape archive — used for backing up and packaging files Format: tar options -f archive.tar files……

  • -f archive.tar: Specify the name of the archive file.
  • [files...]: The files and directories to be packaged.

options parameters

Basic operation options

  • -c: Create a new archive file.
  • -x: Extract the archive file.
  • -t: List the contents of the archive file.
  • -r: Append files to an existing archive file.
  • -u: Only append files that are newer than the existing files in the archive file.
  • -d: Find differences in the archive file that are not synchronized with the file system.
  • -A: Append one .tar file to another .tar file.

File selection and exclusion

  • -f <file>: Specify the name of the archive file (must be placed at the end of the option list).
  • -C <directory>: Switch to the specified directory for operations.
  • --exclude=<pattern>: Exclude files matching the specified pattern.
  • --exclude-from=<file>: Read the patterns to be excluded from the specified file.
  • --exclude-caches: Exclude cache files in directories.
  • --exclude-backups: Exclude backup files ending with ~.
  • --exclude-vcs: Exclude files generated by version control systems (such as .git, .svn, etc.).

Compression and extraction options

  • -z: Compress the archive file using gzip.
  • -j: Compress the archive file using bzip2.
  • -J: Compress the archive file using xz.
  • --lzip: Compress the archive file using lzip.
  • --lzma: Compress the archive file using lzma.
  • --lzop: Compress the archive file using lzop.
  • --zstd: Compress the archive file using zstd.
  • -a: Automatically select the compression method (based on the extension of the archive file, such as .tar.gz, .tar.bz2, etc.).
  • -I <command>: Use the specified compression program for compression or extraction.

Output and interaction options

  • -v: Display the detailed operation process (verbose).
  • --progress: Display a progress bar (when used together with -v).
  • -w or --interactive: Ask the user for confirmation before each operation.
  • --checkpoint: Display a checkpoint after processing each file.
  • --checkpoint-action=<action>: Execute the specified action at a checkpoint, such as echo, dot, etc.
  • --totals: Display the total number of bytes processed after the operation ends.
  • --verbose: Display the processing information in detail.
  • --quiet: Output as little information as possible.

File and permission related options

  • -p: Preserve the original permissions of files (when extracting).
  • --same-owner: Try to set the extracted files to the original owner (requires superuser privileges).
  • --no-same-owner: Do not set the file owner.
  • --same-permissions: Preserve the original permissions of files (same as -p).
  • --no-same-permissions: Do not preserve the original permissions; use the current user’s umask to set permissions.
  • -m: Do not restore the modification time of files when extracting, but use the current time.

Archive management options

  • -k or --keep-old-files: Keep existing files when extracting; do not overwrite.
  • --overwrite: Force overwriting existing files when extracting.
  • --remove-files: Delete the original files after a successful archive.
  • --delete: Delete the specified files from the archive file (only gnu tar).
  • --keep-newer-files: Keep files that are newer than those in the archive when extracting.
  • --listed-incremental=<file>: Create an incremental backup or restore from an incremental backup.

File system and device options

  • -L <N>: Split archive files larger than N bytes (for tape drives).
  • --tape-length=<number>: Specify the tape length (for tape drives).
  • --multi-volume: Create or restore multi-volume archive files.
  • -M: Used together with --multi-volume to handle multi-volume archive files.
  • --use-compress-program=<prog>: Use the specified compression program.

Other useful options

  • --transform=<expression>: Rename files in the archive.
  • --strip-components=<number>: Strip the specified number of path components when extracting.
  • --ignore-failed-read: Ignore read errors and continue the operation.
  • --occurrence=<number>: Select the number-th occurrence of a file in the archive.
  • -S: Handle sparse files (only archive the blocks actually used).
  • --no-recursion: Do not recurse into directories.
  • -h or --dereference: Archive the files that symbolic links point to rather than the links themselves.

Help and version information

  • --help: Display help information.
  • --version: Display the version information of tar.
mkdir

Full name: make directory — used to create directories Format: mkdir -p dirName

Options

  • -p: Create a multi-level directory structure; if the parent directory does not exist, it will be created automatically
  • -m: Set permissions, e.g., mkdir -m 755 my_directory
  • -Z: Set the security context for the directory
  • -v: Display detailed information, including the directories being created
  • -Z: Set the security context for the directory
  • --help: Display help information.
  • --version: Display the version information of tar.
awk

A powerful text processing tool Format: awk options ‘pattern {acation}’ file Option parameter description:

  • options: These are the options used to control the behavior of awk.
  • pattern: This is the pattern used to match the input data. If omitted, awk operates on all lines.
  • : This is the action executed on the lines that match the pattern. If omitted, the default action is to print the entire line.

options parameter description:

  • -F <separator> or --field-separator=<separator>: Specify the input field separator; the default is a space or a tab. For example, awk -F: ‘{print $1}’ /etc/passwd uses the colon as the separator and prints the first field of each line of the /etc/passwd file.
  • -v <variable name>=<value>: Define a variable for the awk script. For example, awk -v var=10 '{print $1 + var}' file.txt sets the variable var to 10 and adds 10 to the first field of each line in the file.
  • -f <script file>: Specify a file containing the awk script. For example, awk -f script.awk data.txt executes the script in script.awk to process the data.txt file.
  • -V or --version: Display the version information of awk.
  • -h or --help: Display the help information of awk, including options and usage examples.

If you enjoyed this, leave a comment~

... Page views
© 2021 - 2026 Vullfin @VV
Powered by theme astro-koharu · Inspired by Shoka