LPIC Cheat Sheet 1- Basic Command Line Tools

LPIC Cheat Sheet 1- Basic Command Line Tools

$ echo        

Prints a text or an input to the output.

  • Use -n option to prevent printing newline (\n) to the output.
  • Shells have metacharacters (* ^ ( ) [ ] $ & < > ! ; ' ") that serve various purposes, including triggering actions or providing additional functionality. When printing these characters, use a backslash (\) before them to prevent any unwanted actions.

$ pwd        

This command prints the absolute path of current working directory. It displays the path starting from the root directory.

$ cd        

This command changes your current working directory.

  • Use cd .. to navigate to the parent directory.
  • Use cd ~ to navigate to your home directory.
  • Use cd - to navigate to your most recent directory.

$ type        

Displays type of the command or symbol, indicating whether its a shell bultin command or symbol or if it's not.

$ uname        

Simple tool for displaying system information.

  • Use -a for displaying all system information.
  • Use -r for displaying kernel release version.

$ ls        

List information about files and directories.

  • Use -l for line formatting and more useful files information.
  • Use -a for displaying all files, including hidden ones.

$ which        

Locate a command. but only if it resides in your PATH directories.

$ man        

Useful command for displaying system reference manual pages, including commands documentation, program syntax and so on.

  • Use -k for keyword searching
  • Use -S for navigating to a specific section.

$ history        

Displays your recent commands history.

  • Use !! to re-execute your most recent command.
  • Use ! followed by the commands line number in history to re-execute it.
  • .bash_history located in your home directory stores your history, except your current session.
  • Use -a to append current session history to the end of your history file.
  • Use -r to overwrite current session history to your history file.

$ nano
$ emacs
$ vim        

Most popular tools for editing text files.

  • Use nano for quick and fast file editing.
  • Use emacs and vim for more advanced file editing. these tools have amazing features including syntax highlighting and various hotkeys.

$ cat        

Displays a text file content to the output.

$ od        

Converts a text file content into an octal and other formats. It doesn't change the original file.

  • Use -x and -s for hexadecimal (base 16) and decimal (base 2) file formatting.

$ split        

Useful utility for splitting large text files into smaller chunks. it can divide up files using size, line count and so on.

  • Use -l for splitting based on line count.

$ sort        

Another useful tool for sorting file's data.

  • Use -n for sorting based on numeric order.

$ nl        

Displays line numbers of a text file.

$ more
$ less        

Tools for paging through large text files.

$ head        

Displays first lines of a text file (10 lines by default).

  • Use -n for displaying more or less lines.

$ tail        

Displays last lines of a text file (10 lines by default).

  • Use -n for displaying more or less lines.
  • Use -f for watching messages as they're added. great option for live logs monitoring.

$ wc        

Displays bytes count, words count and number of lines in a text file.

  • Use -l for displaying number of lines only.

$ md5sum
$ sha256sum
$ sha512sum        

Utilities for deploying different hash algorithms on files.

$ grep        

Powerful tool for filtering and searching a text file using regular expressions (regex).

  • Use -i for case insensitive searching pattern.
  • Use -r for search through files of a directory recursively.

$ [COMMAND] > [FILE]
$ [COMMAND] 2> [FILE]        

Redirects command's standard output (>) or error (2>) to a file. If it exists, overwrites it, if it doesn't, creates one.

$ [COMMAND] >> [FILE]
$ [COMMAND] 2>> [FILE]        

Redirects command's standard output (>) or error (2>) to a file. If it exists, appends to it, if it doesn't, creates one.

$ [COMMAND] &> [FILE]
$ [COMMAND] &>> [FILE]        

Use & in redirecting for both standard output and error redirections.

$ [COMMAND] < [FILE]        

Redirects standard input from specific file into a command.

$ [COMMAND] | [COMMAND]        

Piping is a technique for redirecting a command's standard output to another command's standard input.

要查看或添加评论,请登录

Rouzbeh Sabzehei的更多文章

  • NGINX Cheat Sheet 1 - Basics

    NGINX Cheat Sheet 1 - Basics

    $ sudo yum update $ sudo yum install nginx Installing nginx on RedHat/CentOS. $ sudo apt update $ sudo apt install…

    2 条评论

社区洞察

其他会员也浏览了