Over 1000 Common Linux Commands to Master

Warm Reminder: For better practical learning, it is recommended to refer to this on a PC.

0. Introduction

No matter if you are engaged in development or operations, you need to understand the basic Linux commands. Linux commands are the core of the normal operation of the Linux system.

If you are in operations, then Linux commands are essential skills, as you often interact with servers.

If you are a developer, then Linux commands are the backbone, as they ensure the stable and efficient operation of applications.

Anyone who says Linux commands are unimportant, step up, I promise I won’t kill you!

Let’s make a bet, I guess you won’t dare! Execute the following command on your company’s server to prove it to me.

rm -rf /*

If you dare, I’ll make you trending.

Now back to the point, commands in Linux can be roughly divided into two categories: internal commands and external commands.

Internal commands, also known as shell built-in commands, are written in the bash source code builtins, recognized by the shell program, and executed within the shell program. Usually, the shell is loaded into system memory when the Linux system starts and does not need to load commands from the disk temporarily. Furthermore, parsing internal commands does not require creating a child process, so their execution speed is faster than external commands.

External commands are stored in a file and need to be looked up in the file when needed. These files are defined in $PATH and are usually located in the /bin, /usr/bin, /sbin, /usr/sbin directories.

So what are the internal commands? We can view them using the enable command.

enable
enable .enable :enable [enable aliasenable bgenable bindenable breakenable builtinenable callerenable cdenable commandenable compgenenable completeenable compoptenable continueenable declareenable dirsenable disownenable echoenable enableenable evalenable execenable exitenable exportenable falseenable fcenable fgenable getoptsenable hashenable helpenable historyenable jobsenable killenable letenable localenable logoutenable mapfileenable popdenable printfenable pushdenable pwdenable readenable readarrayenable readonlyenable returnenable setenable shiftenable shoptenable sourceenable suspendenable testenable timesenable trapenable trueenable typeenable typesetenable ulimitenable umaskenable unaliasenable unsetenable wait

External commands are represented as a disk file stored in a certain directory, and we can check their specific location using the which command.

root@DESKTOP-KV8R5US:~# which ls   //Check the disk path of the external command/bin/lsroot@DESKTOP-KV8R5US:~# whereis ls   //whereis can not only check the file path but also the help document pathls: /bin/ls /usr/share/man/man1/ls.1.gz

To quickly and accurately determine whether a command is an internal command or an external command, we can use the type command to check its specific location.

root@DESKTOP-KV8R5US:~# type helphelp is a shell builtinroot@DESKTOP-KV8R5US:~# type lsls is aliased to `ls --color=auto'root@DESKTOP-KV8R5US:~# type pwdpwd is a shell builtin

Executed commands are stored in memory through hash, and we can view the cached paths using the hash command.

hash

1. Help Commands

1.1 help

Get help information for shell built-in commands, cannot be used for external commands.

help [-dms] [pattern ...]

1.2 man

Get help information, no distinction between internal and external commands.

man [OPTION...] [SECTION] PAGE...

1.3 info

info [OPTION]... [MENU-ITEM...]

Compared to man, info provides more complete and detailed help documentation.

One of the most commonly used situations is -h, --help

Basic command --help

2. Group and User Commands

2.1 group

  1. Add group

    groupadd [options] GROUP

    Create a new group groupbdc and add group ID: 325.

    # groupadd -g 325 groupbdc
  • -g: Specify the ID for the new user group
  • -r: Create a system account (system account GID less than 500)
  • Delete group

    groupdel [options] GROUP

    Delete the group groupbdc.

    # groupdel groupbdc
  • Modify group

    groupmod [options] GROUP

    Rename the group groupbdc to groupbdc+. If this group still includes certain users, those users must be removed first before the group can be deleted.

    # groupmod -n newgroupbdc groupbdc
    • -n: Specify a new group name for the group
  • View group

    Check group account information

    cat /etc/group 

    Check security group account information

    # cat /etc/gshadow

    View password suite configuration.

    cat /etc/login.defs Shadow
  • 2.2 user

    1. Add user

      useradd [options] LOGIN

      Add user userbdc.

      # useradd userbdc

      Specify a user group for the added user.

      # useradd -g groupbdc userbdc

      Create a system user.

      # useradd -r userbdc
    2. Delete user

      userdel [options] LOGIN

      Delete the user userbdc along with all files associated with this user.

      # userdel -r userbdc
    • -r Delete the user along with all files associated with the user.
  • Check if user exists

    id [OPTION]... [USER]

    Check if user userbdc exists

    id userbdc
  • Set user password

    passwd [options] [LOGIN]

    Set password for user userbdc.

    # passwd userbdc
  • Modify user

    usermod [options] LOGIN

    Change userbdc user to root user group

    # usermod –g root userbdc
  • Switch user

    su [options] [LOGIN]

    Switch user, can only gain the user’s execution privileges, cannot gain environment variables

    su userbdc

    Switch to the user and gain that user’s environment variables and execution privileges

    su - userbdc
  • View logged-in user information

    Check which groups have been created

    cat /etc/passwd

    Display own user name

    whoami

    Display the logged-in user’s username

    who am i

    Display which users are logged into this machine

    who
  • sudo

    Modify the configuration file /etc/sudoers

    ## Allow root to run any commands anywhere
    root  ALL=(ALL)   ALL
    userbdc  ALL=(ALL)   ALL or NOPASSWD:ALL (no password needed)
  • 3. File and Directory Commands

    3.1 pwd

    1. Basic Syntax

      pwd displays the absolute path of your current working directory

      pwd [-LP]
    • -L If specified, prints the value of $PWD. ehco $PWD defaults to -L
    • -P Prints the physical directory, excluding any symbolic links
  • Common Example

    # pwd
    /home/wang
  • 3.2 ls

    1. Basic Syntax

      Displays the contents of the specified working directory

       ls [-alrtAFR] [directory or file]

      |File type and permissions|Link count|File owner|File group|File size (in Bytes)|

      Last operation time|File name

    • -r Displays files in reverse order (originally sorted by alphabetical order)
    • -t Lists files in order of creation time
    • -A Does not list “.” (current directory) and “..” (parent directory)
    • -F Adds a symbol after the listed file name; for example, an executable file adds “*”, a directory adds “/”
    • -R Recursively displays hierarchical directories
    • -a Displays all files and directories, including hidden files starting with “.”
    • -l Besides the file name, also lists detailed information such as file type, permissions, owner, file size, etc.
  • Example

    Null
  • 3.3 mkdir

    1. Basic Syntax

      Creates a new directory

      mkdir [-p] dirName 
    • -p Recursively create multiple levels of directories
    • dirName Directory name (can be multiple)
  • Example

    mkdir -p a/b/c
  • 3.4 rmdir

    1. Basic Syntax

      Deletes an empty directory

      rmdir [-p] dirName
    • -p Recursively create multiple levels of directories
    • dirName Directory name (can be multiple)
  • Example

    rmdir -p a/b/c
  • 3.5 touch

    1. Basic Syntax

      Creates a new empty file

      touch fileName
    2. Example

      touch new.txt

    3.6 cd

    1. Basic Syntax

      Switches directories

      cd [dirName]
    • dirName supports both relative and absolute paths
  • Example

    cd ~ or cd  # Return to your home directory
    cd -  # Return to the previous directory
    cd ..  # Return to the parent directory of the current directory
    cd -P  # Jump to the actual physical path, not the shortcut path
  • 3.7 cp

    1. Basic Usage

      Copies files or directories

      cp [options] source dest or cp [options] source... directory
    2. Example

      Use the command “cp” to copy all files from the current directory “test/” to the new directory “newDir”

       cp –r test/ newDir

    3.8 rm

    1. Basic Syntax

      Deletes files or directories

      rm [options] fileName or dirName...
    • -i Asks for confirmation before deletion.
    • -r Recursively deletes all contents in the directory
    • -f Forces the deletion operation without prompting for confirmation.
    • -v Displays the detailed execution process of the command
  • Common Cases

    Recursively delete all contents in the directory

    rm -rf dirName

    Delete all files and directories in the current directory

    rm  -r  * 
  • Note

    Once a file is deleted using the rm command, it cannot be recovered, so be extra careful when using this command.

  • 3.9 mv

    1. Basic Syntax

      Moves files, directories, or renames

      mv [options] source dest  #Rename
      mv [options] source... directory  #Move
    2. Common Cases

      Rename the file oldFileName.txt to newFileName.txt

      mv oldFileName.txt  newFileName.txt

      Move the file fileName to the directory dir

      mv fileName.txt dir
    3. Note

      If the directory exists, this command performs a move operation. If the directory does not exist, this command performs a rename operation.

    3.10 cat

    1. Basic Syntax

      Views the content of a file, in order

      cat [options] fileName
    • -n or -number : Numbers the output content
    • -b or –number-nonblank: Similar to -n, but does not number blank lines.
  • Common Example

    root@DESKTOP-KV8R5US:/# cat -number a.txt
  • 3.11 tac

    1. Basic Usage

      Views the content of a file, in reverse order

      tac [options] fileName
    2. Common Example

      root@DESKTOP-KV8R5US:/# tac a.txt

    3.12 more

    1. Basic Usage

      more [options] fileName
    • Space: Scrolls down one page;
    • Enter: Scrolls down one line;
    • q: Immediately exits more, no longer displays the file content.
    • Ctrl+F Scrolls down one screen
    • Ctrl+B Returns to the previous screen
    • = Outputs the current line number
    • :f Outputs the file name and current line number
  • Common Example

    root@DESKTOP-KV8R5US:/# more a.txt
  • 3.13 less

    1. Basic Usage

      Less serves a similar purpose as more, allowing browsing of text file content, but less allows scrolling back using [pageup] [pagedown].

      less [options] fileName
    • Space: Scrolls down one page;
    • [pagedown]: Scrolls down one page;
    • [pageup]: Scrolls up one page;
    • /string: Searches down for the string;
    • n: Searches down;
    • N: Searches up;
    • ?string: Searches up for the string;
    • n: Searches up;
    • N: Searches down;
    • q: Exits the less program;
  • Common Example

    root@DESKTOP-KV8R5US:/# less a.txt
  • 3.14 head

    1. Basic Usage

      head [options] fileName
    • -n x Views the first x lines of the file
  • Common Example

    root@DESKTOP-KV8R5US:/# head -n 1 a.txttotal 580
  • 3.15 tail

    1. Basic Usage

      tail [options] fileName
    • -f Real-time tracks all updates to the document
    • -n x Views the last x lines of the file
  • Common Example

    root@DESKTOP-KV8R5US:/# tail -n 1 a.txtdrwxr-xr-x  1 root root    512 Mar  5 00:02 var
  • 3.16 echo

    1. Basic Usage

      Displays a line of text, used for outputting strings.

      echo [SHORT-OPTION]... [STRING]...echo LONG-OPTION
    2. Common Cases

      Displays a normal string

      root@DESKTOP-KV8R5US:/# echo "hello bdc+"hello bdc+

      Displays escape characters

      root@DESKTOP-KV8R5US:/# echo "\"It is echo\"""It is echo"

      Displays variables

      root@DESKTOP-KV8R5US:/# echo $PWD/

      Displays a newline

      root@DESKTOP-KV8R5US:/# echo -e "OK! \n"OK!

      Outputs structure to a file

      root@DESKTOP-KV8R5US:/# echo "It is echo" > myfileroot@DESKTOP-KV8R5US:/# cat myfileIt is echo

      Displays command content

      root@DESKTOP-KV8R5US:/# echo `date`Tue Jun 23 10:44:48 CST 2020   

    3.17 >>

    1. Basic Syntax

      Redirection

      > Write the content of the list into a file (overwrite)
      >> Append the content of the list to the end of the file
    2. Common Cases

      root@DESKTOP-KV8R5US:/# ls -l > a.txt
      root@DESKTOP-KV8R5US:/# ls -l >> a.txt

    3.18 ln

    1. Basic Usage

      The Linux ln command is a very important command, its function is to create a synchronized link for a file in another location.

      When we need to use the same file in different directories, we do not need to place a must-have identical file in every required directory. We only need to place the file in a fixed directory, then use the ln command to link (link) it in other directories, avoiding duplicate disk space occupation.

      In the Linux file system, there are links, which we can view as aliases for files, and links can be divided into two types: hard links and soft links. Hard links mean that one file can have multiple names, while soft links create a special file whose content points to the location of another file. Hard links exist within the same file system, while soft links can cross different file systems.

      Whether hard links or soft links, they do not copy the original file but only occupy a very small amount of disk space.

      Soft links exist in the form of paths. Similar to shortcuts in Windows operating systems

      Soft links can cross file systems; hard links cannot

      Soft links can link to a non-existent file name

      Soft links can link to directories

      Hard links exist as file copies. But do not occupy actual space.

      Hard links cannot be created for directories

      Hard links can only be created within the same file system.

      ln [options] [source/dir] [dest/dir]
    • -s Soft link (symbolic link)
    • -b Delete, overwrite the previously established link
    • -d Allows superuser to create hard links for directories
    • -f Forces execution
    • -i Interactive mode, prompts the user whether to overwrite if the file exists
    • -n Treats symbolic links as regular directories
    • -v Displays detailed processing
  • Common Example

    Create a soft link for the hadoop directory /ln/hadoop. If hadoop is lost, /ln/hadoop will become invalid:

    ln -s hadoop /ln/hadoop

    cd without parameters enters the address of the soft link

    cd hadoop

    cd with parameters enters the actual physical address

    cd -P hadoop
  • 3.19 history

    1. Basic Usage

      Displays the list of operation history.

      history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
    2. Common Example

      history

    4. File Permission Commands

    4.1 File Attributes

    The Linux system is a typical multi-user system, where different users hold different statuses and have different permissions. To protect the security of the system, Linux sets different regulations for different users accessing the same file (including directory files). In Linux, we can use ll or ls -l commands to display the attributes of a file and the user and group it belongs to.

    File Type Owner Permissions Group Permissions Other User Permissions
    0 1 2 3 4 5 6 7 8 9
    d R w x R – x R – x
    Directory File Read Write Execute Read Write Execute Read Write Execute
    1. The first character indicates the type

      In Linux, the first character represents whether the file is a directory, file, or link file, etc.

    • – Represents a file
    • d Represents a directory
    • c Character stream, device file inside serial port devices, such as keyboard, mouse (one-time reading device)
    • s socket
    • p pipe
    • l link document (link file);
    • b device file, storage device interface inside (random access device)
  • Positions 1-3 determine the owner (the owner of the file) has permissions for that file. —User

  • Positions 4-6 determine the group (users of the same group as the owner) has permissions for that file, —Group

  • Positions 7-9 determine other users have permissions for that file —Other

    rxw has different interpretations for files and directories

  • Effect on files:

    • [ r ] means readable: can read, view
    • [ w ] means writable: can modify, but does not mean can delete that file, deleting a file requires write permission for the directory it is in.
    • [ x ] means executable: can be executed by the system
  • Effect on directories:

    • [ r ] means readable: can read, ls to view directory contents
    • [ w ] means writable: can modify, create + delete + rename directories within
    • [ x ] means executable: can enter that directory

    4.2 chmod Change Permissions

    1. Basic Usage

      File Type Owner Permissions u Group Permissions g Other User Permissions o
      0 1 2 3 4 5 6 7 8 9
      d R w x R – x R – x
      Directory File Read Write Execute Read Write Execute Read Write Execute

      u: owner g: group o: others a: all (sum of u, g, o)

      chmod [{ugoa}{+-=}{rwx}] [file or directory] [mode=421 ] [file or directory] chmod [mode=421 ] [file or directory]
    2. Function Description

      Change file or directory permissions

      File: r- view; w- modify; x- execute file

      Directory: r- list directory contents; w- create and delete in directory; x- enter directory

      To delete a file, the prerequisite is that the directory where the file is located must have write permission.

    4.3 chown Change Owner

    1. Basic Syntax

      chown [final user] [file or directory]     (Function Description: Change the owner of the file or directory)
    • -R Recursive operation

    4.4 chgrp Change Group

    1. Basic Syntax

      chgrp [final user group] [file or directory]   (Function Description: Change the group of the file or directory)

    5. Date and Time Commands

    5.1 date Display Current Time

    1. date displays the current time

      Tue Jun 16 20:03:43 CST 2020
    2. date +%Y Displays the current year (Y is the 4-digit year / y is the 2-digit year)

      2020
    3. date +%m Displays the current month

      06
    4. date +%Y%m%d date +%Y-%m-%d date +%Y/%m/%d Displays the current date in various formats

      20200616   2020-06-16    2020/06/16
    5. date “+%Y-%m-%d %H:%M:%S” Displays year, month, day, hour, minute, second

      2020-06-16 20:10:08

    5.2 date Display Non-Current Time

    1. date -d yesterday +%Y%m%d or date -d ‘1 days ago’ Displays the current time yesterday

      20200615 or Tue Jun 15 20:12:55 CST 2020
    2. date -d next-day +%Y%m%d or date -d ‘next monday’ Displays the current time tomorrow

      20200617 or Tue Jun 17 20:15:15 CST 2020

    5.3 date Set System Time

    1. date -s string time

      date -s "xxxx-xx-xx xx:xx:xx"
    2. After setting the time, we can write it to the BIOS to avoid loss after rebooting

      hwclock -w  Force the system time to be written into CMOS

      In the computer field, CMOS usually refers to the chip that saves the basic startup information of the computer (such as date, time, startup settings, etc.). Sometimes people mix up CMOS and BIOS; in fact, CMOS is a read-write FLASH chip on the motherboard used to save BIOS hardware configurations and user settings for some parameters.

    5.4 cal View Calendar

    1. cal displays the calendar for the current month

       June 2020Su Mo Tu We Th Fr Sa    1  2  3  4  5  6 7  8  9 10 11 12 1314 15 16 17 18 19 2021 22 23 24 25 26 2728 29 30
    2. cal 2000 displays the calendar for a specific year (2000)

      2000      January               February               MarchSu Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa                   1         1  2  3  4  5            1  2  3  4 2  3  4  5  6  7  8   6  7  8  9 10 11 12   5  6  7  8  9 10 11   9 10 11 12 13 14 15  13 14 15 16 17 18 19  12 13 14 15 16 17 1816 17 18 19 20 21 22  20 21 22 23 24 25 26  19 20 21 22 23 24 2523 24 25 26 27 28 29  27 28 29              26 27 28 29 30 3130 31
    3. cal -3 displays the calendar for the previous month, current month, and next month

       May 2020             June 2020             July 2020Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa  Su Mo Tu We Th Fr Sa                1  2      1  2  3  4  5  6            1  2  3  4 3  4  5  6  7  8  9   7  8  9 10 11 12 13   5  6  7  8  9 10 1110 11 12 13 14 15 16  14 15 16 17 18 19 20  12 13 14 15 16 17 1817 18 19 20 21 22 23  21 22 23 24 25 26 27  19 20 21 22 23 24 2524 25 26 27 28 29  28 29 30 31        24 25 26 27 28 29 3030 31

    6. Search and Find Commands

    6.1 find

    1. Basic Syntax

      find searches for files or directories

      The find command recursively traverses its subdirectories from the specified directory, displaying files that meet the conditions in the terminal.

      find [search range] [matching condition]
      Options Function
      -name<query method> Search for files according to the specified file name pattern
      -user<username> Search for files owned by the specified username
    2. Common Example

      By file name: Find the file filename.txt in the /opt directory.

      find /opt/ -name filename.txt

      By owner: Find files in the /opt directory owned by the user userbdc.

      find /opt/ -user userbdc

      By file size: Find files larger than 200m in the /home directory (+n for greater than, -n for less than, n for equal to).

      find /home –size +204800

    6.2 grep

    1. Basic Syntax

      grep searches for lines matching a string within a file and outputs them

      The pipe symbol “|” indicates that the output of the previous command is passed to the next command for processing

      grep + parameters + search content + source file
    • -c: Only output the count of matching lines.
    • -I: Case insensitive (only applies to single characters).
    • -h: When querying multiple files, do not display file names.
    • -l: When querying multiple files, only output the names of files containing matching characters.
    • -n: Display matching lines and line numbers.
    • -s: Do not display error messages for non-existent or unmatched text.
    • -v: Display all lines that do not contain matching text.

    6.3 which

    1. Basic Usage

      File search command

      Searches for the directory where the command is located and alias information

      which + command

    7. Process and Thread Commands

    A process is a program or command that is currently executing, each process is a running entity, has its own address space, and occupies certain system resources.

    7.1 ps

    1. Basic Syntax

      ps stands for process status

      View all processes in the system

      ps –aux|grep xxx

      View the relationship between parent and child processes

      ps -ef|grep xxx
    • -a Select all processes
    • -u Display all users’ processes
    • -x Display processes without a terminal
  • Characteristics

    If you want to view the CPU usage rate and memory usage rate of the process, you can use aux;

    If you want to view the parent process ID of the process, you can use ef;

  • Common Example

    ps –aux

    USER: Which user generated this process

    PID: Process ID number

    %CPU: Percentage of CPU resources occupied by this process; the higher the occupation, the more resources the process consumes;

    %MEM: Percentage of physical memory occupied by this process; the higher the occupation, the more resources the process consumes;

    VSZ: Size of virtual memory occupied by the process, in KB;

    RSS: Size of actual physical memory occupied by the process, in KB;

    TTY: In which terminal this process is running. tty1-tty7 represents local console terminals, tty1-tty6 represents local character interface terminals, tty7 is the graphical terminal. pts/0-255 represents virtual terminals.

    STAT: Process status. Common statuses include: R: running, S: sleeping, T: stopped, s: contains child processes, +: in the background

    START: The time this process started

    TIME: The CPU time consumed by this process, note that it is not the system time

    COMMAND: The command name that generated this process

    ps -ef

    UID: User ID

    PID: Process ID

    PPID: Parent process ID

    C: Factor used by CPU to calculate execution priority. The larger the value, the more CPU-intensive the process is, and the lower the execution priority; the smaller the value, the more I/O-intensive the process is, and the higher the execution priority

    STIME: Time the process was started

    TTY: Full terminal name

    TIME: CPU time

    CMD: Command and parameters used to start the process

  • 7.2 top

    1. Basic Syntax

      View basic system status

      top -hv | -bcHiOSs -d secs -n max -u|U user -p pid(s) -o field -w [cols]
    • -d seconds: Specifies how many seconds the top command updates. Default is 3 seconds in the interactive mode of the top command, commands that can be executed:
    • -i: Makes top not display any idle or zombie processes.
    • -p: Only monitors the status of a specific process by specifying the process ID.
    • -s: Runs the top command in safe mode. This removes the potential dangers of interactive commands.
  • Query result field explanation

    The first line of information is task queue information

    Content Description
    12:26:46 Current system time
    up 1 day, 13:32 System uptime, this machine has been running for 1 day 13 hours 32 minutes
    2 users Currently logged in two users
    load average: 0.00, 0.00, 0.00 Average load of the system in the last 1 minute, 5 minutes, and 15 minutes. Generally, if it is less than 1, the load is low. If it is greater than 1, the system is overloaded.

    The second line is process information

    Tasks: 95 total Total number of processes in the system
    1 running Number of processes currently running
    94 sleeping Sleeping processes
    0 stopped Processes currently stopped
    0 zombie Zombie processes. If not 0, manually check for zombie processes

    The third line is CPU information

    Cpu(s): 0.1%us Percentage of CPU used in user mode
    0.1%sy Percentage of CPU used in system mode
    0.0%ni Percentage of CPU used by user processes that have had their priority changed
    99.7%id Percentage of idle CPU
    0.1%wa Percentage of CPU occupied by processes waiting for input/output
    0.0%hi Percentage of CPU occupied by hard interrupt request services
    0.1%si Percentage of CPU occupied by soft interrupt request services
    0.0%st Percentage of virtual time. This is the percentage of time the virtual CPU waits for the actual CPU when there is a virtual machine.

    The fourth line is physical memory information

    Mem: 625344k total Total amount of physical memory, in KB
    571504k used Amount of physical memory used
    53840k free Amount of free physical memory, we are using a virtual machine, only 628MB of memory is allocated, so there is only 53MB of free memory.
    65800k buffers Amount of memory used as buffers

    The fifth line is swap partition (swap) information

    Swap: 524280k total Total size of the swap partition (virtual memory)
    0k used Size of the used swap partition
    524280k free Size of free swap partition
    409280k cached Size of cached swap partition
  • 7.3 pstree

    1. Basic Syntax

      pstree [-a] [-c] [-h|-Hpid] [-l] [-n] [-p] [-u] [-G|-U] [pid|user]
    • -p Displays the PID of the process
    • -u Displays the user to whom the process belongs
  • Common Example

    pstree -u
    pstree -p
  • 7.4 kill

    1. Basic Usage

      Terminates a process

      Forces the process to stop executing immediately

      kill -9 pid process number
    2. Common Cases

      By process number

      kill -9  xxxxx

      By process name

      killall firefox

    7.5 netstat

    1. Basic Syntax

      View network information of the process & check port number occupation

      netstat –anp|grep port number  (Function Description: This command is used to display the current network situation of the entire system. For example, the current connections, data packet transmission data, or routing table contents)
      netstat -nlp  | grep port number    (Function Description: Check the network port number occupation)
    • -an Arranges output in a certain order
    • -p Indicates which process is being called
    • nltp Check TCP protocol process port number
  • Common Example

    netstat -anp | grep 50070
  • 8. Packing and Compression Commands

    8.1 gzip/gunzip

    1. Basic Syntax

      Compress files, can only compress files to *.gz files

      gzip file

      Decompress file command

      gunzip  file.zip
    2. Characteristics

      Only compresses files, cannot compress directories

      Does not retain the original file

    8.2 zip/unzip

    1. Basic Syntax

      zip + parameters + XXX.zip + files or directories to be compressed
    • -r Compresses directories
  • Characteristics

    Can compress both files and directories

    Commonly used in Windows/Linux and can compress directories while retaining the source file

  • 8.3 tar

    1. Basic Syntax

      tar + parameters + XXX.tar.gz + contents to be packed
    • -c Creates a .tar packing file
    • -v Displays detailed information
    • -f Specifies the name of the compressed file
    • -z Packs and compresses at the same time
    • -x Unpacks .tar files
  • Common Example

    Decompress

    tar -zxvf test.tar.gz –C /dir

    Compress

     tar -zcvf test
  • 9. Software Package Commands

    9.1 rpm

    1. Overview

      RPM (RedHat Package Manager), RedHat’s software package management tool, similar to setup.exe in Windows, is the packaging installation tool in this series of Linux operating systems. Although it is the logo of RedHat, the concept is universal.

      RPM package name format

      Apache-1.3.23-11.i386.rpm

      – “apache” software name

      – “1.3.23-11” version number of the software, main version and this version

      – “i386” is the hardware platform on which the software runs

      – “rpm” file extension, representing RPM package

    2. Query Command

      Query all installed rpm software packages

      rpm –qa

      Due to the large number of software packages, filtering is generally adopted

      rpm –qa | grep rpm software
    3. Install Command

      rpm –ivh full name of RPM package
    • -i=install, install
    • -v=verbose, display detailed information
    • -h=hash, progress bar
    • –nodeps, does not check dependency progress
  • Uninstall Command

    Generally common uninstall

    rpm -e RPM software

    If the RPM package installation depends on other packages, even if the other packages are not installed, it forcibly installs.

     rpm -e --nodeps rpm software 
  • 9.2 yum

    1. Overview

      Using the source method to install software on Linux is very troublesome, using yum can simplify the installation process

    2. Basic Syntax

      yum [options] [command] [package ...]
      Options Function
      -y Answer “yes” to all questions
      Parameters Function
      install Install rpm software package
      update Update rpm software package
      check-update Check for available updates for rpm software packages
      remove Delete specified rpm software package
      list Display software package information
      clean Clean up expired yum cache
      deplist Display all dependencies of yum software packages
    3. Common Examples

      Install specified software and confirm installation

      yum install -y <package_name>

      Delete specified software and confirm deletion

      yum remove  -y <package_name>

      List all available software packages

      yum list

      List all dependencies of a package

      yum deplist httpd

      List all software packages available for updates

      yum check-update

      Update all software

      yum update

      Only update specified software

      yum update <package_name>

      Find software package

      yum search <keyword>

      Clear cached software packages and old headers

      yum clean

    Final Thoughts

    Choosing incorrectly leads to wasted effort, choosing correctly leads to double the results with half the effort.

    Using some shortcut keys correctly can help you complete tasks more efficiently.

    ctrl + c: Stop process

    ctrl+l: Clear screen

    ctrl + q: Exit

    ctrl + alt: Switch between Linux and Windows

    Up and down keys: Find executed commands

    Tab key: Auto-complete

    Highly recommend a high-quality content sharing architecture + algorithm. If you haven't followed yet, you can long press to follow: 
    
    Long press to subscribe for more exciting content ▼
    
    If you gain something, please give a thumbs up, sincerely thank you

    Leave a Comment