The shell command for Linux

Source: Internet
Author: User
Tags parent directory

Start contacting the Linux command line to learn about the Linux file system navigation and the commands needed to create, delete, and process files.

Note: At the end of the article there are benefits! Several shortcut keys:
    • Linux distributions typically use the Ctrl+alt key combination with F1~F7 to enter the console you want to use, the same key to return to the graphical interface, and Ubuntu to use F7,rhel F1.
    • In Ubuntu unity, you can use Ctrl+alt+t to quickly access gnome endpoints.
    • Shift+ctrl+n launches a new shell session in a new terminal window.
    • Shift+ctrl+t launches a new shell session in the new tab in the existing Terminal window.
    • Shift+ctrl+w closing a session in the current tab
    • Shift+ctrl+q closing the current terminal session
Basic Bash Shell command:
  • Man: View command manuals, such as: Man Mans
    The manual page is displayed by the paging program, the Space bar page, enter the line view, arrow keys before and after scrolling, Q key exit.
  • PWD: Shows the current directory of the shell session
  • CD: You can switch directly to the directory under the absolute file path, or you can switch to a directory under the relative file path, for example, if you are currently in the home directory, you can use the CD docuemnts command directly when you want to switch to the documents subdirectory. You can also use the double-dot character to switch to the parent directory, such as: CD. /downloads
  • LS: Displays files and directories in the current directory
    It has several parameters:
    Ls-f: Districts separate files and directories
    Ls-a: Show hidden files and normal files and directories together (LS does not show hidden files by default)
    Ls-l: Output detailed information for each file in a long-list format
    Ls-r: Recursive option to list files in subdirectories contained in the current directory
    You can have more than one parameter or merge to write:

    ls -F -Rls -FR  
  • The LS command also supports defining filters on the command line. This filter is a string for simple text matching. You can use the name of a particular file as a filter, and the LS command displays only the information for that file. Such as:

    ls -l my_script  
  • The LS command also recognizes standard wildcard characters and uses them for pattern matching in filters:
    1. Question mark (?) : Represents a character
    2. Asterisk (*): 0 or more characters on behalf of
    3. Brackets []: The position of a character has more than one possible choice, you can also specify a range of characters
    4. Exclamation point (!) : Exclude unwanted content

        ls -l my_scr?pt    ls -l my_s*t    ls -l my_scr[ai]pt    ls -l my_scr[a-i]pt    ls -l my_scr[!a]pt

    File extension matching can also be used with shell commands other than LS.

The shell provides many commands for manipulating files on a Linux file system, and this article learns some basic shell commands about files and directories.

1. Working with files
    • Touch: Create an empty file

      $ touch test_one$ ls -l test_one  
    • CP: Copying Files
      In the most basic usage, the CP command requires two parameters---the source object and the target object:

      cp source destination

      When both the source and destination parameters are filenames, the CP command copies the sources to a new file and is named destination.

      $ cp test_one test_two        $ ls -l test_*

The CP command does not remind you if the target file already exists, so it is best to add the-I option to force the shell to ask whether to overwrite the existing file.

$ cp -i test_one test_two
    • The CP command can also copy files into an existing directory with the same name as the source file

      $ cp -i test_one /home/christine/Documents/

      You can also use relative paths:

      $ cp -i test_one Documents/
    • The CP command has an-R parameter that can be used to recursively replicate the contents of the entire directory in a single command.

      $ cp -R Scripts/ Mod_Scripts$ ls -Fd *Scripts   (d参数是只列出目录本身信息,不列出其中内容)

      The directory mod_scripts does not exist until the cp-r command is executed, and he is created with the Cp-r command, and the contents of the entire scripts directory are copied to it.

    • MV: Renaming files
      The MV command can move a file or directory to another location or rename it.

      $ mv fall fzll$ mv fzll Pictures/

      You can also use the MV command to move the file location and modify the file name:

      $ mv/home/christine/Picture/fzll /home/christine/fall
    • RM: Deleting files
      Basic format:

      $ rm -i fall

      If you want to delete a lot of files and are not disturbed by the prompt, you can use the-f parameter to force the deletion.

2. Working with Catalogs
    • mkdir New_dir: Creating a Directory
    • You want to create multiple directories and subdirectories at the same time. You need to include the-p parameter:

      $ mkdir -p New_Dir/Sub_Dir/Under_Dir$ ls -R New_Dir
    • RMDIR: Deleting a directory
      By default, the rmdir command only removes empty directories, and if there are files in the directory, delete the files first.
      Using the-r option allows the command to go down to the directory, delete the files in it, and then delete the directory itself.

      $ rm -ri New_Dir
    • RM-RF command: Directly forces the deletion of the directory and all its contents without prompting.
3. View Files
    • File New_dir: Viewing files Type
    • Cat test_one: Viewing file contents
      Several parameters of the cat command:
      -N: Add line numbers to all rows
      -B: Add line numbers only to lines of text (that is, line numbers that omit blank lines)
      -T: Do not allow tabs to appear

    • The more command: The more command is the paging tool, which can be accessed by a space or a carriage return and the Q key exits.

    • Less command: One screen at a time to display a text file, can identify the upper and lower keys and page up and down.
    • Tail Command: Displays the contents of the last few lines of the file, showing the end of the file at 10 lines by default.
      The tail command joins the-n parameter to modify the number of rows displayed:

      $ tail -n 2 test_one

      The-f parameter allows you to view the contents of a file while other processes are using it. and the tail command remains active, displaying the content added to the file, which can be used to monitor the system log in real time.

    • Head command: Displays the contents of the first few lines of the file. There is also the-n parameter, but no-f argument.

Recommend a conscience public number "IT resources":

This public number is committed to free sharing of the best video resources, learning materials, interview experience, Front end, Php,java, algorithms, Python, big Data and so on, which you want to have

IT Resources-QQ Exchange Group: 625494093

Can also add pull you into the group: super1319164238

Search public Number: Itziyuanshe or scan the QR code below direct attention,

The shell command for Linux

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.