A basic Bash shell command (based on Ubuntu implementation)

Source: Internet
Author: User
Tags create directory touch command

A basic Bash shell command (based on Ubuntu implementation) The/etc/passwd file contains a list of all system user accounts and basic configuration information for each user. Man command

Enter the man command before the name of the tool you want to find, and you'll find the manual entry for that tool.

    • Space PAGE Down
    • Carriage return downward line-wise
    • b PAGE Up
    • Q exit

Linux top-level virtual directory names and their contents

Traverse Directory CD command
$ CD Destination
    • Absolute file path: The absolute file path always starts with a forward slash (/), indicating the root directory of the virtual file. You can clearly indicate exactly where the user wants to switch to.
    • Relative file path: Allows the user to specify a destination file path based on the current location. Relative file paths do not start with a forward slash (/) that represents the root, but instead begin with a directory name or a special character.
$ pwd

The PWD command can display the current directory of the shell session.

    1. A single dot (.) indicates the current directory;
    2. Double dot character (.. ) represents the parent directory of the current directory
Basic list Function ls command

The most basic form of the LS command displays the files and directories in the current directory

$ ls
    1. The-f parameter of the LS command easily distinguishes between files and directories
    2. The-a parameter displays the hidden file along with the normal file and directory.
    3. -D Displays the directory's own properties and does not display content.
    4. -r recursive option. Lists the files in subdirectories that are contained in the current directory.
    5. -L produces a long list of output that contains more information about each file in the directory.
    6. -L--time=atime Displays the access time of the file. (-l shows the modification time)
    7. -I view the inode number of a file or directory (the inode number is a unique number used for identification, assigned to each object in the file system by the kernel)

The information shown in each section is as follows:

Ls-f-R can be combined into ls-fr.

    • A question mark (?) represents a character;
    • An asterisk (*) represents 0 or more characters.

Ls-l can list information for a single specific file.

Create a File Touch command
$ Touch Test_one

Create an empty file with a file size of zero and your own user name as the owner.

The touch command can be used to change the file's modification time (while changing the access time).

    • -A changes access time only
Copy file CP command
$ cp Source destination
    1. is a file name, the CP command copies the source file into a new file and is named destination. There is a new modification time;
    2. Cp-i mandatory to ask if you need to overwrite existing files;
    3. You can assign a file to an existing directory (the tail of the target directory name plus a forward slash (/), or you will create a file with the same name as the tail directory);
    4. The cp-r replicates the entire contents of the directory recursively.
Tree command

Tree-shaped Display file structure

Link File ln command
    • Symbolic Links
    • Hard Links
Symbolic Link Example

Ln-n Original file Symbolic link name

[Email protected]:~/myubuntu$ls-L MN-rw-rw-r--1Li Li0October One  A: theMn[email protected]:~/myubuntu$LN-s MN sl_mn[email protected]:~/myubuntu$ls-L *mn-rw-rw-r--1Li Li0October One  A: themnlrwxrwxrwx1Li Li2October One  A: theMN, Sl_mn
Hard Link Example

ln Original file Hard link name

[Email protected]:~/myubuntu$ls-L *mn-rw-rw-r--1Li Li0October One  A: themnlrwxrwxrwx1Li Li2October One  A: theSl_mnMn[email protected]:~/myubuntu$ls-L MN-rw-rw-r--1Li Li0October One  A: theMn[email protected]:~/myubuntu$LNmn h_mn[email protected]:~/myubuntu$ls-L *mn-rw-rw-r--2Li Li0October One  A: theh_mn-rw-rw-r--2Li Li0October One  A: themnlrwxrwxrwx1Li Li2October One  A: theSL_MN-M
 [email protected]:~/myubuntu$ ls -il * MN  1578569 -rw-rw-r--2  li Li 0  October 11  22 : 49   h_mn  1578569 -rw-rw-r--2  li Li 0  October 11  22 : 49   mn  1582500  lrwxrwxrwx 1  li li 2  October 11  22 : 49  sl_mn- > MN 
Rename file mv command

The MV command can move files and directories to another location or rename them.

    • -I asks whether to overwrite an existing file when the command tries to overwrite it.
Delete File RM command
    • -I prompts you if you want to delete the file.
    • -F If you want to delete many files and are not disturbed by the prompt, the-f parameter is forced to delete.
Create directory mkdir command
    • -P Create multiple directories and subdirectories at the same time
Delete directory rmdir command

By default, the RmDir command removes only empty directories.

RM command
    • -R allows the command to go down to the directory, delete the file, and then delete the directory itself.
    • -I prompts whether to really delete
    • -ir after entering the directory, you will be prompted to delete each file
View file contents View File types: Files command
file my_file
View entire file: 1.cat command
Cat My_file
    • -N will add line numbers to all rows
    • -B adds line numbers only to lines with text
    • -T does not allow tabs to appear (renders ^t)
2.more command

The more command displays the contents of the text file, but stops after each page of data is displayed. Page Down the space, page up the B key (read to the end and exit, so to the end can not page up), enter downward line.

 More My_file
3.less command

More advanced features. You can scroll up and down (read to end to page UP, Q to exit)

View partial files: 1.tail command
Tail My_file

The tail command displays the contents of the last few lines of the file (the "tail" of the file). The default last ten lines.

    • -N Number: Only the last digit line is displayed
    • -Number: Show only the last digit line
    • -F: Allows you to view the contents of a file while other processes are using it. Keep active (Detect system logs)
2.head command
Head My_file

The head command displays the contents of the first few lines of the file (the "head" of the file). The default starts with 10 rows.

    • -N Number: Displays only the first digit line
    • -Number: Displays only the first digit line

There is no-f argument.

A basic Bash shell command (based on Ubuntu implementation)

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: info-contact@alibabacloud.com 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.