linux命令速查
所属分类 linux
浏览量 1512
LINUX COMMAND LINE CHEAT SHEET
1 - SYSTEM INFORMATION
uname -a # Display Linux system information
uname -r # Display kernel release information
cat /etc/redhat-release # Show which version of redhat installed
uptime # Show how long the system has been running + load
hostname # Show system host name
hostname -I # Display the IP addresses of the host
last reboot # Show system reboot history
date # Show the current date and time
cal # Show this month's calendar
w # Display who is online
whoami # Who you are logged in as
2 - HARDWARE INFORMATION
dmesg # Display messages in kernel ring buffer
cat /proc/cpuinfo # Display CPU information
cat /proc/meminfo # Display memory information
free -h #Displayfreeandusedmemory(- h forhumanreadable, -m for MB, -g for GB.)
lspci -tv # Display PCI devices
lsusb -tv # Display USB devices
dmidecode # Display DMI/SMBIOS (hardware info) from the BIOS
hdparm -i /dev/sda # Show info about disk sda
hdparm -tT /dev/sda # Perform a read speed test on disk sda
badblocks -s /dev/sda # Test for unreadable blocks on disk sda
3 - PERFORMANCE MONITORING AND STATISTICS
top # Display and manage the top processes
htop # Interactive process viewer (top alternative)
mpstat 1 # Display processor related statistics
vmstat 1 # Display virtual memory statistics 1秒钟刷新一次
iostat 1 # Display I/O statistics
tail 100 /var/log/messages
tcpdump -i eth0 # Capture and display all packets on interface eth0
tcpdump -i eth0 'port 80' # Monitor all traffic on port 80 ( HTTP )
lsof # List all open files on the system
lsof -u #Listfilesopenedbyu ser
free -h
watch date # Execute "date", showing periodic updates
lsof -n -P| grep ":80" | grep LISTEN #查看占用80端口的进程
4 - USER INFORMATION AND MANAGEMENT
id # Display the user and group ids of your current user.
last # Display the last users who have logged onto the system.
who # Show who is logged into the system.
w # Show who is logged in and what they are doing.
groupadd test # Create a group named "test".
useradd -c "John Smith" -m john # Create an account named john, with a comment of "John Smith" and create the user's home directory.
userdel john # Delete the john account.
usermod -aG sales john # Add the john account to the sales group
5 - FILE AND DIRECTORY COMMANDS
ls -al
pwd
mkdir directory
rm file
rm -r directory
rm -f file
rm -rf directory
cp file1 file2
cp -r source_directory
destination
mv file1 file2
ln -s /path/to/file linkname
touch file
cat file
less file
head file
tail file
tail -f file
6 - PROCESS MANAGEMENT
ps
ps -ef
ps -ef | grep processname
ps aux|grep java
top
htop
kill pid
killall program #Killallprocessesnamedp rocessname
bg # Display stopped or background jobs
fg # Brings the most recent background job to foreground
fg n # Bringsjobn totheforeground
processname & # Startp rogram inthebackground
7 - FILE PERMISSIONS
drwxr-xr-x
-rw-r--r--
第一位 d 目录 - 普通文件
execute x read r write w
user group other(world)
UGW
rwx rwx rwx chmod 777 filename
rwx rwx r-x chmod 775 filename
rwx r-x r-x chmod 755 filename
rw- rw- r-- chmod 664 filename
rw- r-- r-- chmod 644 filename
U = User
G = Group
W = World
r = Read
w = write
x = execute
- = no access
8 - NETWORKING
ifconfig -a
ifconfig eth0
ethtool eth0
ping host
whois domain
dig domain
dig -x IP_ADDRESS
host domain
hostname -i
hostname -I
wget http://domain.com/file
netstat -nutlp
9 - ARCHIVES (TAR FILES)
tar cf archive.tar directory
tar xf archive.tar
tar czf archive.tar.gz directory
tar xzf archive.tar.gz
tar cjf archive.tar.bz2 directory # Create a tar file with bzip2 compression
tar xjf archive.tar.bz2 # Extract a bzip2 compressed tar file
10 - INSTALLING PACKAGES
yum search keyword
yum install package
yum info package
rpm -i package.rpm
yum remove package
tar zxvf sourcecode.tar.gz
cd sourcecode
./configure
make
make install
11 - SEARCH
grep pattern file
grep -r pattern directory
locate name
find /home/john -name 'prefix*'
find /home -size +100M # Find files larger than 100MB in /home
12 - SSH LOGINS
ssh host
ssh user@host
ssh -p port user@host
13 - FILE TRANSFERS
scp file.txt server:/tmp
scp server:/var/www/*.html /tmp
scp -r server:/var/www /tmp
rsync -a /home /backups/
rsync -avz /home server:/backups/ # Synchronize files/directories between the local and remote system with compression enabled
14 - DISK USAGE
df -h
df -i # Show free and used inodes on mounted filesystems
fdisk -l
du -ah
du -sh
15 - DIRECTORY NAVIGATION
cd ..
cd # Go to the $HOME directory
cd /etc
16 - skills
查看占用80端口的进程 lsof -n -P| grep ":80" | grep LISTEN
nohup ./xxx.sh >/dev/null 2>&1 &
find . -name '*.tmp'|xargs rm -rf
上一篇
下一篇
程序员眼中的女人
高性能服务器性能优化
AOP要点整理
币圈修炼指南
让程序员抓狂的那些事儿
管理者必须掌握的七个实用管理工具