Linux for Complete Beginners

查找

find . 可以查看当前目录所有嵌套的文件
find .|grep .txt 使用管道符
find . -type f 只想看到文件
find . -type d 只想看到目录
find . -type f -exec ls -l '{}' ';' 其中'{}'代表找到的文件
还可以使用ack,来自beyondgrep.com,具体使用见happycasts.net/episodes/26

脚本编程

指定解析器

如脚本第一行#!/usr/bin/env bash即指定bash为解析器,当然还可以将bash换成python、ruby等

语句即命令,命令即语句

terminal:
$echo "hello"
hello
script:
#!/usr/bin/env python
echo "hello"
脚本语句对空格非常敏感

位置参数

$即是位置参数
$peter.sh a.txt b.txt,则引用第一个参数用$0,第二个用$1,第三个用$2,以此类推

脚本中的语句不在当前shell执行

$ ls
bin Desktop happygrep mydir peter.sh
$ ls mydir/
$ vim peter.sh#!/usr/bin/env bashcd /home/peter/mydir
touch a.txt
$ ./peter.sh
$ ls mydir/
a.txt
当前工作目录没有改变,如果将第八行改成source peter.sh,当前目录就会变成脚本所在目录

循环控制

$ ls mydir/
a b c
$ vim rename.sh

!/usr/bin/env bash

cd $1 # 对应执行脚本时传入的第一个参数
for file in a b c
do
mv $file $file.txt
done
$ chmod +x rename.sh
$ ./rename.sh mydir/
$ ls mydir/
a.txt b.txt c.txt

远程执行

在本地执行一个脚本,此脚本中的命令作用在服务器上
如在本地写一个脚本mkfile.ssh:
ssh -t peter@happycasts.net 'touch a.txt'
执行脚本:
./mkfile.ssh
对服务器来说就相当于执行了此命令touch a.txt

进程

查看当前所有进程

ps aux|grep【要查找的内容】
ctrl+shift+c 复制内容
ctrl+shift+v 粘贴内容
例:vim启动vim,ps aux|grep vim查看进程号,如为4646,则要结束这个进程用kill 4646

后台执行

【程序名】 & 程序便在后台执行
使用ctrl+z结束程序

结束进程

kill【选项】
选项如9 强制杀死进程
Linux同时有7个工作台在运行,当正在使用的出现卡死情况时,ctrl+out+f1切换工作台,在这里可以杀死那个导致卡死的进程,然后ctrl+out+f7回到原先工作台

软件安装

安装方式Ⅰ

使用解压缩命令来解压,然后将程序放到echo $PATH的任意路径下,或者使用软链接,如ln -s ~/.sublime3/sublime_text ~/bin/subl,其中的subl是快捷命令名

安装方式Ⅱ

解压缩后进入软件目录下,然后做一下三步:

  1. ./configure

  2. make

  3. sudo make install

deb包安装【只适用于ubuntu系统】

程序本身 配置文件 安装位置 依赖关系
happycasts.net/episodes/14会讲解如何将源码打包成deb包
在deb所在的目录下sudo dpkg -i 【包名】.deb
dpkg -l 列出系统上所有的deb包

从apt-get仓库安装

sudo apt-get install git 安装git
sudo apt-get remove git 删除git
sudo apt-get purge git 删除git,连配置文件都一起删除
安装的时候也有tab补齐功能,敲两下tab键,它也能自动处理依赖问题

网络操作

只要ssh跑得通,那么就能用rsync
rsync -r mydir happycasts.net:【服务器上的路径】代表将本地的目录mydir上传到服务上
反过来,rsync -r happycasts.net:【服务器上的路径】mydir.代表将服务器上的目录下载到本地,最后的.代表当前目录
rsync -r mydir/ happycasts.net:mydir/可以同步客户端和服务器的对应目录,注意两个/都不能省,而且一般使用-a参数替代-r-av可以打印出一些有用信息
-a只能同步在客户端新创建的文件,而有时候本地还会删除一些文件,需要服务器也做相应删除除了,则应rsync -av --delete mydir/ happycasts.net:mydir/,但这样也是有风险的,一般在上面命令后再加一个--dry-run,会开启验证

用户和文件权限

三种权限

读:r;写:w;执行:x

三类人

所有者:owner;用户组:group;其他人:world
实际考虑的就是每类人是否拥有rwx三种权限

chmod--change file mode

ls -l a.txt
# -rw-rw-r-- 1 peter peter 0 Aug 30 11:57 a.txt

# a.txt对world没有写和执行权限

chmod rw-rw-rw- a.txt # wrong!

chmod 110110110 a.txt # wrong!

chmod 666 a.txt # right! 6对110就是二进制转八进制

实际上还可以通过chown命令来改变权限所对应的用户,具体看billie66的书《Linux命令行》第十章--权限


inux for Beginners doesn't make any assumptions about your background or knowledge of Linux. You need no prior knowledge to benefit from this book. You will be guided step by step using a logical and systematic approach. As new concepts, commands, or jargon are encountered they are explained in plain language, making it easy for anyone to understand. Here is what you will learn by reading Linux for Beginners: How to get access to a Linux server if you don't already. What a Linux distribution is and which one to choose. What software is needed to connect to Linux from Mac and Windows computers. Screenshots included. What SSH is and how to use it, including creating and using SSH keys. The file system layout of Linux systems and where to find programs, configurations, and documentation. The basic Linux commands you'll use most often. Creating, renaming, moving, and deleting directories. Listing, reading, creating, editing, copying, and deleting files. Exactly how permissions work and how to decipher the most cryptic Linux permissions with ease. How to use the nano, vi, and emacs editors. Two methods to search for files and directories. How to compare the contents of files. What pipes are, why they are useful, and how to use them. How to compress files to save space and make transferring data easy. How and why to redirect input and output from applications. How to customize your shell prompt. How to be efficient at the command line by using aliases, tab completion, and your shell history. How to schedule and automate jobs using cron. How to switch users and run processes as others. Where to go for even more in-depth coverage on each topic. What you learn in "Linux for Beginners" applies to any Linux environment including Ubuntu, Debian, Linux Mint, RedHat, Fedora, OpenSUSE, Slackware, and more.
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值