Linux基本指令学习(一)

来源:互联网 发布:mac 查看文件的路径 编辑:程序博客网 时间:2024/05/21 14:40

- 1.文件指令的基本操作

pwd –查看当前位置

$ pwd/home/lzl/lzl

cd –进入某个文件夹

进入familyA文件中    ~/lzl$ cd familyA/~/lzl/familyA$ cd ..

ls –显示该路径下的所有信息

~/lzl$ lsfamilyA  Son.txt  study01.txt  tmp_study~/lzl$ ls -ltotal 36drwxrwxr-x 4 lzl lzl  4096 Sep 28 01:15 familyA-rw-rw-r-- 1 lzl lzl  1625 Sep 28 03:01 Son.txt-rw-rw-r-- 1 lzl lzl 22035 Sep 29 23:24 study01.txtdrwxrwxr-x 2 lzl lzl  4096 Sep 28 01:08 tmp_study

mkdir –创建文件夹

~/lzl$ mkdir linuxStudy~/lzl$ ls -ltotal 40drwxrwxr-x 4 lzl lzl  4096 Sep 28 01:15 familyAdrwxrwxr-x 2 lzl lzl  4096 Oct 11 23:42 linuxStudy-rw-rw-r-- 1 lzl lzl  1625 Sep 28 03:01 Son.txt-rw-rw-r-- 1 lzl lzl 22035 Sep 29 23:24 study01.txtdrwxrwxr-x 2 lzl lzl  4096 Sep 28 01:08 tmp_study

touch –创建一个新文件

lzl@ubuntu:~/lzl$ cd linuxStudy/lzl@ubuntu:~/lzl/linuxStudy$ touch study01.txtlzl@ubuntu:~/lzl/linuxStudy$ ls -ltotal 0-rw-rw-r-- 1 lzl lzl 0 Oct 11 23:44 study01.txt

touch –创建一个带内容的文件

lzl@ubuntu:~/lzl/linuxStudy$ cat study01.txt lzl@ubuntu:~/lzl/linuxStudy$ echo "hello Linux!" > study01.txt lzl@ubuntu:~/lzl/linuxStudy$ cat study01.txt hello Linux!

cp –拷贝文件

cp +文件名 +路径

lzl@ubuntu:~/lzl/linuxStudy$ cp study01.txt /home/lzl/lzl/familyA/lzl@ubuntu:~/lzl/linuxStudy$ cd ../familyA/lzl@ubuntu:~/lzl/familyA$ ls -ltotal 12-rw-rw-r-- 1 lzl lzl0 Sep 28 01:15 daughter.txt-rw-rw-r-- 1 lzl lzl0 Sep 28 01:14 erzidrwxrwxr-x 2 lzl lzl 4096 Sep 28 01:15 fangzi-rw-rw-r-- 1 lzl lzl0 Sep 28 01:14 father.txtdrwxrwxr-x 9 lzl lzl 4096 Sep 28 01:45 house-rw-rw-r-- 1 lzl lzl0 Sep 28 01:14 mothre.txt-rw-rw-r-- 1 lzl lzl0 Sep 28 01:15 nver-rw-rw-r-- 1 lzl lzl0 Sep 28 01:14 son.txt-rw-rw-r-- 1 lzl lzl   13 Oct 11 23:49 study01.txt

rm –删除文件

rm +文件名(必须是文件名)

lzl@ubuntu:~/lzl/familyA$ rm fangzirm: cannot remove 'fangzi': Is a directorylzl@ubuntu:~/lzl/familyA$ rm erzilzl@ubuntu:~/lzl/familyA$ ls -l

more –显示文件内容

more less +文件名 (分页显示内容)
more +文件名

lzl@ubuntu:~/lzl/linuxStudy$ more less study01.txt 以下是内容more: stat of less failed: No such file or directory::::::::::::::study01.txt::::::::::::::hello Linux!lzl@ubuntu:~/lzl/linuxStudy$ cd ..lzl@ubuntu:~/lzl$ more less study01.txt more: stat of less failed: No such file or directorylzl@ubuntu:~/lzl$ more study01.txt以下是内容 Script started on Wed 28 Sep 2016 01:13:03 AM PDTlzl@ubuntu:~/lzl$ cd familyA/lzl@ubuntu:~/lzl/familyA$ ls -ltotal 0lzl@ubuntu:~/lzl/familyA$ touch father.txtlzl@ubuntu:~/lzl/familyA$ touch mothre.txt

wc –显示文档的行数、字数、字符数

lzl@ubuntu:~/lzl$ wc study01.txt 380  2408 22035 study01.txt

find –查找指定的文件

lzl@ubuntu:~/lzl$ find -name study01.txt ./study01.txt./familyA/study01.txt./linuxStudy/study01.txt./tmp_study/study01.txt

grep –查找指定字符串

lzl@ubuntu:~/lzl/linuxStudy$ grep hello study01.txt hello Linux!

tree –显示目录树

lzl@ubuntu:~/lzl/linuxStudy$ tree.└── study01.txt0 directories, 1 file

rmdir –删除空文件夹

rmdir +文件夹(文件夹中是空的文件)

lzl@ubuntu:~/lzl$ rmdir tmp_study/rmdir: failed to remove 'tmp_study/': Directory not emptylzl@ubuntu:~/lzl$ mkdir hellolzl@ubuntu:~/lzl$ rmdir hello

ln –连接

ln +路径名 +虚拟路径

lzl@ubuntu:~/lzl/familyA/house$ sudo passwd[sudo] password for lzl: Enter new UNIX password: Retype new UNIX password: passwd: password updated successfullylzl@ubuntu:~/lzl/familyA/house$ su rootPassword: root@ubuntu:/home/lzl/lzl/familyA/house# ln -s /home/lzl/lzl/familyA/house/roomA /home/roomAroot@ubuntu:/home/lzl/lzl/familyA/house# 

- 2.系统管理命令

stat –显示指定文件的相关信息

lzl@ubuntu:/home$ stat lzl  File: 'lzl'  Size: 4096        Blocks: 8          IO Block: 4096   directoryDevice: 801h/2049d  Inode: 1325139     Links: 22Access: (0755/drwxr-xr-x)  Uid: ( 1000/     lzl)   Gid: ( 1000/     lzl)Access: 2016-10-11 23:13:08.798006194 -0700Modify: 2016-10-12 00:42:40.961904505 -0700Change: 2016-10-12 00:42:40.961904505 -0700 Birth: -

who、w –显示在线登录用户

lzl@ubuntu:/home$ w 02:53:52 up  3:50,  1 user,  load average: 0.04, 0.03, 0.00USER     TTY      FROM             LOGIN@   IDLE   JCPU   PCPU WHATlzl      tty7     :0               23:10    3:50m 55.34s  0.42s /sbin/upstart -lzl@ubuntu:/home$ wholzl      tty7         2016-10-11 23:10 (:0)

whoami –显示用户自己的身份

lzl@ubuntu:/home$ whoamilzl

hostname –显示主机名称
hostname -i –显示主机IP

lzl@ubuntu:/home$ hostnameubuntulzl@ubuntu:/home$ hostname -i127.0.1.1

uname –显示系统信息
uname -a 显示全部信息(内核名称,主机名,等)

lzl@ubuntu:/home$ uname -aLinux ubuntu 4.4.0-38-generic #57-Ubuntu SMP Tue Sep 6 15:42:33 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux

top –显示当前系统中耗费资源最多的进程,动态显示过程,实时监控

lzl@ubuntu:~$ toptop - 23:20:10 up 6 min,  1 user,  load average: 1.32, 1.38, 0.77Tasks: 249 total,   1 running, 247 sleeping,   0 stopped,   1 zombie%Cpu(s): 15.2 us,  5.7 sy,  0.4 ni, 72.8 id,  5.7 wa,  0.0 hi,  0.4 si,  0.0 stKiB Mem :   998388 total,    75560 free,   588888 used,   333940 buff/cacheKiB Swap:  1045500 total,   931964 free,   113536 used.   197480 avail Mem    PID USER      PR  NI    VIRT    RES    SHR S %CPU %MEM     TIME+ COMMAND                                                                      4014 root      20   0  358972  35536  15384 S 10.2  3.6   0:05.58 Xorg                                                                         4888 lzl       20   0 1169848  44240  19736 S  5.0  4.4   0:07.94 compiz                                                                     

ps 显示瞬间进程状态

ps -aux 显示所有瞬间进程状态
lzl@ubuntu:~$ ps

PID TTY          TIME    CMD5378 pts/1    00:00:00   bash5892 pts/1    00:00:00   ps

du 显示指定的文件(目录)已使用的磁盘空间的总量,可以使用–help查看帮助

lzl@ubuntu:~/lzl/familyA$ du 4   ./house/chufang32  ./house4   ./fangzi44  .lzl@ubuntu:~/lzl/familyA$ du fangzi4   fangzi

df –显示文件系统磁盘空间的使用情况

df -h

lzl@ubuntu:~/lzl/familyA$ df -hFilesystem  Size  Used Avail Use% Mounted onudev469M 0  469M   0% /devtmpfs98M  6.2M   92M   7% /run/dev/sda149G  9.0G   37G  20% /tmpfs   488M  212K  488M   1% /dev/shmtmpfs   5.0M  4.0K  5.0M   1% /run/locktmpfs   488M 0  488M   0% /sys/fs/cgrouptmpfs98M   64K   98M   1% /run/user/1000

free –显示当前内存和交换空间的使用情况

lzl@ubuntu:~/lzl/familyA$ free  totalusedfree  shared  buff/cache   availableMem: 998388  533612   964048884  368372  261220Swap:   1045500  172640  872860

ifconfig –显示网络接口信息

lzl@ubuntu:~/lzl/familyA$ ifconfigens33     Link encap:Ethernet  HWaddr 00:0c:29:02:e8:ab    inet addr:192.168.119.129  Bcast:192.168.119.255  Mask:255.255.255.0  inet6 addr: fe80::6c67:b87b:336d:fc67/64 Scope:Link  UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1  RX packets:39015 errors:0 dropped:0 overruns:0 frame:0  TX packets:17193 errors:0 dropped:0 overruns:0 carrier:0  collisions:0 txqueuelen:1000   RX bytes:51782377 (51.7 MB)  TX bytes:1049241 (1.0 MB)

ping –测试网络的连通性

ping +IP

lzl@ubuntu:~/lzl/familyA$ ping 10.18.250.120PING 10.18.250.120 (10.18.250.120) 56(84) bytes of data.64 bytes from 10.18.250.120: icmp_seq=1 ttl=128 time=1.42 ms64 bytes from 10.18.250.120: icmp_seq=2 ttl=128 time=1.80 ms64 bytes from 10.18.250.120: icmp_seq=3 ttl=128 time=1.42 ms

netstat 显示网络状态信息

unix  3      [ ]         STREAM     CONNECTED     27293    unix  3      [ ]         STREAM     CONNECTED     26034    unix  3      [ ]         STREAM     CONNECTED     25756    /run/systemd/journal/

- 3.备份压缩命令

gzip –命令

  • 压缩文件
  • 把lzl目录下的famailyA目录所有文件压缩成.gz文件
  • tar -cvf +压缩后的路径名 +要压缩的文件路径
tar -cvf /home/lzl/lzl/familyA/.tar /home/lzl/lzl/familyA/  首先进行打包,因为gzip不能直接对目录进行压缩lzl@ubuntu:~/lzl$ gzip familyA.tar 进行压缩lzl@ubuntu:~/lzl$ gzip -l familyA.tar.gz  查看压缩包详情compressed        uncompressed  ratio uncompressed_name644               30720  98.0% familyA.tar
  • 解压缩命令
  • 将myname.tar.g解压缩
  • tar -zxvf 压缩文件名.tar.gz
lzl@ubuntu:~/lzl/linuxStudy$ tar -zxvf myname.tar.gz home/lzl/lzl/linuxStudy/home/lzl/lzl/linuxStudy/study01.txtlzl@ubuntu:~/lzl/linuxStudy$ 

bzip2 –命令

  • 压缩命令
  • 将linuxStudy文件夹进行压缩
  • bzip2 -z linuxStudy.tar 需要加上-z参数
tar -cvf /home/lzl/lzl/study.tar /home/lzl/lzl/linuxStudy/lzl@ubuntu:~/lzl$ bzip2 -z study.tar -rw-rw-r-- 1 lzl lzl   601 Oct 14 01:07 study.tar.bz2
  • 解压缩study.tar.bz2
  • tar -jxvf study.tar.bz2
lzl@ubuntu:~/lzl$ tar -jxvf study.tar.bz2 home/lzl/lzl/linuxStudy/home/lzl/lzl/linuxStudy/study01.txthome/lzl/lzl/linuxStudy/home/home/lzl/lzl/linuxStudy/home/lzl/home/lzl/lzl/linuxStudy/home/lzl/lzl/home/lzl/lzl/linuxStudy/home/lzl/lzl/linuxStudy/home/lzl/lzl/linuxStudy/home/lzl/lzl/linuxStudy/study01.txthome/lzl/lzl/linuxStudy/myname.tar.gz

tar –命令

仅打包,不压缩

tar -cvf /home/lzl/lzl/familyA.tar /home/lzl/lzl/familyA

打包后,以gzip压缩

tar -zcvf /home/lzl/lzl/familyA.tar.gz /home/lzl/lzl/itcast/familyA

打包后,以bzip2压缩

tar -jcvf /home/lzl/lzl/familyA.tar.bz2 /home/lzl/lzl/familyA# 特别注意,在参数f之后的文件档名是自己取的,我们习惯上都用.tar来作为辨识# 如果加z参数,则以.tar.gz或.tgz来代表gzip压缩过的tar file# 如果加j参数,则以.tar.bz2来作为文档名

- 4.Ubuntu软件包管理

sudo dpkg -l –查看Ubuntu系统已安装所有软件包列表

lzl@ubuntu:~/lzl$ sudo dpkg -l[sudo] password for lzl: Desired=Unknown/Install/Remove/Purge/Hold| Status=Not/Inst/Conf-files/Unpacked/halF-conf/Half-inst/trig-aWait/Trig-pend|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)||/ Name   Version  Architecture Description+++-==============-============-============-=================================ii  a11y-profile-m 0.1.10-0ubun amd64Accessibility Profile Manager - Uii  account-plugin 0.12+16.04.2 all  GNOME Control Center account plugii  account-plugin 0.12+16.04.2 all  GNOME Control Center account plugii  account-plugin 0.12+16.04.2 all  GNOME Control Center account plug

sudo lsb_release -a –查看系统版本信息

lzl@ubuntu:~/lzl$ sudo lsb_release -aNo LSB modules are available.Distributor ID: UbuntuDescription:    Ubuntu 16.04.1 LTSRelease:    16.04Codename:   xenial

安装软件

sudo apt-get install softname1 softname2 softname3……

卸载软件命令:

 sudo apt-get remove softname1 softname2 softname3……

卸载并清除配置命令:

sudo apt-get remove --purge softname1

更新软件信息数据库命令:

sudo apt-get update

进行系统升级命令:

sudo apt-get upgrade

搜索软件包命令:

sudo apt-cache search softname1 softname2 softname3……
0 0
原创粉丝点击