This article provides practical examples for 50 most frequently used commands in Linux / UNIX.
无论如何,这不是一个全面的列表,但这应该可以让您快速入门一些常见的Linux3d捕鱼达人。将本文添加为书签,以供将来参考。
我是否错过任何常用的Linux3d捕鱼达人? 发表评论 让我知道
1. tar3d捕鱼达人示例
创建一个新的tar存档。
$ tar cvf archive_name.tar dirname/
从现有的tar存档中提取。
$ tar xvf archive_name.tar
查看现有的tar存档。
$ tar tvf archive_name.tar
更多tar示例: 最终的Tar3d捕鱼达人教程,包含10个实际示例
2. grep3d捕鱼达人示例
在文件中搜索给定的字符串(不区分大小写的搜索)。
$ grep -i "the" demo_file
打印匹配的行以及其后的三行。
$ grep -A 3 -i "example" demo_text
在所有文件中递归搜索给定的字符串
$ grep -r "ramesh" *
更多grep示例: 掌握Grep! – 15个实用的Grep3d捕鱼达人示例
3.查找3d捕鱼达人示例
使用文件名查找文件(区分大小写)
# find -iname "MyCProgram.c"
对由find3d捕鱼达人找到的文件执行3d捕鱼达人
$ find -iname "MyCProgram.c" -exec md5sum {} \;
在主目录中查找所有空文件
# find ~ -empty
查找更多示例: 妈妈,我找到了! — 15个实用的Linux Find3d捕鱼达人示例
4. ssh3d捕鱼达人示例
登录到远程主机
ssh -l jsmith remotehost.example.com
调试SSH客户端
ssh -v -l jsmith remotehost.example.com
显示SSH客户端版本
$ ssh -V OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003
更多ssh示例: 5个基本的Linux SSH客户端3d捕鱼达人
5. sed3d捕鱼达人示例
当您将DOS文件复制到Unix时,您可以在每行末尾找到\ r \ n。本示例使用sed3d捕鱼达人将DOS文件格式转换为Unix文件格式。
$sed 's/.$//' filename
以相反的顺序打印文件内容
$ sed -n '1!G;h;$p' thegeekstuff.txt
为文件中所有非空行添加行号
$ sed '/./=' thegeekstuff.txt | sed 'N; s/\n/ /'
sed的更多示例: 高级Sed替换示例
6. awk3d捕鱼达人示例
使用awk删除重复的行
$ awk '!($0 in array) { array[$0]; print }' temp
从/ etc / passwd打印具有相同uid和gid的所有行
$awk -F ':' '$3==$4' passwd.txt
仅打印文件中的特定字段。
$ awk '{print $2,$5;}' employee.txt
更多awk示例: 8个强大的Awk内置变量– FS,OFS,RS,ORS,NR,NF,FILENAME,FNR
7. vim3d捕鱼达人示例
转到文件的第143行
$ vim +143 filename.txt
转到指定的第一个匹配项
$ vim +/search-term filename.txt
以只读模式打开文件。
$ vim -R /etc/passwd
更多vim示例: 如何在Vim编辑器中录制和播放
8. diff3d捕鱼达人示例
比较时忽略空白。
# diff -w name_list.txt name_list_new.txt 2c2,3 < 约翰 Doe --- > 约翰 M Doe > Jason Bourne
更多差异示例: UNIX / Linux上的前4个文件差异工具-Diff,Colordiff,Wdiff,Vimdiff
9.排序3d捕鱼达人示例
升序排列文件
$ sort names.txt
以降序排列文件
$ sort -r names.txt
按第三字段对passwd文件进行排序。
$ sort -t: -k 3n /etc/passwd | more
10.导出3d捕鱼达人示例
查看与oracle相关的环境变量。
$ export | grep ORACLE declare -x ORACLE_BASE="/u01/app/oracle" declare -x ORACLE_HOME="/u01/app/oracle/product/10.2.0" declare -x ORACLE_SID="med" declare -x ORACLE_TERM="xterm"
要导出环境变量:
$ export ORACLE_HOME=/u01/app/oracle/product/10.2.0
11. xargs3d捕鱼达人示例
将所有图像复制到外部硬盘驱动器
# ls *.jpg | xargs -n1 -i cp {} /external-hard-drive/directory
搜索系统中的所有jpg图像并将其存档。
# find / -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz
下载url-list.txt文件中提到的所有URL
# cat url-list.txt | xargs wget –c
12. ls3d捕鱼达人示例
显示文件大小以人类可读的格式(例如KB,MB等)
$ ls -lh -rw-r----- 1 ramesh team-dev 8.9M Jun 12 15:27 arch-linux.txt.gz
使用ls -ltr根据上次修改时间(反向)订购文件
$ ls -ltr
使用ls -F对具有特殊字符的文件进行视觉分类
$ ls -F
更多ls示例: Unix LS3d捕鱼达人:15个实用示例
13. pwd3d捕鱼达人
pwd是打印工作目录。对于已经打印了多年的当前目录名称的老Pwd,还有什么可以说的。
14. cd3d捕鱼达人示例
使用“ cd-”在最后两个目录之间切换
使用“ shopt -s cdspell”自动更正光盘上输入错误的目录名称
更多cd示例: 6个很棒的Linux cd3d捕鱼达人技巧
15. gzip3d捕鱼达人示例
要创建* .gz压缩文件:
$ gzip test.txt
要解压缩* .gz文件:
$ gzip -d test.txt.gz
使用gzip -l显示压缩文件的压缩率
$ gzip -l *.gz compressed uncompressed ratio uncompressed_name 23709 97975 75.8% asp-patch-rpms.txt
16. bzip23d捕鱼达人示例
要创建一个* .bz2压缩文件:
$ bzip2 test.txt
要解压缩* .bz2文件:
bzip2 -d test.txt.bz2
更多bzip2示例: BZ是Eazy! bzip2,bzgrep,bzcmp,bzdiff,bzcat,bzless,bzmore示例
17.解压缩3d捕鱼达人示例
提取* .zip压缩文件:
$ unzip test.zip
查看* .zip文件的内容(不解压缩):
$ unzip -l jasper.zip Archive: jasper.zip Length Date Time 名称 -------- ---- ---- ---- 40995 11-30-98 23:50 META-INF/MANIFEST.MF 32169 08-25-98 21:07 classes_ 15964 08-25-98 21:07 classes_names 10542 08-25-98 21:07 classes_ncomp
18. shutdown3d捕鱼达人示例
关闭系统并立即关闭电源。
# shutdown -h now
10分钟后关闭系统。
# shutdown -h +10
使用shutdown3d捕鱼达人重新引导系统。
# shutdown -r now
在重新引导期间强制检查文件系统。
# shutdown -Fr now
19. ftp3d捕鱼达人示例
Both ftp and secure ftp (sftp) has similar commands. To connect to a remote server and 做wnload multiple files, 做 the following.
$ ftp IP/hostname ftp> mget *.html
To view the file names located 上 the remote server before 做wnloading, mls ftp command as shown below.
ftp> mls *.html - /ftptest/features.html /ftptest/index.html /ftptest/othertools.html /ftptest/samplereport.html /ftptest/usage.html
更多ftp示例: FTP和SFTP入门指南,包含10个示例
20. crontab3d捕鱼达人示例
查看特定用户的crontab条目
# crontab -u john -l
每10分钟安排一次cron作业。
*/10 * * * * /home/ramesh/check-disk-space
更多crontab示例: Linux Crontab:15个很棒的Cron作业示例
21.服务3d捕鱼达人示例
Service3d捕鱼达人用于运行系统V init脚本。即,可以使用service3d捕鱼达人来代替位于/etc/init.d/目录中的脚本及其完整路径。
检查服务状态:
# service ssh status
检查所有服务的状态。
service --status-all
重新启动服务。
# service ssh restart
22. ps3d捕鱼达人示例
ps command is used to display information about the processes that are running in the system.
While there are lot of arguments that could be passed to a ps command, following are some of the common 上es.
查看当前正在运行的进程。
$ ps -ef | more
To view current running processes in a tree structure. H option stands for process hierarchy.
$ ps -efH | more
23.自由3d捕鱼达人示例
This command is used to display the free, used, swap memory available in the system.
典型的免费3d捕鱼达人输出。输出以字节显示。
$ free total used free shared buffers cached Mem: 3566408 1580220 1986188 0 203988 902960 -/+ buffers/cache: 473272 3093136 Swap: 4000176 0 4000176
如果要快速检查系统有多少GB RAM,请使用-g选项。 -b选项以字节显示,-k以千字节显示,-m以兆字节显示。
$ free -g total used free shared buffers cached Mem: 3 1 1 0 0 0 -/+ buffers/cache: 0 2 Swap: 3 0 3
If you want to see a total memory ( including the swap), use the -t switch, which will display a total line as shown below.
[email protected]:~$ free -t total used free shared buffers cached Mem: 3566408 1592148 1974260 0 204260 912556 -/+ buffers/cache: 475332 3091076 Swap: 4000176 0 4000176 Total: 7566584 1592148 5974436
24. top3d捕鱼达人示例
top3d捕鱼达人显示系统中的顶级进程(默认情况下按cpu的使用情况排序)。要按任何列对顶部输出进行排序,请按O(大写字母O),这将显示您可以按其排序的所有可能的列,如下所示。
Current Sort Field: P for window 1:Def Select sort field via field letter, type any other key to return a: PID = Process Id v: nDRT = Dirty Pages count d: UID = User Id y: WCHAN = Sleeping in Function e: USER = User 名称 z: Flags = Task Flags ........
要仅显示属于特定用户的进程,请使用-u选项。以下仅显示属于oracle用户的顶级进程。
$ top -u oracle
更多热门示例: 你能顶一下吗? 15个实用的Linux最高3d捕鱼达人示例
25. df3d捕鱼达人示例
Displays the file system disk space usage. By default df -k displays output in 通过tes.
$ df -k Filesystem 1K-blocks Used Available Use% Mounted 上 /dev/sda1 29530400 3233104 24797232 12% / /dev/sda2 120367992 50171596 64082060 44% /home
df -h以易于阅读的形式显示输出。即大小将以GB显示’s.
[email protected]:~$ df -h Filesystem Size Used Avail Use% Mounted 上 /dev/sda1 29G 3.1G 24G 12% / /dev/sda2 115G 48G 62G 44% /home
使用-T选项显示什么类型的文件系统。
[email protected]:~$ df -T Filesystem Type 1K-blocks Used Available Use% Mounted 上 /dev/sda1 ext4 29530400 3233120 24797216 12% / /dev/sda2 ext4 120367992 50171596 64082060 44% /home
26. kill3d捕鱼达人示例
使用kill3d捕鱼达人终止进程。首先使用ps -ef3d捕鱼达人获取进程ID,然后使用kill -9杀死正在运行的Linux进程,如下所示。您还可以使用killall,pkill,xkill终止unix进程。
$ ps -ef | grep vim ramesh 7243 7222 9 22:43 pts/2 00:00:00 vim $ kill -9 7243
更多杀死示例: 杀死进程的4种方法–杀死,杀死所有人,杀死,杀死xkill
27. rm3d捕鱼达人示例
在删除文件之前获得确认。
$ rm -i filename.txt
在文件名参数中赋予外壳元字符时,这非常有用。
打印文件名并在删除文件之前获得确认。
$ rm -i file*
以下示例以递归方式删除示例目录下的所有文件和目录。这也会删除示例目录本身。
$ rm -r example
28. cp3d捕鱼达人示例
将文件1复制到文件2,以保留模式,所有权和时间戳。
$ cp -p file1 file2
Copy file1 to file2. if file2 exists prompt for confirmation before overwritting it.
$ cp -i file1 file2
29. mv3d捕鱼达人示例
Rename file1 to file2. if file2 exists prompt for confirmation before overwritting it.
$ mv -i file1 file2
注意:mv -f恰好相反,它将在不提示的情况下覆盖file2。
mv -v will print what is happening during file rename, which is useful while specifying shell metacharacters in the file name argument.
$ mv -v file1 file2
30. cat3d捕鱼达人示例
You can view multiple files at the same time. Following example prints the content of file1 followed 通过 file2 to stdout.
$ cat file1 file2
While displaying the file, following cat -n command will prepend the line number to each line of the output.
$ cat -n /etc/logrotate.conf 1 /var/log/btmp { 2 missingok 3 monthly 4 create 0660 root utmp 5 rotate 1 6 }
31. mount3d捕鱼达人示例
To mount a file system, you should first create a directory and mount it as shown below.
# mkdir /u01 # mount /dev/sdb1 /u01
You can also add this to the fstab for automatic mounting. i.e Anytime system is restarted, the filesystem will be mounted.
/dev/sdb1 /u01 ext2 defaults 0 2
32. chmod3d捕鱼达人示例
chmod3d捕鱼达人用于更改文件或目录的权限。
Give full access to user and group (i.e read, write and execute ) 上 a specific file.
$ chmod ug+rwx file.txt
Revoke all access for the group (i.e read, write and execute ) 上 a specific file.
$ chmod g-rwx file.txt
Apply the file permissions recursively to all the files in the sub-directories.
$ chmod -R ug+rwx file.txt
更多chmod示例: 适用于初学者的7个Chmod3d捕鱼达人示例
33. chown3d捕鱼达人示例
chown3d捕鱼达人用于更改文件的所有者和组。 \
To change owner to oracle and group to db 上 a file. i.e Change both owner and group at the same time.
$ chown oracle:dba dbora.sh
使用-R递归更改所有权。
$ chown -R oracle:dba /home/oracle
34. passwd3d捕鱼达人示例
Change your password from command line using passwd. This will prompt for the old password followed 通过 the new password.
$ passwd
Super user can use passwd command to reset others password. This will not prompt for current password of the user.
# passwd USERNAME
删除特定用户的密码。根用户可以禁用特定用户的密码。禁用密码后,用户无需输入密码即可登录。
# passwd -d USERNAME
35. mkdir3d捕鱼达人示例
以下示例在主目录下创建一个名为temp的目录。
$ mkdir ~/temp
使用一个mkdir3d捕鱼达人创建嵌套目录。如果这些目录已经存在,则不会显示任何错误。如果这些目录中的任何一个没有’如果存在,它将创建它们。
$ mkdir -p dir1/dir2/dir3/dir4/
36. ifconfig3d捕鱼达人示例
Use ifconfig command to view or configure a network interface 上 the Linux system.
查看所有接口以及状态。
$ ifconfig -a
使用up和down3d捕鱼达人启动或停止特定接口,如下所示。
$ ifconfig eth0 up $ ifconfig eth0 做wn
更多的ifconfig示例: Ifconfig:7个配置网络接口的示例
37. uname3d捕鱼达人示例
Uname command displays important information about the system such as—Kernel name, Host name, Kernel release number,
处理器类型等
下面显示了来自Ubuntu笔记本电脑的uname输出示例。
$ uname -a Linux john-laptop 2.6.32-24-generic #41-Ubuntu SMP Thu Aug 19 01:12:52 UTC 2010 i686 GNU/Linux
38. whereis3d捕鱼达人示例
当您要查找特定Unix3d捕鱼达人的位置(例如ls3d捕鱼达人的位置?)时,可以执行以下3d捕鱼达人。
$ whereis ls ls: /bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
当您要从whereis默认路径以外的路径搜索可执行文件时,可以使用-B选项并将path作为其参数。这将在/ tmp目录中搜索可执行文件lsmk,并显示它(如果可用)。
$ whereis -u -B /tmp -f lsmk lsmk: /tmp/lsmk
39. whatis3d捕鱼达人示例
Whatis3d捕鱼达人显示有关3d捕鱼达人的单行描述。
$ whatis ls ls (1) - list directory contents $ whatis ifconfig ifconfig (8) - configure a network interface
40.查找3d捕鱼达人示例
使用locate3d捕鱼达人,您可以快速搜索特定文件(或文件组)的位置。查找3d捕鱼达人使用由updatedb创建的数据库。
The example below shows all files in the system that contains the word crontab in it.
$ locate crontab /etc/anacrontab /etc/crontab /usr/bin/crontab /usr/share/doc/cron/examples/crontab2english.pl.gz /usr/share/man/man1/crontab.1.gz /usr/share/man/man5/anacrontab.5.gz /usr/share/man/man5/crontab.5.gz /usr/share/vim/vim72/syntax/crontab.vim
41. 人 command examples
Display the 人 page of a specific command.
$ 人 crontab
当3d捕鱼达人的手册页位于多个部分下时,您可以从特定部分查看该3d捕鱼达人的手册页,如下所示。
$ 人 SECTION-NUMBER commandname
Following 8 sections are available in the 人 page.
- 一般3d捕鱼达人
- 系统调用
- C库函数
- 特殊文件(通常是设备,在/ dev中找到的设备)和驱动程序
- 文件格式和约定
- 游戏和屏保
- 杂
- 系统管理3d捕鱼达人和守护程序
例如,当您执行whats crontab时,’将会注意到crontab有两个手册页(第1节和第5节)。要查看crontab手册页的第5节,请执行以下操作。
$ whatis crontab crontab (1) - maintain crontab files for individual users (V3) crontab (5) - tables for driving cron $ 人 5 crontab
42. tail3d捕鱼达人示例
默认情况下,打印文件的最后10行。
$ tail filename.txt
从名为filename.txt的文件中打印N行
$ tail -n N filename.txt
使用tail -f实时查看文件的内容。这对于查看不断增长的日志文件很有用。可以使用CTRL-C终止该3d捕鱼达人。
$ tail -f log-file
更多的尾巴示例: 在一个终端中查看多个日志文件的tail -f输出的3种方法
43. less3d捕鱼达人示例
less is very efficient while viewing huge log files, as it 做esn’t need to load the full file while opening.
$ less huge-log-file.log
您可以使用较少的3d捕鱼达人打开文件,以下两个键非常有用。
CTRL+F – forward 上e window CTRL+B – backward 上e window
更少的示例: Unix Less3d捕鱼达人:有效导航的10个技巧
44. su3d捕鱼达人示例
Switch to a different user account using su command. Super user can switch to any other user without entering their password.
$ su - USERNAME
从其他帐户名执行一个3d捕鱼达人。在以下示例中,john可以以raj用户名执行ls3d捕鱼达人。一旦执行了3d捕鱼达人,它将回到约翰’s account.
[[email protected]]$ su - raj -c 'ls' [[email protected]]$
Login to a specified user account, and execute the specified shell instead of the default shell.
$ su -s 'SHELLNAME' USERNAME
45. mysql3d捕鱼达人示例
mysql可能是Linux上使用最广泛的开源数据库。即使你不’为了在服务器上运行mysql数据库,您可能最终使用mysql3d捕鱼达人(client)连接到在远程服务器上运行的mysql数据库。
连接到远程mysql数据库。这将提示您输入密码。
$ mysql -u root -p -h 192.168.1.2
连接到本地mysql数据库。
$ mysql -u root -p
If you want to specify the mysql root password in the command line itself, enter it immediately after -p (without any space).
46. yum3d捕鱼达人示例
使用yum安装apache。
$ yum install httpd
使用yum升级apache。
$ yum update httpd
使用yum卸载/删除apache。
$ yum remove httpd
47. rpm3d捕鱼达人示例
要使用rpm安装apache。
# rpm -ivh httpd-2.2.3-22.0.1.el5.i386.rpm
要使用rpm升级apache。
# rpm -uvh httpd-2.2.3-22.0.1.el5.i386.rpm
使用rpm卸载/删除apache。
# rpm -ev httpd
更多rpm示例: RPM3d捕鱼达人:15个示例,用于安装,卸载,升级,查询RPM软件包
48. ping3d捕鱼达人示例
通过仅发送5个数据包来Ping远程主机。
$ ping -c 5 gmail.com
更多ping示例: Ping教程:15个有效的Ping3d捕鱼达人示例
49.日期3d捕鱼达人示例
设置系统日期:
# date -s "01/31/2010 23:59:53"
Once you’ve changed the system date, you should syncronize the hardware clock with the system date as shown below.
# 时钟–systohc # 时钟--systohc –utc
50. wget3d捕鱼达人示例
The quick and effective method to 做wnload software, music, video from internet is using wget command.
$ wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.1.tar.gz
用其他名称下载并存储它。
$ wget -O taglist.zip http://www.vim.org/scripts/download_script.php?src_id=7701
更多wget示例: Ultimate Wget下载指南,其中包含15个很棒的示例
我是否错过任何常用的Linux3d捕鱼达人?发表评论,让我知道。
如果您喜欢这篇文章,您可能还会喜欢..
![]() |
![]() |
![]() |
![]() |
非常感谢。