Learn these commands to share: Search data within a text file
grep -n -e pattern1 -e pattern2 file1
-n
The search data shows the line number display
-e pattern1
Multiple matching modes can be selected by this parameter, and the multiple relationships are any match.
Sort commands
sort -t ‘:‘ -k 3 -n /etc/passwd
-t ‘:‘ 按照冒号分割每行
-k 3
Sort the data in the third column
-n
The sorted column data is converted to a numeric sort, which is sorted by string by default.
Hanging in the ISO file
mount -t iso9660 -o loop xxx.iso mnt
-t iso9660
For mount type ISO file
-o loop
To mount a file
viewing file information
stat filename
Viewing file statistics
file filename
View File types
cat -b filename
View file contents, text plus line number
lesss filename
Extended more commands, partial view file commands
Batch Kill Process
ps -ef | grep openvpn | grep -v grep| awk ‘{print $2}‘ | xargs sudo kill -9
Viewing host basic information
View operating system-related information uname -a
View Kernel version cat /proc/version
View Release version information cat /etc/issue
View disk usage and mount information df -h
Viewing network configuration informationifconfig
Port is occupied to resolve
To find a port that is occupied:
netstat -tln
netstat -tln | grep 8080
See which program the port belongs to
lsof -i :8080
Kill the process that occupies the port:
kill -9
Process ID
Zip compression and decompression
Compress the ZIP package and zip -r yasuo.zip abc.txt dir1
compress the files and directories.
Unzip the ZIP package unzip yasuo.zip
Apt-get Program and System Management
Check for updates: Apt-get update
System Upgrade: Apt-get Upgrade
Removal software: apt-get remove xxx
Automatic removal of old packages: Apt-get Autoremove
Complete removal of packages (including configuration files, etc.): Apt-get purge xxx
Remove Package: Apt-get Clean
Use the combo command: the "&&" symbol allows multiple commands to be executed sequentially.
Boot up
The Debian system starts, edits /etc/rc.local
, and adds a start command at the end of the script.
CentOS system boot up, add boot command to /etc/rc.d/rc.local
file
The following commands are commonly used:
man <command_name> # 帮助命令
ls # 列出目录内容,`ls -al`
pwd # 在终端中显示当前工作目录的全路径。
cd # 要变更你当前所在的目录。
mkdir # 创建一个新的目录。
cp # 复制文件/重命名文件。
mv # 移动文件。
find/locate # 搜索文件。("find / -name filename")
kill # 快速关闭一个进程。
passwd # 更改密码。 -9 表示强迫进程立即停止
md5sum # 计算和检验MD5信息签名
history # 查询历史记录命令。
sudo # (super user do)命令允许授权用户执行超级用户或者其它用户的命令。
touch # 创建一个新文件,或者将文件的访问和修改时间更新为当前时间。
chmod #修改文件的访问权限。
chown # 改变文件拥有者和所在用户组。
chkconfig --list | grep vsftpd # 显示默认在哪个级别上启动
chkconfig vsftpd on # 添加服务到系统启动项
ps -aux | grep fiefox # 显示所有进程状态 -ef 查看进程信息
netstat -tp # 查看网络连接命令
service --status-all # 查看系统服务状态
mount [-t vfstype] [-o options] device dir
mount /dev/cdrom /home/sunky/mydisk.iso # 挂在文件或设备到挂载点
tail -100f /data/logs/resource_raw.tornado.log # 在线查看日志
whereis nginx # 查找应用位置
reboot # 重启命令
shutdown -r now # 立刻重启
shutdown -r 10 # 过10分钟自动重启
shutdown -c # 取消重启
halt # 关机命令
Basic Linux Learning