【转载】Linux Examination

原博地址:https://blog.csdn.net/weixin_42568655/article/details/94603660

(来自我的同学QiaoGuangtong大佬)

Fundamental About Linux

    Partition.
    Generally, the partitions in linux, take the ubuntu for instance, four partitions are general, which including “/”, “/boot”, “/swap”, and “/home”, in which home is your users’ directory.

File Command

  In linux, the file processing commands are pretty important because all your actions are about file processing. So next term, let us to learn about the commands for processing the files.
At first, you should know that the command is case sensitive, for which you should know which are upper case, and which are lowercase.

 ls -list directory contents

    List the files and directory from current directory order by the first case default.

  Options     Long Option     Describe
  -a   -all   List all files
  -l   -long   Display results in long format
  -t   -time   Display result order by time

 

    cp -copy   

 This command can copy files or directories. It can be used two different ways.
    cp item1 item2
    to copy the file or directory from item1 to item2, and
    cp item… directory
    to copy multiple items (files or directories) into a directory.
    Example:
    cp -r item1 item2
    Recursively copy directories and their contents. This option is required when item1 is a directory.

    mv -move
    This command can move file or directory to a new directory and rename a file
    Example:
    mv item1… item2
    Like cp, move files or recursively move directories and their contents. item1 and item2 can be directory or file.

    rm -remove
    This command can remove the directed file or directory
    Example:
    rm -r item
    The same, recursively remove directories and their contents. This option is required when item is a directory.
    rm -f item
    This command will cancel warning when you remove a file or directory and its contents.
    rm -rf item
    This command combined two above.

    tar
    This command can zip or unzip the directed files or directories.
    Example:
    tar -czvf item1 item2….
    -czvf create zip visual file (new file name)
    This command can zip item2, which can be file or directory. item2 can be multiple items.
    tar -xvzf item
    This command can unzip item, a zip file.

    chmod -change mode
    This command can change permissions of a file or directory.
    Example:
    chmod u+x item    add execute on item for current user
    chmod u+r item    add read on item for current user
    chmod u+x item add write on item for current user
    chmod g+x item    g is group add execute for all users in the same group with current user.
    chmod a+x item    a is all add execute for all users

    touch
    This command can change the time for visiting and changing. If the file does not exists, create a new file.
    option:
    touch [filename]
    This command can create a new file filename.

    find
    This command is the most complex in my class that cannot remind me all the time.
    find ./ -size -name passwd -ok cp {} /home ;

 

Directory Command

    mkdir
    This command can create a new directory
    Example:
    mkdir item
    This command creates a directory item in current directory.
    cd
    This command can change directory
    Example:
    cd item
    This command changes into item, which is a directory.

User Command

    su
    This command can change current user to another.
    Example:
    su sam
    This command change user to sam.
    passwd
    This command can update password for a user.
    Example:
    passwd sam
    This command can update password for sam.

Other Command

    cat
    This command can display the content of a file. E.g. cat a.txt
    echo
    This command can display the content of a string or environment variables and so on. E.g. echo java
    ps -ef
    This command can display the processes of current system.
    kill -9 [pid]
    This command can kill a process which number is pid.

Vi/Vim

vi is a screen-oriented text editor originally created for the Unix operating system.
vi is a modal editor: it operates in either insert mode (where typed text becomes part of the document) or command mode (where keystrokes are interpreted as commands that control the edit session). When you enter “:” , you will enter last-line mode.

change mode:
i from command mode to insert command
Command mode:
dd    delete current line
yy    copy current line to buffer
nyy copy n lines to buffer

Last-line mode:
:q quit with no action
:wq save write and quit
:q! force to quit
:x save and quit

. Shell Scripting

  1. Tips     For a new shell scripting, you can make it according the following steps.
  2. Write your shell scripting file using vi/vim or other editors
  3. Change its permissions so that it can be executed
  4. Execute it 
  5. Practice

copy files

  copy /etc/passwd, /etc/profile, /etc/shadow to current directory.

1 cp /etc/passwd ./
2 cp /etc/profile ./
3 cp /etc/shadow ./

 

Specific size

  Decide if a number is greater than 50.

1 x=50
2 if [ $x -gt 50 ] ; then
3     echo ">0"
4 else
5     echo "<=0"
6 fi
7 
8 ./e1

 

Add 1-100

  Display the sum from 1 to 100

1 i=0;
2 sum=0;
3 while [ $i -lt 100 ] ; do
4     let i+=1
5     let sum+=$i
6 done
7 echo "sum is $sum"

 

Create Files

  Please create 100 files f1 to f100

1 i=0;
2 while [ $i -lt 100 ] ; do
3     i+=1
4     touch f$i
5 done 

Re-Write cp

  Re-Write my copy using two arguments, and decide if the first argument is a directory

1 if [ -f $1 ] ; then
2     cp $1 $2
3 else
4     cp -r $1 $2
5 fi

 

Ten Score cp

 (快考试了排不完了 先不排了)

(有空再弄)

(烂尾预警)

 

posted @ 2019-07-04 21:23  Jiahui_Zhan  阅读(202)  评论(0编辑  收藏  举报