`
DavyJones2010
  • 浏览: 154177 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

Linux: Basic Command Introduction V

阅读更多

Part I: Network Related Command

1) Command Name: write

    Command Derived From: write

    Command Path: /usr/bin/write

    Command Auth: all users

    Command Function: Send instant message to another user.

    Command Syntax: write [username]

    Example:

write administrator              --> Write im to administrator, Ctrl+d as the EOF command.

 

2) Command Name: wall

    Command Derived From: write all

    Command Path: /usr/bin/wall

    Command Auth: all users

    Command Function: Send instant message to all users.

    Command Syntax: wall

    Example:

wall              --> Write im to all logined user, Ctrl+d as the EOF command.

 

3) Command Name: ping

    Command Derived From: ping

    Command Path: /usr/bin/ping

    Command Auth: all users

    Command Function: Test network connection.

    Command Syntax: ping [ip-address]

    Example:

ping 192.168.1.1              --> Send icmp request packet to test network connection. Ping will not terminate as long as we didn't terminate this command.ping -c 3 192.168.1.1       --> Sent 3 icmp request packets to test network connection. Ping will terminate after all 3 packets sent. c stands for count.

ping -s 6000 192.168.1.1 --> Sent icmp request packets with the size of 6000Bytes. s stands for size. 

     Comment:

1) Even if we got reply from the target ip address, that doesn't mean that we have a stable connection with the destination.

    We have to pay attention to the ping statistics, such as packet loss rate and errors count.

 

4) Command Name: ifconfig

    Command Derived From: interface config

    Command Path: /usr/bin/ifconfig

    Command Auth: all users

    Command Function: Get info of network interface including wired interface(eth0) and wireless interface(wlan0).

    Command Syntax: ifconfig [eth0 OR wlan0 OR lo]

    Example:

ifconfig eth0              --> Get the information of wired network interface.ifconfig wlan0           --> Get the information of wireless network interface.

ifconfig lo                  --> Local loopback network interface address.

ifconfig etho0 192.168.1.99  --> Modify current ip address to 192.168.1.99.

     Comment:

1) When we modify the ip address of current machine. This new ip address will only apply for current conversation.

    When we restart the machine, the new ip address will not be reserved.

    In linux, if we need to permanently modify the configuration, we have to modify the config file.

    If not, the modification will be only apply for current conversation.

 

Part II: Shell Command Techniques

1) Shell Intro

    Example:

cat /etc/shells    --> This file listed all the installed shells in current system.

    Comment:

1) There are a lot of shells in linux, such as bash, ksh, sh, dash...

2) Different kind of shells have different syntax.

3) If we use bash, we can press <TAB> to auto complete current command.

4) We can use Ctrl+l to clear current screen and use Ctrl+u to clear input in current line before current cursor .

    We can use Shift+Ctrl+r to find previous typed command.

 

2) Command Alias

    Example:

alias                            --> Get all the predefined alias.

alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias grep='grep --color=auto'
alias l='ls -CF'
alias la='ls -A'
alias ll='ls -alF'
alias ls='ls --color=auto'

alias copy=cp           --> Create an alias for cp.

alias drm="rm -rf"     --> Create an alias for command "rm -rf".

unalias copy             --> Delete the alias copy.

unalias drm              --> Delete the alias drm.

     Comment:

1) Caution the difference of defining alias for command without options and command with options.

    We have to use "" to enclose the command with options.

 2) There is no predefined alias in UNIX OS.

 

3) I/O Redirection

    Introduction:

1) Shell predefined 0 for standard input (STDIN). Standard input in linux is keyboard input by default.

    Shell predefined 1 for standard output (STDOUT). Standard output in linux is screen output by default.

    Shell predefined 2 for standard error (STDERR). Standard error in linux is screen output by default.

2) I/O redirection means that we redirected the default I/O source.

    Input source may be redirected to file or network stream.

    Output source may be redirected to file or network stream.

    Example:

ls -ltr /etc > /temp/info.log    --> The listed results will not be displayed in screen. They will be written into /temp/info.log.

                                                   The reason is that our output is redirected to /temp/info.log.

                                                   The info.log is override by current info.

                                                   The '>' means output redirection. That equals "1>"

ls -ltr /etc >> /temp/info.log  --> The listed results will be appended into /temp/info.log instead of override it.

wall < /test/info.log               --> The content of /test/info.log will be send to all users. Here we redirect the input source from keyboard to file.

cp -R /usr /backup/usr.bak 2> /backup/error.log   --> If there is any error occurs, write the error message into /backup/error.log.

ls -ltr /nothing 2> /error.log  --> The /nothing dir doesn't exists. If we don't redirect the error output, the error message will be shown in screen.

                                                   Here we redirect the error message into /error.log file.

    Comment:

1) Imagine that we are administrator of a dozens of servers.

    We have to check the server's states such as cpu and memory usage every day.

    Instead of login servers one by one and type the command. We can redirect the output into a specific log file.

    And schedule a job send an email to us with these files as attachment.

2) /usr dir just like system32/ dir. It's very important and contains all the core system program.

4) Pipe

    Introduction:

Pipe: Send the output of previous command as input for post command.

    Example:

ls -ltr /etc | more    --> The output of command ls -ltr /etc would be so long that overflow the screen.

                              --> We use the output of previous command as the input of "more" so that we can view all

                                    the output by typing space to next page and enter to next line.

ls -ltr /etc | grep init --> The output of command ls -ltr /etc would be so long that make it difficult to find the entry contains 'init'

                               --> We use the output as input for grep init and we can easily find the interested entry.

ls -ltr /etc | grep init | wc -l

                               --> Count the number of entry that contains keyword 'init'.

    Comment:

1) Pipe combines simple commands and makes a difference.

 

5) Command Connector

    Introduction:

";"          --> The commands connected by ; means execute by the command order.

"&&"      --> The commands connected by && means the command after && will only excute after the successful execution of the command before &&.

"||"         --> The commands connected by || means the command after || will only excute after the failed execution of the command before ||

 

    Example:

pwd ; ls -ltr; date    --> First, we print out the current directory.

                               --> Second, we list out the file details in current directory.

                               --> Third, we print out the date of command execution.

write Mary < /home/davy/love.txt && rm /home/davy/love.txt

                               --> Send im to Mary.

                               --> If send successful, remove the input source.

write Mary < /home/davy/love.txt || mail Mary < /home/davy/love.txt

                               --> Send im to Mary.

                               --> If send failed, send mail to Mary.

ls /nothing || pwd

                               --> List files in /nothing directory

                               --> If list failed, print current working directory.

ls /nothing || touch /home/davy/error.log; ls /nothing 2> /home/davy/error.log

                               --> List files in /nothing directory.

                               --> If list failed, create a new log file. And re-execute list command, log error message into error.log file.

    Comment:

1) A traditional usage of ; is that if we want to compile the linux kernel, we have to type several command by order.

    The time consumption of each command would be very huge. Instead of type first command and wait and type second command and wait...

    We can simply use ; to connect all the command and output the error log.

 
 
分享到:
评论

相关推荐

    Linux for Beginners: An Introduction to the Linux Operating System

    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 ...

    Linux for Developers

    ### Linux for ... this book provides a comprehensive introduction to Linux programming, covering a wide range of topics from command line basics to advanced scripting and programming techniques.

    The_Linux_Networking_Architecture

    Basic Structure of Traffic Control in Linux 367 Section 18.3. Traffic Control in the Outgoing Direction 367 Section 18.4. Kernel Structures and Interfaces 369 Section 18.5. Ingress Policing 378...

    The.Linux.Networking.Architecture

    Basic Structure of Traffic Control in Linux 367 Section 18.3. Traffic Control in the Outgoing Direction 367 Section 18.4. Kernel Structures and Interfaces 369 Section 18.5. Ingress Policing ...

    Wiley.Publishing.Fedora.Linux.Toolbox.1000+.Commands.for.Fedora.CentOS.and.Red.Hat.Power.Users.and.Red.Hat.Power.Users.2008.pdf

    - **Understanding the Command Line**: Basic concepts and terminologies used in the shell environment. - **Navigating Directories**: Moving around the file system using commands like `cd`, `ls`, and `...

    Linux Shell Scripting Cookbook

    Introduction 7 Printing in the terminal 9 Playing with variables and environment variables 12 Doing math calculations with the shell 17 Playing with file descriptors and redirection 19 Arrays and ...

    Linux System Administrator Guide Version0.9

    #### Introduction The Linux System Administrator’s Guide Version 0.9 is a comprehensive resource aimed at helping new and experienced system administrators understand the nuances of managing Linux ...

    Ubuntu Pocket Guide and Reference: A concise companion for day-to-day Ubuntu use

    - **Scripting Basics**: Introduction to basic scripting concepts and examples of simple scripts are included. **Software Management** - **Package Management**: The book covers package management ...

    unix power tools 3ed.pdf

    **1.1 引言 (Chapter 1: Introduction)** - **目标**: 介绍Unix的基本概念和发展历史。 - **内容**: 解释Unix的基本特性和优势,包括其对开发者友好性、稳定性和可移植性。 **1.2 获取帮助 (Chapter 2: Getting ...

    Linux高级bash编程

    A Detailed Introduction to I/O and I/O Redirection F. Standard Command-Line Options G. Important Files H. Important System Directories I. Localization J. History Commands K. A Sample .bashrc File L. ...

    geronimo-book.pdf

    #### Introduction Apache Geronimo is a robust and flexible open-source Java EE (previously known as J2EE) application server. The "geronimo-book.pdf" provides detailed guidance on installing, ...

    apache hbase reference guide

    - **Introduction**(介绍):Apache HBase 是一个分布式的、可扩展的大数据存储系统,基于Google的Bigtable论文实现。它提供了高可靠性、高性能、面向列的数据存储能力。适合于存储海量半结构化/非结构化数据。 - ...

    impala-2.8

    #### Introduction to Apache Impala (Incubating) Apache Impala is a high-performance, distributed SQL query engine that enables fast, interactive SQL queries on data stored in Apache Hadoop's HDFS, ...

    python3.6.5参考手册 chm

    PEP 389: The argparse Module for Parsing Command Lines PEP 391: Dictionary-Based Configuration For Logging PEP 3106: Dictionary Views PEP 3137: The memoryview Object Other Language Changes ...

    Python4DelphiPart-1-7139726.pdf

    - **Usage in Console Applications**: Python for Delphi can be used in console applications, making it suitable for command-line tools and scripts. - **Lazarus/FPC Support**: There is also support for ...

    Complete Guide to Open Source Big Data Stack-Apress(2018).pdf

    It would be useful to have some basic knowledge of Centos Linux and Scala. But don’t be deterred if you don’t; I believe that if you are interested in these topics and willing to learn, you will ...

Global site tag (gtag.js) - Google Analytics