-
常用命令
code
-n-新建窗口-r-使用已打开的窗口打开文件
grep
- -i - 忽略大小写
- -w 只显示全字符合的列。
- -x 只显示全列符合的列。
- -E 使用正则表达式
- 重定向 > 是覆盖模式,>> 是追加模式
- grep [options] PATTERN [FILE…]
- tail -f file
- less -N file
- htop
- scp
vim
- :set number 在编辑文件时显示行号
SYSTEM INFORMATION
uname -a- Display Linux system informationuname -r- Display kernel release informationcat /etc/redhat-release- Show which version of redhat installedcat /etc/issue- 查看 Linux 系统版本信息uptime- Show how long the system has been running + loadhostname- Show system host namehostname -I- Display the IP addresses of the hostlast reboot- Show system reboot historydate- Show the current date and timecal- Show this month’s calendarw- Display who is onlinewhoami- Who you are logged in as
HARDWARE INFORMATION
dmesg- Display messages in kernel ring buffercat /proc/cpuinfo- Display CPU informationcat /proc/meminfo- Display memory informationfree -h- Display free and used memory ( -h for human readable, -m for MB, -g for GB.)lspci -tv- Display PCI deviceslsusb -tv- Display USB devicesdmidecode- Display DMI/SMBIOS (hardware info) from the BIOShdparm -i /dev/sda- Show info about disk sdahdparm -tT /dev/sda- Perform a read speed test on disk sdabadblocks -s /dev/sda- Test for unreadable blocks on disk sda
PERFORMANCE MONITORING AND STATISTICS
top- Display and manage the top processeshtop- Interactive process viewer (top alternative)mpstat 1- Display processor related statisticsvmstat 1- Display virtual memory statisticsiostat 1- Display I/O statisticstail 100 /var/log/messages- Display the last 100 syslog messages (Use /var/log/syslog for Debian based systems.)tcpdump -i eth0- Capture and display all packets on interface eth0tcpdump -i eth0 'port 80'- Monitor all traffic on port 80 ( HTTP )lsof- List all open files on the systemlsof -u user- List files opened by userfree -h- Display free and used memory ( -h for human readable, -m for MB, -g for GB.)watch df -h- Execute “df -h”, showing periodic update
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
FILE AND DIRECTORY COMMANDS
ls -al- List all files in a long listing (detailed) formatpwd- Display the present working directorymkdir directory- Create a directoryrm file- Remove (delete) filerm -r directory- Remove the directory and its contents recursivelyrm -f file- Force removal of file without prompting for confirmationrm -rf directory- Forcefully remove directory recursivelycp file1 file2- Copy file1 to file2cp -r source_directory destination- Copy source_directory recursively to destination. If destination exists, copy source_directory into destination, otherwise create destination with the contents of source_directorymv file1 file2- Rename or move file1 to file2. If file2 is an existing directory, move file1 into directory file2ln -s /path/to/file linkname- Create symbolic link to linknametouch file- Create an empty file or update the access and modification times of file.cat file- View the contents of fileless file- Browse through a text filehead file- Display the first 10 lines of filetail file- Display the last 10 lines of filetail -f file- Display the last 10 lines of file and “follow” the file as it grows.
PROCESS MANAGEMENT
ps- Display your currently running processesps -ef- Display all the currently running processes on the system.ps -ef | grep processname- Display process information for processnametop- Display and manage the top processeshtop- Interactive process viewer (top alternative)kill pid- Kill process with process ID of pidkillall processname- Kill all processes named processnameprogram &- Start program in the backgroundbg- Display stopped or background jobsfg- Brings the most recent background job to foregroundfg n- Brings job n to the foreground
NETWORKING
ifconfig -a- Display all network interfaces and ip addressifconfig eth0- Display eth0 address and detailsethtool eth0- Query or control network driver and hardware settingsping host- Send ICMP echo request to hostwhois domain- Display whois information for domaindig domain- Display DNS information for domaindig -x IP_ADDRESS- Reverse lookup of IP_ADDRESShost domain- Display DNS ip address for domainhostname -i- Display the network address of the host name.hostname -I- Display all local ip addresseswget http://domain.com/file- Download http://domain.com/filenetstat -nutlp- Display listening tcp and udp ports and corresponding programs
ARCHIVES (TAR FILES)
tar cf archive.tar directory- Create tar named archive.tar containing directory.tar xf archive.tar- Extract the contents from archive.tar.tar czf archive.tar.gz directory- Create a gzip compressed tar file name archive.tar.gz.tar xzf archive.tar.gz- Extract a gzip compressed tar file.tar cjf archive.tar.bz2 directory- Create a tar file with bzip2 compressiontar xjf archive.tar.bz2- Extract a bzip2 compressed tar file.
INSTALLING PACKAGES
yum search keyword- Search for a package by keyword.yum install package- Install package.yum info package- Display description and summary information about package.rpm -i package.rpm- Install package from local file named package.rpmyum remove package- Remove/uninstall package.Install software from source code.
tar zxvf sourcecode.tar.gz cd sourcecode ./configure make make install
SEARCH
grep pattern file- Search for pattern in filegrep -r pattern directory- Search recursively for pattern in directorylocate name- Find files and directories by namefind /home/john -name 'prefix*'- Find files in /home/john that start with “prefix”.find /home -size +100M- Find files larger than 100MB in /home
SSH LOGINS
ssh host- Connect to host as your local username.ssh user@host- Connect to host as userssh -p port user@host- Connect to host using port
FILE TRANSFERS
scp file.txt server:/tmpSecure copy file.txt to the /tmp folder on serverscp server:/var/www/*.html /tmpCopy *.html files from server to the local /tmp folder.scp -r server:/var/www /tmpCopy all files and directories recursively from server to the current system’s /tmp folder.rsync -a /home /backups/Synchronize /home to /backups/homersync -avz /home server:/backups/Synchronize files/directories between the local and remote system with compression enabled
DISK USAGE
df -h- Show free and used space on mounted filesystemsdf -i- Show free and used inodes on mounted filesystemsfdisk -l- Display disks partitions sizes and typesdu -ah- Display disk usage for all files and directories in human readable formatdu -sh- Display total disk usage off the current directory
DIRECTORY NAVIGATION
- To go up one level of the directory tree. (Change into the parent directory.)
- Go to the $HOME directory
- Change to the /etc directory