【linux練習】基礎作業一

來源:互聯網
上載者:User

標籤:linux練習

1. 建立一個目錄/data。 [[email protected][1] oldboystudy]# mkdir data[[email protected][1] oldboystudy]# lltotal 4drwxr-xr-x. 2 root root 4096 Apr 11 09:49 data2. 在/data下面建立一個檔案oldboy.txt。 [[email protected][1] oldboystudy]# cd data/[[email protected][1] data]# touch oldboy.txt[[email protected][1] data]# lltotal 0-rw-r--r--. 1 root root 0 Apr 11 09:53 oldboy.txt[[email protected][1] data]#3. 為oldboy.txt增加內容為“I am studying linux.”。 [[email protected][1] data]# vim oldboy.txt [[email protected][1] data]# cat oldboy.txt i am studying linux.[[email protected][1] data]#4. 把oldboy.txt檔案拷貝到/tmp下。 [[email protected][1] data]# cp oldboy.txt /tmp [[email protected][1] data]# ll /tmp/total 8-rw-r--r--. 1 root root   21 Apr 11 09:55 oldboy.txtdrwx------. 2 root root 4096 Jan 13 16:31 pulse-GmmRjFD7HG5z[[email protected][1] data]#5. 把/data目錄移動到/root下。[[email protected][1] oldboystudy]# lltotal 4drwxr-xr-x. 2 root root 4096 Apr 11 10:01 data[[email protected][1] oldboystudy]# mv  data/  /root[[email protected][1] oldboystudy]# lltotal 0[[email protected][1] oldboystudy]# cd[[email protected][1] ~]# lltotal 108-rw-r--r--. 1 root root   143 Mar 16 14:39 !-rw-------. 1 root root  1554 Dec 22 12:21 anaconda-ks.cfgdrwxr-xr-x. 2 root root  4096 Apr 11 10:01 data[[email protected][1] ~]# ll data/total 4-rw-r--r--. 1 root root 21 Apr 11 09:55 oldboy.txt[[email protected][1] ~]#  6. 進入/root目錄下的data目錄,刪除oldboy.txt檔案。 [[email protected][1] ~]# ll data/total 4-rw-r--r--. 1 root root 21 Apr 11 09:55 oldboy.txt[[email protected][1] ~]# [[email protected][1] ~]# [[email protected][1] ~]# [[email protected][1] ~]# cd data/[[email protected][1] data]# rm -f oldboy.txt    #-f表示強制移除檔案[[email protected][1] data]# lltotal 0[[email protected][1] data]#7. 接第6題,退出到上一級目錄,刪除data目錄。 [[email protected][1] data]# cd[[email protected][1] ~]# rm -f data/rm: cannot remove `data/‘: Is a directory   #必須加上-r參數進行遞迴刪除[[email protected][1] ~]# rm -rf data/     #遞迴強制移除目錄[[email protected][1] ~]#8. 已知檔案test.txt內容為:testliyaooldboy 9. 請給出輸出test.txt檔案內容時,不包含oldboy字串的命令。 [[email protected][1] oldboystudy]# cat test.txt testliyaooldboy[[email protected][1] oldboystudy]# tail -n 2 test.txt liyaooldboy[[email protected][1] oldboystudy]#10. 請用一條命令完成建立目錄/oldboy/test,即建立/oldboy目錄及/oldboy/test目錄 [[email protected][1] oldboystudy]# mkdir -p  /oldboy/test[[email protected][1] oldboystudy]# cd /oldboy/test/[[email protected][1] test]#Mkdir常用的參數介紹:  -m, --mode=MODE   set file mode (as in chmod), not a=rwx - umask  -p, --parents     no error if existing, make parent directories as needed#-p參數表示當父目錄不存在是直接建立父目錄,如該題中/oldboy目錄不存在的情況下建立test這個目錄時,需要使用-p參數自動建立test目錄的父目錄。  -v, --verbose     print a message for each created directory  -Z, --context=CTX  set the SELinux security context of each created                      directory to CTX      --help     display this help and exit      --version  output version information and exit11. 已知/tmp下已經存在test.txt檔案,如何執行命令才能把/mnt/test.txt拷貝到/tmp下覆蓋掉/tmp/test.txt,而讓系統不提示是否覆蓋(root許可權下)。 [[email protected][1] ~]# cp -f -r  /mnt/test.txt /tmp/test.txt cp: overwrite `/tmp/test.txt‘? [[email protected][1] ~]##理論上來說,-r表示遞迴,-f表示強制。增加了-r和-f參數不會再提示是否覆蓋的情況,但實際情況仍然會提示是否覆蓋,什麼原因呢?是別名在作怪,請看下面:[[email protected][1] ~]# aliasalias cp=‘cp -i‘alias l.=‘ls -d .* --color=auto‘alias ll=‘ls -l --color=auto‘alias ls=‘ls --color=auto‘alias mv=‘mv -i‘alias rm=‘rm -i‘這就意味著,執行cp命令實際上執行的是cp –i命令。那麼我們想要通過cp命令在不提示覆蓋的前提下實現覆蓋,就需要修改alias。[[email protected][1] ~]# cat ~/.bashrc# .bashrc# User specific aliases and functionsalias rm=‘rm -i‘#alias cp=‘cp -i‘   #將cp相關的alias注釋掉alias mv=‘mv -i‘# Source global definitionsif [ -f /etc/bashrc ]; then. /etc/bashrcfi[[email protected][1] ~]##注釋掉後重新登入即可。附上cp命令相關參數:-R, -r, --recursive          copy directories recursively      --reflink[=WHEN]         control clone/CoW copies. See below.      --remove-destination     remove each existing destination file before                                 attempting to open it (contrast with --force)      --sparse=WHEN            control creation of sparse files. See below.      --strip-trailing-slashes  remove any trailing slashes from each SOURCE                                 Argument-f, --force                  if an existing destination file cannot be                                 opened, remove it and try again (redundant if                                 the -n option is used)12. 只查看/etc/passwd檔案(共100行)內第20到第30行的內容 head -n 30 /etc/passwd | tail -n +20


本文出自 “mangguo” 部落格,請務必保留此出處http://mangguostudy.blog.51cto.com/5643869/1632185

【linux練習】基礎作業一

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.