Linux System Notes

Linux System Notes

Basic Commands

  1. Find IP address:
    ifconfig
  2. View all files in the current directory (including hidden files):
    ls -a

    or

    ll
  3. Check memory usage:
    df -h
  4. Check memory usage of each file in the current directory:
    du -sh ./*
  5. Check if a specific process is running, for example, Nginx,
    ps -ef|grep nginx
  6. Kill a running process, for example, Nginx,
    kill -9 <nginx process ID>
  7. Another way to kill a running process, for example, Nginx:
    pkill nginx
  8. Find files ending with .txt in the /home directory:
    find /home -name "*.txt"
  9. Same as above, but ignore case:
    find /home -iname "*.txt"
  10. Create a new file command:
    touch a.txt
  11. Create a new directory command:
    mkdir ./temp
  12. Create a multi-level directory command:
    mkdir -p /home/temp
  13. View current path command:
    pwd
  14. View system running status:
    top
  15. View system information:
    uname -a
  16. System reboot command:
    reboot
  17. System shutdown command:
    shutdown -t now
  18. Shell script execution command:
    ./ a.sh

    or

    sh a.sh
  19. Authorization command:
    chmod u+x a.sh

    or

    chmod -R 777 /home/a.sh

    or

    chown -R root:root /home/a.sh

Account Authorization Execution

  1. Switch account
    su - root
  2. Execute with highest authorization
    sudo command that requires input

Check Network Connectivity

  1. Network ping command:
    ping 192.168.1.1

    or

    ping www.baidu.com
  2. Network telnet command:
    telnet 192.168.1.1:8080
  3. Exit telnet command:
    quit

Remote Connection

  1. ssh username@remote server address:
    ssh [email protected]
  2. Specify port 2211:
    ssh -p 2211 [email protected]

Note: After entering the

ssh

remote connection command, you will be prompted to enter a password, just enter it to log in.

View Log Notes

  1. Dynamic log viewing command:
    tail -f xxx.log
  2. The first command can also be abbreviated as:
    tailf xxx.log
  3. View the last 10 lines of the log command:
    tail -10 xxx.log

Modify Permissions Notes

  1. Modify user and group permissions command:
    chown -R root:root /home
  2. Modify a single file or folder command:
    chmod 777 /home

Copy and Move

  1. Copy a file to another location:
    cp /home/a.txt /home/temp/a.txt
  2. Copy a folder to another location:
    cp -r /home/opt /home/temp
  3. Move a file to another location:
    mv /home/a.txt /home/temp
  4. Rename a file:
    mv ./a.txt ./b.txt

Delete Files

  1. Delete file command:
    rm xxx.txt
  2. Delete folder command:
    rm -rf /home

Note:

-r

means recursive, deleting a folder requires deleting each file recursively,

-f

means force execution.

SCP Remote File Transfer

  1. Copy a file from remote to local directory
scp [email protected]:/opt/soft/nginx-0.5.38.tar.gz /opt/soft/

Note: The above command downloads the file

nginx-0.5.38.tar.gz

from the

/opt/soft/

directory on the machine

10.10.10.10

to the local directory

/opt/soft/

.

  1. Upload local file to specified directory on remote machine
scp /opt/soft/nginx-0.5.38.tar.gz [email protected]:/opt/soft/
  1. If SCP has a custom port, such as 2222
scp -rp -P 2222 /opt/soft/nginx-0.5.38.tar.gz [email protected]:/opt/soft/

FTP Commands

  1. FTP connection command
ftp -inv username@ip address:port number
  1. SFTP connection command
sftp username@ip address:port number
  1. Download file from remote to local (download)
ftp> get readme.txt # Download readme.txt file
ftp> mget *.txt     # Download 
  1. Upload file from local to remote (upload)
ftp> put /path/readme.txt # Upload readme.txt file
ftp> mput *.txt           # Can upload multiple files
  1. Close FTP connection (any of the following three can be used)
bye
exit
quit

Package Management RPM Commands

  1. Install RPM package:
    rpm -ivh nginx.rpm
  2. Uninstall RPM package:
    rpm -e nginx
  3. View all installed RPM packages:
    rpm -qa
  4. View RPM packages containing the string
    nginx

    :

    rpm -qa|grep nginx
  5. View RPM package installation path:
    rpm -ql nginx

Compression and Decompression

  1. Compress tar package:
    tar -zcvf /home/a.tar.gz a.txt
  2. Decompress tar package:
    tar -zxvf /home/a.tar.gz /home
  3. Compress zip package:
    zip /home/a.zip a.txt
  4. Decompress zip package:
    unzip /home/a.zip /home

YUM Commands

  1. YUM update package:
    yum update
  2. YUM search package:
    yum search nginx
  3. YUM install package:
    yum install nginx
  4. YUM list all installed packages:
    yum list
  5. YUM remove package
yum remove package1                # Remove program package1
yum groupremove group1             # Remove program group group1
yum deplist package1               # View program package1 dependency status
  1. YUM clean cache
yum clean packages       # Clean software packages in cache directory
yum clean headers        # Clean headers in cache directory
yum clean oldheaders     # Clean old headers in cache directory

Vim Commands (for example, input:

vim a.txt

)

  1. Search command:
    /
  2. After searching, find downwards:
    n

    , upwards:

    N
  3. Jump to the last line command:
    gg
  4. Jump to the first line command:
    GG
  5. If you need to input or edit, just press the letter
    i

    .

  6. After editing, enter
    :x

    to save, or you can enter

    :wq

    , of course, you must press the

    ESC

    key before entering these commands.

  7. Force exit and save command:
    :wq!
  8. Force exit without saving command:
    :q!

Leave a Comment