Linux System Notes
Basic Commands
- Find IP address:
ifconfig - View all files in the current directory (including hidden files):
ls -aor
ll - Check memory usage:
df -h - Check memory usage of each file in the current directory:
du -sh ./* - Check if a specific process is running, for example, Nginx,
ps -ef|grep nginx - Kill a running process, for example, Nginx,
kill -9 <nginx process ID> - Another way to kill a running process, for example, Nginx:
pkill nginx - Find files ending with .txt in the /home directory:
find /home -name "*.txt" - Same as above, but ignore case:
find /home -iname "*.txt" - Create a new file command:
touch a.txt - Create a new directory command:
mkdir ./temp - Create a multi-level directory command:
mkdir -p /home/temp - View current path command:
pwd - View system running status:
top - View system information:
uname -a - System reboot command:
reboot - System shutdown command:
shutdown -t now - Shell script execution command:
./ a.shor
sh a.sh - Authorization command:
chmod u+x a.shor
chmod -R 777 /home/a.shor
chown -R root:root /home/a.sh
Account Authorization Execution
- Switch account
su - root - Execute with highest authorization
sudo command that requires input
Check Network Connectivity
- Network ping command:
ping 192.168.1.1or
ping www.baidu.com - Network telnet command:
telnet 192.168.1.1:8080 - Exit telnet command:
quit
Remote Connection
- ssh username@remote server address:
ssh [email protected] - Specify port 2211:
ssh -p 2211 [email protected]
Note: After entering the
sshremote connection command, you will be prompted to enter a password, just enter it to log in.
View Log Notes
- Dynamic log viewing command:
tail -f xxx.log - The first command can also be abbreviated as:
tailf xxx.log - View the last 10 lines of the log command:
tail -10 xxx.log
Modify Permissions Notes
- Modify user and group permissions command:
chown -R root:root /home - Modify a single file or folder command:
chmod 777 /home
Copy and Move
- Copy a file to another location:
cp /home/a.txt /home/temp/a.txt - Copy a folder to another location:
cp -r /home/opt /home/temp - Move a file to another location:
mv /home/a.txt /home/temp - Rename a file:
mv ./a.txt ./b.txt
Delete Files
- Delete file command:
rm xxx.txt - Delete folder command:
rm -rf /home
Note:
-rmeans recursive, deleting a folder requires deleting each file recursively,
-fmeans force execution.
SCP Remote File Transfer
- 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.gzfrom the
/opt/soft/directory on the machine
10.10.10.10to the local directory
/opt/soft/.
- Upload local file to specified directory on remote machine
scp /opt/soft/nginx-0.5.38.tar.gz [email protected]:/opt/soft/
- 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
- FTP connection command
ftp -inv username@ip address:port number
- SFTP connection command
sftp username@ip address:port number
- Download file from remote to local (download)
ftp> get readme.txt # Download readme.txt file
ftp> mget *.txt # Download
- Upload file from local to remote (upload)
ftp> put /path/readme.txt # Upload readme.txt file
ftp> mput *.txt # Can upload multiple files
- Close FTP connection (any of the following three can be used)
bye
exit
quit
Package Management RPM Commands
- Install RPM package:
rpm -ivh nginx.rpm - Uninstall RPM package:
rpm -e nginx - View all installed RPM packages:
rpm -qa - View RPM packages containing the string
nginx:
rpm -qa|grep nginx - View RPM package installation path:
rpm -ql nginx
Compression and Decompression
- Compress tar package:
tar -zcvf /home/a.tar.gz a.txt - Decompress tar package:
tar -zxvf /home/a.tar.gz /home - Compress zip package:
zip /home/a.zip a.txt - Decompress zip package:
unzip /home/a.zip /home
YUM Commands
- YUM update package:
yum update - YUM search package:
yum search nginx - YUM install package:
yum install nginx - YUM list all installed packages:
yum list - YUM remove package
yum remove package1 # Remove program package1
yum groupremove group1 # Remove program group group1
yum deplist package1 # View program package1 dependency status
- 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
vim a.txt)
- Search command:
/ - After searching, find downwards:
n, upwards:
N - Jump to the last line command:
gg - Jump to the first line command:
GG - If you need to input or edit, just press the letter
i.
- After editing, enter
:xto save, or you can enter
:wq, of course, you must press the
ESCkey before entering these commands.
- Force exit and save command:
:wq! - Force exit without saving command:
:q!