考試月終於暫告一段落,終於有時間回歸Linux 的懷抱。不知怎的,在VMware Workstation 12 上登入Ubuntu後總是blue screen,明明昨天用terminal 也沒有事啊真令人摸不著頭腦@@ 算吧,反正有kali linux 用著吧。早晚VMware 會被換掉的。

哈哈,但是荒廢太久的關係,連賬號密碼也給忘了。被迫爬文:http://www.technig.com/reset-lost-password-of-kali-linux/

昨天剛開始,試了一下command:

pwd: print working directory

cd: change directory,cd ~ 就是回家的意思。

ls: list current directory

rm -rf <--哈哈這個當然沒有,也千萬不要試(remove, forced recursive: remove every OS files!!!)

在mkdir上除了一點狀況。實際上要用 mkdir -p /apple/orange/banana, 但是這個指令會overwrite existing directories. 就是,無論舊的、同名的directory裡面有什麼,都會被移除。還有,用rmdir 的話,如果targetted directory 不是空的,那就不能用這個。you must have to delete the sub-directories beneath it first.

哎,雖然學了普通話拼音都有這些年了,但是用拼音輸入還是很慢。還不如用英語輸入。

But noted you cannot delete the particular directory where you are in.

Also, for beginners, it's very easy to forget the '/' preceeding the name of directory. It is particular problematic when we are trying to use rmdir, cd, etc.

Another common error when using 'cd' is forgetting to place '/ <current_directory>' in front of the targetted directory. It causes an error "such directory does not exist"...

===========================

mkdir  vs mkdir -p

mkdir -p /apple: establish 'apple' directory in parent directory. Therefore, changes invisible in root.

mkdir /root/apple: changes visible in root

Similarly, 'rmdir /apple' would only remove that in parent directory, not that in the root.

Common mistake in using mkdir, rmdir, cd

$ mkdir root/pineapple     # missing '/' before 'root'

$ mkdir /root/pineapple/banana  #greedy declaration: pineapple missing directory

$ rmdir /pineapple/banana    # missing '/root': directory DNE

$ rmdir /root/pineapple/banana

$ cd /banana   #missing '/root' in changing directory; directory DNE

$ cd /root/banana

$ rm /root/pineapple    #rm: for removing non-empty directory; rmdir: remove empty dir

 ===========================

pushd vs popd

remark: pushd, pushes current directory into stack and go to the destinated directory.

!! No confusion: pushd does not push the destinated directory into stack!

popd, pop the lastest visited directory

===========================

File I/O

touch new.txt  #establish a new text file

cat >> new.txt << EOF  #open txt file for editing 

START RANDOM WRITING IN FILE

Hello World this is my first linux txt document!!

EOF  #indicate end of file-input; return to parent directory 

cat new.txt  #view the txt file in terminal 

cat << new.txt << EOF  #open txt file and move cursor to the end of file

Overwriting in process...

EOF

cat /root/new.txt

START RANDOM WRITING IN FILE

Hello World this is my first linux txt document!!

Overwriting in process...  #overwrite existing txt failed :(

echo > a.txt  #empty the txt file 

echo >> Hello! >> /root/hello_world.txt  #append at EOF

rm hello_world.txt   #directly remove a file in terminal 

===========================

How to check the type of shell your Unix/Linux is using

ps -p $$  #well, usually it's bash shell

===========================

To-slash, or not to slash

~# ls

> Documents  Music  Pictures

~# cd Documents  #access under current directory, need not '/'

c.f.

~# pwd

/root/Documents

~# cd /root/Pictures  #access directories not at current level, use '/'

** same principle for 'rmdir', e.g. rmdir apple, rmdir hello_world.txt, iff in current directory

===================

cp: copy file or directory

#this command bit-wise copy from one document to another

~# ls

a.txt

~# cp a.txt b.txt

~# ls

> a.txt  b.txt

~# mkdir something

~# ls

> a.txt  b.txt  something

~# cp -r something another

~#ls

> a.txt  b.txt  something  another

===========================

Forcefully remove non-empty directory

sudo rm -r somthing  # '-r' usually for directory-level command

c.f.

cd -r somthing anotherThing  #copy entire directory

===========================

Move a file from one place to another

~# pwd

> /root/temp

~# ls

> a.txt  b.txt  another

~# mv a.txt /root  #move file from one directory to next 

~# mv another /root   #move directory from one to another 

~# pushd /root

~# ls

a.txt  Documents  Music  Pictures  temp

~# cd temp

> b.txt another

===================

題外話:昨晚寫了一個小工具程序給哥哥,他好像很喜歡呢<3 太好了!原來路徑用程序下載時default的路徑就可以了,根本不用在batch當裡面動態產生。哎,真爬文爬死了。看來要認真的學batch的基礎。還有,原來哥哥都會用虛擬機,顆顆真棒!都說我的哥哥是宇宙最強的哈哈哈哈<3 瞎扯瞎遠了,言歸正傳。

每次開虛擬機linux terminal 都耗時很久,等到它開了已經沒有熱情了,還是用一下網上的好了:https://www.tutorialspoint.com/execute_bash_online.php

===================

Opening txt file in bash

less a.txt

q  #quit viewing txt

less vs cat

less a.txt b.txt   #error: less for openning one document only one in a time!

cat a.txt b.txt  #allowed

===================

結語

這篇可算是第一篇結案的文章,算是有頭有尾吧,哈哈。這裡都是非常基本的bash shell command lines。接下來可能的發展方向是學windows' command prompt,或是繼續發掘:https://www.gnu.org/software/bash/manual/bashref.html

但是無論如何,都會跟大家在新的一篇裡面見面咯:)

~~全文完~~

Linux Command Line(I): Beginner的更多相关文章

  1. Linux Command Line(II): Intermediate

    Prerequisite: Linux Command Line(I): Beginner ================================ File I/O $ cat > a ...

  2. 《The Linux Command Line》 读书笔记04 Linux用户以及权限相关命令

    Linux用户以及权限相关命令 查看身份 id:Display user identity. 这个命令的输出会显示uid,gid和用户所属的组. uid即user ID,这是账户创建时被赋予的. gi ...

  3. 《The Linux Command Line》 读书笔记02 关于命令的命令

    <The Linux Command Line> 读书笔记02 关于命令的命令 命令的四种类型 type type—Indicate how a command name is inter ...

  4. 《The Linux Command Line》 读书笔记01 基本命令介绍

    <The Linux Command Line> 读书笔记01 基本命令介绍 1. What is the Shell? The Shell is a program that takes ...

  5. Linux Command Line Basics

    Most of this note comes from the Beginning the Linux Command Line, Second Edition by Sander van Vugt ...

  6. Linux Command Line 解析

    Linux Command Line 解析 0 处理模型 Linux kernel的启动包括很多组件的初始化和相关配置,这些配置参数一般是通过command line进行配置的.在进行后续分析之前,先 ...

  7. 15 Examples To Master Linux Command Line History

    When you are using Linux command line frequently, using the history effectively can be a major produ ...

  8. 10 Interesting Linux Command Line Tricks and Tips Worth Knowing

    I passionately enjoy working with commands as they offer more control over a Linux system than GUIs( ...

  9. Reso | The Linux Command Line 的中文版

    http://book.haoduoshipin.com/tlcl/book/zh/ 本书是 The Linux Command Line 的中文版, 为大家提供了多种不同的阅读方式. 中英文双语版- ...

随机推荐

  1. thinkphp3.2自定义常量

    在项目文件夹 (如:Home) 中的Common文件夹下新建function.php //thinkphp3.2.2版本加入如下语句: define('XXX', XXX); //第一个参数是常量名, ...

  2. Angular4 后台管理系统搭建(2) - flexgrid 单元格模板 wjFlexGridCellTemplate 的坑

    这几天中了很多坑,尤其是两个大坑.先是运行环境的坑,在是flexgrid单元格内部模板的坑.这里记录下. 一开始我遇见一些很奇怪的问题,按网上的说法,别人这么写代码都正常,就在我机器上不正常.按以前的 ...

  3. 如何使用mybatis对mysql数据库进行操作,batis的增删改查

    1.先下载Mybatis和mysql connecrt的jar包 下载地址: 链接: https://pan.baidu.com/s/1kVFfF8N 密码: ypkb 导入jar包,maven的话可 ...

  4. GNU的makefile文件编写说明

    这篇文章讲的相当详细,转来收藏: linux下Makefile学习 MAC

  5. http(一)web和网络基础

    深入学习http不为别的,只为补充底层知识,打好根基,深入了解其他技术,擒贼先擒王,学好九阳神功以后,乾坤大挪移,太极剑就容易了,急于求成,就只能变周芷若.走着...... 来源于:图解HTTP 1. ...

  6. 第一章:windows下 python 的安装和使用

    1. 主流的python版本和大部分人使用的版本都是 2.7 和3.6 2.安装 python2.7 和 python3.6的步骤 1. 下载 python对应的版本:选择使用的 系统, 64位和32 ...

  7. Python3组合数据类型(元组、列表、集合、字典)语法

    一.序列类型(字符串,元组(),列表[]) 序列类型支持in,len(),分片[],迭代,5种内置序列类型:bytearray,bytes,list,str,tuple(元组). 1.元组可以嵌套(如 ...

  8. 浏览器json格式化插件 yformater

    本人最近做的工作就是写interface,几个前端写前端,他们需要什么样的数据格式,我就得返回这样的数据格式.这就导致每一个接口都得检查json格式是否是他们所需要的.但浏览器直接请求的json格式很 ...

  9. 简单地总结几种常见web攻击手段及其防御方式

    web攻击手段有几种,本文简单介绍几种常见的攻击手段及其防御方式 XSS(跨站脚本攻击) CSRF(跨站请求伪造) SQL注入 DDOS XSS 概念 全称是跨站脚本攻击(Cross Site Scr ...

  10. PHP连接数据库、创建数据库、创建表的三种方式

    这篇博客主要介绍了三种方式来连接MySQL数据库以及创建数据库.创建表.(代码是我在原来的基础上改的) MySQLi - 面向对象 MySQLi - 面向过程 PDO MySQLi 面向对象 < ...