[笔记]Linux常用命令行

ls
directory listing
ls -l
long listing, display file ownersship
ls -la
display hidden files/directories

cd directory
cd /
cd ~
change directory

whoami
displays your logged in user id
 
mv [source_file] [target_file]

rm myfile
removes a file
rm -rf mydirectory/
removes a directory, recursively

pwd
prints working directory
the full path name

ln -s directory1 /usr/local/bin/npm
create soft link

which docker
which top
where is the executable located
/usr/bin/docker
/usr/bin/top

top
what is eating your cpu

ps -ef
displays informantion about a selection of the active process

ssh
secure shell, an encrypted network protocol allowing for remote login and command execution
an “ssh.exe” is also available via Cygwin as well as with a git installation
attention:on Windows:putty、winscp
 
who
display the user online's tty or pts
 

netstat -nultp

查看当前所有已经使用的端口情况

netstat -anp |grep 82

查看82端口的使用情况

netstat –an

查看当前打开的端口

 

查看Linux的系统信息

hostname

查看机器名

mksxy.centos

uname –a

查看系统内核

Linux mksxy.centos 2.6.32

cat /etc/centos-release

查看操作系统的版本

centos release 6.6

ifconfig

查看网络配置信息

当前有三个网卡:eth0,eth1,eth2,lo;

其中lo的ip是127.0.0.1,是用于测试的虚拟接口

fdisk –l

查看磁盘信息

df –h

查看磁盘信息

filesystem

/dev/sda2

tmpfs

/dev/sda1

/dev/sda5

cat /proc/cpuinfo

查看cpu的信息

cat /proc/meminfo

查看内存信息

 

天梯Linux命令总结

系统消息  
关机(系统的关机、重启、登出)

shutdown -h now  关闭系统

init 0  关闭系统

telinit 0  关闭系统

shutdown -h hours:minutes &  按预定时间关闭系统

shutdown -r now  重启

reboot  重启

logout  注销

文件和目录  
文件搜索  
磁盘空间

df -h  显示已经挂载的分区列表

ls -ISr |more  以尺寸大小排列文件和目录

du -sh dir1  估算dir1已经使用的磁盘空间

du -sk * | sort -rn  以容量大小为依据依次显示文件和目录的大小

rpm -q -a --qf '%10{SIZE}t%{NAME}n' | sort -k1,1n  以大小为依据依次显示已经安装的rpm包所使用的空间(Fedora、Redhat类系统=)

dpkg-query -W -f= '${Installed-Size;10}t${Package}n' | sort -k1,1n  以大小为依据显示已经安装的deb包所使用的空间(Ubuntu、Debian类系统)

用户和群组  
文件的权限(使用+设置权限,使用-用于取消)  
文件的特殊属性(使用+设置权限,使用-用于取消)

chattr +a file1  只允许以追加的方式读写文件

chattr +c file1  允许这个文件被内核自动压缩、解压

chattr +d file1  在进行文件系统备份时,dump程序将忽略这个文件

chattr +i file1  设置成不可变的文件,不能被删除、修改、重命名、链接

chattr +s file1  允许一个文件被安全地删除

chattr +S file1  一旦应用程序对这个文件进行了写操作,使系统立刻把修改的结果写到磁盘

chattr +u file1  若文件被删除,系统允许在以后恢复这个文件

lsattr  显示特殊的属性

打包和压缩文件

bunzip2 file1.bz2  解压file1.bz2的文件

bzip2 file1  压缩file1文件

gunzip file1.gz  解压file1.gz的文件

gzip file1  压缩file1文件

gzip -9 file1  最大程度压缩file1文件

unrar x file1.rar  解压file1.rar包

rar x file1.rar  解压file1.rar包

rar a file.rar test_file  将test_file压缩成file1.rar

rar a file.rar file1 file2 dir1  同时压缩file1、file2以及目录dir1成一个file.rar

tar -cvf archive.tar file1  创建一个非压缩的tarball

tar -cvf archive.tar file1 file2 dir1  创建一个包含了file1、file2、dir1的tarball(原始码)

RPM包(Fedora、Redhat及类似系统)  
查看文件内容(cat、vim)

cat file1  从文件的第一个字节开始正向查看文件的内容

more file1  当文件较大时,文本在屏幕上迅速闪过(滚屏),用户往往看不清所显示的内容。因此,一般用more等命令分屏显示

备注:为了控制滚屏,可以按Ctrl+S键,停止滚屏;按Ctrl+Q键可以恢复滚屏。按Ctrl+C(中断)键可以终止该命令的执行,并且返回Shell提示符状态

tac file1  从最后一行开始反向查看文件的内容,它可以对调试日志文件提供很大的帮助,扭转日志内容的时间顺序

head -2 file1  查看一个文件的前两行

tail -2 file1  查看一个文件的后两行

tail -f /var/log/messages  实时查看被添加到一个文件中的内容

文本处理  
原文地址:https://www.cnblogs.com/hoanfir/p/9096526.html