Linux

Linux基础

2017-07-13  本文已影响2人  Bottle丶Fish

常用命令:

**文件和目录:**
# cd /home                        进入 '/home' 目录
# cd ..                                返回上一级目录
# cd ../..                             返回上两级目录
# cd -                                 返回上次所在目录
# cp file1 file2                    将file1复制为file2
# cp -a dir1 dir2                 复制一个目录
# cp -a /tmp/dir1 .              复制一个目录到当前工作目录(.代表当前目录)
# ls                                    查看目录中的文件
# ls -a                                显示隐藏文件
# ls -l                                 显示详细信息
# ls -lrt                               按时间显示文件(l表示详细列表,r表示反向排序,t表示按时间排序)
# pwd                                显示工作路径
# mkdir dir1                       创建 'dir1' 目录
# mkdir dir1 dir2                同时创建两个目录
# mkdir -p /tmp/dir1/dir2    创建一个目录树
# mv dir1 dir2                    移动/重命名一个目录
# rm -f file1                        删除 'file1'
# rm -rf dir1                       删除 'dir1' 目录及其子目录内容
**查看文件内容:**
# cat file1                          从第一个字节开始正向查看文件的内容
# head -2 file1                   查看一个文件的前两行
# more file1                       查看一个长文件的内容
# tac file1                          从最后一行开始反向查看一个文件的内容
# tail -3 file1                      查看一个文件的最后三行
**文本处理:**
# grep str /tmp/test            在文件 '/tmp/test' 中查找 "str"
# grep ^str /tmp/test           在文件 '/tmp/test' 中查找以 "str" 开始的行
# grep [0-9] /tmp/test         查找 '/tmp/test' 文件中所有包含数字的行
# grep str -r /tmp/*             在目录 '/tmp' 及其子目录中查找 "str"
# diff file1 file2                   找出两个文件的不同处
# sdiff file1 file2                 以对比的方式显示两个文件的不同
**查找:**
# find / -name file1                                                 从 '/' 开始进入根文件系统查找文件和目录
# find / -user user1                                                查找属于用户 'user1' 的文件和目录
# find /home/user1 -name \*.bin                            在目录 '/ home/user1' 中查找以 '.bin' 结尾的文件
# find /usr/bin -type f -atime +100                         查找在过去100天内未被使用过的执行文件
# find /usr/bin -type f -mtime -10                           查找在10天内被创建或者修改过的文件
# locate \*.ps                                                         寻找以 '.ps' 结尾的文件,先运行 'updatedb' 命令
# find -name '*.[ch]' | xargs grep -E 'expr'              在当前目录及其子目录所有.c和.h文件中查找 'expr'
# find -type f -print0 | xargs -r0 grep -F 'expr'        在当前目录及其子目录的常规文件中查找 'expr'
# find -maxdepth 1 -type f | xargs grep -F 'expr'    在当前目录中查找 'expr'
**压缩和解压:**
# bzip2 file1                                   压缩 file1
# bunzip2 file1.bz2                        解压 file1.bz2
# gzip file1                                     压缩 file1
# gzip -9 file1                                最大程度压缩 file1
# gunzip file1.gz                            解压 file1.gz
# tar -cvf archive.tar file1               把file1打包成 archive.tar
(-c: 建立压缩档案;-v: 显示所有过程;-f: 使用档案名字,是必须的,是最后一个参数)
# tar -cvf archive.tar file1 dir1        把 file1,dir1 打包成 archive.tar
# tar -tf archive.tar                         显示一个包中的内容
# tar -xvf archive.tar                      释放一个包
# tar -xvf archive.tar -C /tmp         把压缩包释放到 /tmp目录下
# zip file1.zip file1                          创建一个zip格式的压缩包
# zip -r file1.zip file1 dir1               把文件和目录压缩成一个zip格式的压缩包
# unzip file1.zip                             解压一个zip格式的压缩包到当前目录
# unzip test.zip -d /tmp/                 解压一个zip格式的压缩包到 /tmp 目录
**yum工具:**
# yum -y install [package]              下载并安装一个rpm包
# yum localinstall [package.rpm]    安装一个rpm包,使用你自己的软件仓库解决所有依赖关系
# yum -y update                              更新当前系统中安装的所有rpm包
# yum update [package]                 更新一个rpm包
# yum remove [package]                删除一个rpm包
# yum list                                        列出当前系统中安装的所有包
# yum search [package]                 在rpm仓库中搜寻软件包
# yum clean [package]                   清除缓存目录(/var/cache/yum)下的软件包
# yum clean headers                      删除所有头文件
# yum clean all                                删除所有缓存的包和头文件
**网络:**
# ifconfig eth0                                                                       显示一个以太网卡的配置
# ifconfig eth0 192.168.1.1 netmask 255.255.255.0            配置网卡的IP地址
# ifdown eth0                                                                        禁用 'eth0' 网络设备
# ifup eth0                                                                            启用 'eth0' 网络设备
# iwconfig eth1                                                                     显示一个无线网卡的配置
# iwlist scan                                                                         显示无线网络
# ip addr show                                                                     显示网卡的IP地址
**其他:**
# su -                                 切换到root权限(与su有区别)
# shutdown -h now           关机
# shutdown -r now            重启
# top                                  罗列使用CPU资源最多的linux任务 (输入q退出)
# pstree                             以树状图显示程序
# man ping                        查看参考手册(例如ping 命令)
# passwd                          修改密码
# df -h                               显示磁盘的使用情况
# cal -3                             显示前一个月,当前月以及下一个月的月历
# cal 10 1988                   显示指定月,年的月历
# date --date '1970-01-01 UTC 1427888888 seconds'   把一相对于1970-01-01 00:00的秒数转换成时间
**常用快捷键:**
       CentOS 6.4 中可以通过系统->首选项->键盘快捷键来设置快捷键,如图所示。例如可将运行终端的快捷键设为Ctrl+Alt+T。

Ctrl + u            删除光标之前到行首的字符
Ctrl + k            删除光标之前到行尾的字符
Ctrl + c            取消当前行输入的命令,相当于Ctrl + Break
Ctrl + a            光标移动到行首(ahead of line),相当于通常的Home键
Ctrl + e            光标移动到行尾(end of line)
Ctrl + f             光标向前(forward)移动一个字符位置
Ctrl + b            光标往回(backward)移动一个字符位置
Ctrl + l             清屏,相当于执行clear命令
Ctrl + r            显示:号提示,根据用户输入查找相关历史命令(reverse-i-search)
Ctrl + w           删除从光标位置前到当前所处单词(word)的开头
Ctrl + t             交换光标位置前的两个字符
Ctrl + y            粘贴最后一次被删除的单词
Ctrl + Alt + d   显示桌面
Alt + b             光标往回(backward)移动到前一个单词
Alt + d             删除从光标位置到当前所处单词的末尾
Alt + F2           运行
Alt + F4           关闭当前窗口
Alt + F9           最小化当前窗口
Alt + F10         最大化当前窗口
Alt + Tab         切换窗口
Alt +按住左键  移动窗口(或在最下面的任务栏滚动鼠标滑轮)
[鼠标中间键] 粘贴突出显示的文本。使用鼠标左键来选择文本。把光标指向想粘贴文本的地方。点击鼠标中间键来粘贴。
[Tab] 命令行自动补全。使用 shell 提示时可使用这一方式。键入命令或文件名的前几个字符,然后按 [Tab] 键,它会自动补全命令或显示匹配键入字符的所有命令。
在桌面或文件管理器中直接按 / 就可以输入位置,打开文件管理器。
快速搜索:在 vi 或 Firefox 中直接按 / 即可进入搜索状态。
网站链接和图片可直接拖放到桌面或者目录,可以马上下载。
直接将文件管理器中的文件拖到终端中就可以在终端中得到完整的路径名。
在滚动条的空白处点击鼠标中键,屏幕即滚动到那个地方。

Linux Directory Structure

/           Root
|---root        The home directory for the root user
|---home        Contains the user's home directories
|    |----ftp       Users include many services as listed here
|    |----httpd
|    |----samba
|    |----user1
|    |----user2
|---bin      Commands needed during bootup that might be needed by normal users
|---sbin        Like bin but commands are not intended for normal users.  Commands run by LINUX.
|---proc        This filesystem is not on a disk.  Exists in the kernels imagination (virtual).  This directory
|    |          Holds information about kernel parameters and system configuration.
|    |----1     A directory with info about process number 1.  Each process
|               has a directory below proc.  
|---usr         Contains all commands, libraries, man pages, games and static files for normal
|    |          operation.
|    |----bin       Almost all user commands.  some commands are in /bin or /usr/local/bin.
|    |----sbin      System admin commands not needed on the root filesystem.  e.g., most server 
|    |          programs.
|    |----include   Header files for the C programming language.  Should be below /user/lib for
|    |          consistency.
|    |----lib       Unchanging data files for programs and subsystems
|    |----local     The place for locally installed software and other files.
|    |----man       Manual pages
|    |----info      Info documents
|    |----doc       Documentation for various packages
|    |----tmp
|    |----X11R6     The X windows system files.  There is a directory similar to usr below this 
|    |          directory.
|    |----X386      Like X11R6 but for X11 release 5
|---boot        Files used by the bootstrap loader, LILO.  Kernel images are often kept here.
|---lib         Shared libraries needed by the programs on the root filesystem
|    |----modules   Loadable kernel modules, especially those needed to boot the system after
|            disasters.
|---dev         Device files for devices such as disk drives, serial ports, etc.
|---etc         Configuration files specific to the machine.
|    |----skel      When a home directory is created it is initialized with files from this directory
|    |----sysconfig     Files that configure the linux system for networking, keyboard, time, and more.
|---var         Contains files that change for mail, news, printers log files, man pages, temp files
|    |----file
|    |----lib       Files that change while the system is running normally
|    |----local     Variable data for programs installed in /usr/local.
|    |----lock      Lock files.  Used by a program to indicate it is using a particular device or file
|    |----log       Log files from programs such as login and syslog which logs all logins,
|    |          logouts, and other system messages.
|    |----run       Files that contain information about the system that is valid until the system is
|    |          next booted
|    |----spool     Directories for mail, printer spools, news and other spooled work.
|    |----tmp       Temporary files that are large or need to exist for longer than they should in
|    |          /tmp.
|    |----catman    A cache for man pages that are formatted on demand
|---mnt         Mount points for temporary mounts by the system administrator.
|---tmp         Temporary files.  Programs running after bootup should use /var/tmp.

对比

目录 应放置档案内容 
/bin 系统有很多放置执行档的目录,但/bin比较特殊。因为/bin放置的是在单人维护模式下还能够被操作的指令。 在/bin底下的指令可以被root与一般帐号所使用,主要有:cat, chmod, chown, date, mv, mkdir, cp, bash等等常用的指令。 
/boot 这个目录主要在放置开机会使用到的档案,包括Linux核心档案以及开机选单与开机所需设定档等等。 Linux kernel常用的档名为:vmlinuz,如果使用的是grub这个开机管理程式, 则还会存在/boot/grub/这个目录喔! 
/dev 在Linux系统上,任何装置与周边设备都是以档案的型态存在于这个目录当中的。 你只要透过存取这个目录底下的某个档案,就等于存取某个装置啰~ 比要重要的档案有/dev/null, /dev/zero, /dev/tty, /dev/lp*, /dev/hd*, /dev/sd*等等 
/etc 系统主要的设定档几乎都放置在这个目录内,例如人员的帐号密码档、 各种服务的启始档等等。一般来说,这个目录下的各档案属性是可以让一般使用者查阅的, 但是只有root有权力修改。FHS建议不要放置可执行档(binary)在这个目录中喔。比较重要的档案有: /etc/inittab, /etc/init.d/, /etc/modprobe.conf, /etc/X11/, /etc/fstab, /etc/sysconfig/ 等等。另外,其下重要的目录有: 
/etc/init.d/:所有服务的预设启动 script 都是放在这里的,例如要启动或者关闭 iptables 的话:‘ /etc/init.d/iptables start’、‘/etc/init.d/iptables stop’ 
/etc/xinetd.d/:这就是所谓的super daemon管理的各项服务的设定档目录。 
/etc/X11/:与 X Window 有关的各种设定档都在这里,尤其是 xorg.conf 这个 X Server 的设定档。
 
/home 这是系统预设的使用者家目录(home directory)。在你新增一个一般使用者帐号时, 预设的使用者家目录都会规范到这里来。比较重要的是,家目录有两种代号喔:
~:代表目前这个使用者的家目录,而 
~dmtsai :则代表 dmtsai 的家目录! 
/lib 系统的函式库非常的多,而/lib放置的则是在开机时会用到的函式库, 以及在/bin或/sbin底下的指令会呼叫的函式库而已。 什么是函式库呢?你可以将他想成是‘外挂’,某些指令必须要有这些‘外挂’才能够顺利完成程式的执行之意。 尤其重要的是/lib/modules/这个目录, 因为该目录会放置核心相关的模组(驱动程式)喔! 
/media media是‘媒体’的英文,顾名思义,这个/media底下放置的就是可移除的装置啦! 包括软碟、光碟、DVD等等装置都暂时挂载于此。常见的档名有:/media/floppy, /media/cdrom等等。 
/mnt 如果你想要暂时挂载某些额外的装置,一般建议你可以放置到这个目录中。 在古早时候,这个目录的用途与/media相同啦!只是有了/media之后,这个目录就用来暂时挂载用了。 
/opt 这个是给第三方协力软体放置的目录。什么是第三方协力软体啊? 举例来说,KDE这个桌面管理系统是一个独立的计划,不过他可以安装到Linux系统中,因此KDE的软体就建议放置到此目录下了。 另外,如果你想要自行安装额外的软体(非原本的distribution提供的),那么也能够将你的软体安装到这里来。 不过,以前的Linux系统中,我们还是习惯放置在/usr/local目录下呢! 
/root 系统管理员(root)的家目录。之所以放在这里,是因为如果进入单人维护模式而仅挂载根目录时, 该目录就能够拥有root的家目录,所以我们会希望root的家目录与根目录放置在同一个分割槽中。 
/sbin Linux有非常多指令是用来设定系统环境的,这些指令只有root才能够利用来‘设定’系统,其他使用者最多只能用来‘查询’而已。 放在/sbin底下的为开机过程中所需要的,里面包括了开机、修复、还原系统所需要的指令。 至于某些伺服器软体程式,一般则放置到/usr/sbin/当中。至于本机自行安装的软体所产生的系统执行档(system binary), 则放置到/usr/local/sbin/当中了。常见的指令包括:fdisk, fsck, ifconfig, init, mkfs等等。 
/srv srv可以视为‘service’的缩写,是一些网路服务启动之后,这些服务所需要取用的资料目录。 常见的服务例如WWW, FTP等等。举例来说,WWW伺服器需要的网页资料就可以放置在/srv/www/里面。 
/tmp 这是让一般使用者或者是正在执行的程序暂时放置档案的地方。 这个目录是任何人都能够存取的,所以你需要定期的清理一下。当然,重要资料不可放置在此目录啊! 因为FHS甚至建议在开机时,应该要将/tmp下的资料都删除唷! 

部分Linux命令缩写

bin = BINaries
/dev = DEVices
/etc = ETCetera
/lib = LIBrary
/proc = PROCesses
/sbin = Superuser BINaries
/tmp = TeMPorary
/usr = Unix Shared Resources
/var = VARiable ?
FIFO = First In, First Out
GRUB = GRand Unified Bootloader
IFS = Internal Field Seperators
LILO = LInux LOader
MySQL = My是最初作者女儿的名字,SQL = Structured QueryLanguage
PHP = Personal Home Page Tools = PHP HypertextPreprocessor
PS = Prompt String
Perl = "Pratical Extraction and Report Language" ="Pathologically Eclectic Rubbish Lister"
Python 得名于电视剧Monty Python's Flying Circus
Tcl = Tool Command Language
Tk = ToolKit
VT = Video Terminal
YaST = Yet Another Setup Tool
apache = "a patchy" server
apt = Advanced Packaging Tool
ar = archiver
as = assembler
awk = "Aho Weiberger and Kernighan"三个作者的姓的第一个字母
bash = Bourne Again SHell
bc = Basic (Better) Calculator
bg = BackGround
biff = 作者HeidiStettner在U.C.Berkely养的一条狗,喜欢对邮递员汪汪叫。
cal = CALendar
cat = CATenate
cd = Change Directory
chgrp = CHange GRouP
chmod = CHange MODe
chown = CHange OWNer
chsh = CHange SHell
cmp = compare
cobra = Common Object Request BrokerArchitecture
comm = common
cp = CoPy
cpio = CoPy In and Out
cpp = C Pre Processor
cron = Chronos 希腊文时间
cups = Common Unix Printing System
cvs = Current Version System
daemon = Disk And Execution MONitor
dc = Desk Calculator
dd = Disk Dump
df = Disk Free
diff = DIFFerence
dmesg = diagnostic message
du = Disk Usage
ed = editor
egrep = Extended GREP
elf = Extensible Linking Format
elm = ELectronic Mail
emacs = Editor MACroS
eval = EVALuate
ex = EXtended
exec = EXECute
fd = file descriptors
fg = ForeGround
fgrep = Fixed GREP
fmt = format
fsck = File System ChecK
fstab = FileSystem TABle
fvwm = F*** Virtual Window Manager
gawk = GNU AWK
gpg = GNU Privacy Guard
groff = GNU troff
hal = Hardware Abstraction Layer
joe = Joe's Own Editor
ksh = Korn SHell
lame = Lame Ain't an MP3 Encoder
lex = LEXical analyser
lisp = LISt Processing = Lots of IrritatingSuperfluous Parentheses
ln = LiNk
lpr = Line PRint
ls = list
lsof = LiSt Open Files
m4 = Macro processor Version 4
man = MANual pages
mawk = Mike Brennan's AWK
mc = Midnight Commander
mkfs = MaKe FileSystem
mknod = MaKe NODe
motd = Message of The Day
mozilla = MOsaic GodZILLa
mtab = Mount TABle
mv = MoVe
nano = Nano's ANOther editor
nawk = New AWK
nl = Number of Lines
nm = names
nohup = No HangUP
nroff = New ROFF
od = Octal Dump
passwd = PASSWorD
pg = pager
pico = PIne's message COmposition editor
pine = "Program for Internet News &Email" = "Pine is not Elm"
ping = 拟声 又 = Packet InterNet Grouper
pirntcap = PRINTer CAPability
popd = POP Directory
pr = pre
printf = PRINT Formatted
ps = Processes Status
pty = pseudo tty
pushd = PUSH Directory
pwd = Print Working Directory
rc = runcom = run command, rc还是plan9的shell
rev = REVerse
rm = ReMove
rn = Read News
roff = RunOFF
rpm = RPM Package Manager = RedHat PackageManager
rsh, rlogin, rvim中的r = Remote
rxvt = ouR XVT
seamoneky = 我
sed = Stream EDitor
seq = SEQuence
shar = SHell ARchive
slrn = S-Lang rn
ssh = Secure SHell
ssl = Secure Sockets Layer
stty = Set TTY
su = Substitute User
svn = SubVersioN
tar = Tape ARchive
tcsh = TENEX C shell
tee = T (T形水管接口)
telnet = TEminaL over Network
termcap = terminal capability
terminfo = terminal information
tex = τέχνη的缩写,希腊文art
tr = traslate
troff = Typesetter new ROFF
tsort = Topological SORT
tty = TeleTypewriter
twm = Tom's Window Manager
tz = TimeZone
udev = Userspace DEV
ulimit = User's LIMIT
umask = User's MASK
uniq = UNIQue
vi = VIsual = Very Inconvenient
vim = Vi IMproved
wall = write all
wc = Word Count
wine = WINE Is Not an Emulator
xargs = eXtended ARGuments
xdm = X Display Manager
xlfd = X Logical Font Description
xmms = X Multimedia System
xrdb = X Resources DataBase
xwd = X Window Dump
yacc = yet another compiler compiler
Fish = the Friendly Interactive SHell
su = Switch User
MIME = Multipurpose Internet Mail Extensions
ECMA = European Computer ManufacturersAssociation


http://www.comptechdoc.org/os/linux/usersguide/linux_ugfilestruct.html
http://www.cnblogs.com/wqsbk/p/5649037.html

上一篇下一篇

猜你喜欢

热点阅读