Louis Better than before

Linux/Unix command Handbook

[UPDATED: 2022/02/23]

Purpose

During the period from graduating to being an Engineer, Linux/Unix commands becomes part of my working daily routine. Here, recording several useful and powerful commands to keep in mind.

Linux/Unix command

Table of Contents

  1. SED command
  2. WC command
  3. LN command
  4. SEQ command

SED command

"sed" is used for finding, parsing, text substitution, replacement and text manipulations such as insertion, deletion search etc. And, we also can use sed with regular expression.


$ Usage: sed [OPTION]... {script-only-if-no-other-script} [input-file]... 
$
$  -i[SUFFIX], --in-place[=SUFFIX]
$                 edit files in place (makes backup if extension supplied).
$                 The default operation mode is to break symbolic and hard links.
$                 This can be changed with --follow-symlinks and --copy.
$
$  -e script, --expression=script
$                 add the script to the commands to be executed
$
$  ...

Example:

  1. Parsing the strings
  2. $ sed -e 's/^..............\(..\)/\1/' nput-file]
    
    This command is used for parsing the last two strings, line by line.
  3. Replacement
  4. $ sed -i 's/abc/123/' [input-file]
    
    This command is used for replacing "abc" with "123".
  5. Add a line in a specific position
  6. $ sed '3iline 3' [input-file]
    
    This command is used for inserting the "line 3" text at line 3 in input-file file.

WC command

"wc" is used for print newline, word, and byte counts for each file.

$ Usage: wc [OPTION]... [FILE]...
$
$   -l, --lines            print the newline counts
$   -w, --words            print the word counts
$  ...

Example:

  1. Present the number of lines
  2. $ wc -le  [FILE]
    
    This command supports more than one files.

LN command

"ln" is an utility for creating links between files. By default, the ln command creates hard links. To create a symbolic links use the -s (–symbolic) option.

$ Usage: ln [OPTION]... [-T] TARGET LINK_NAME   (1st form)
$  or:  ln [OPTION]... TARGET                  (2nd form)
$  or:  ln [OPTION]... TARGET... DIRECTORY     (3rd form)
$  or:  ln [OPTION]... -t DIRECTORY TARGET...  (4th form)
  
$  ...
$  -s, --symbolic              make symbolic links instead of hard links
$  -S, --suffix=SUFFIX         override the usual backup suffix
$  -t, --target-directory=DIRECTORY  specify the DIRECTORY in which to create
                                the links
$  ...

Example:

  1. Creating Symlinks
  2. $ ln -s source_file symbolic_link
    
    This command creates symbolic link in Linux, replascing source_file with the name of the existing file for which you want to create the symbolic link and symbolic_link with the name of the symbolic link.

SEQ command

“seq” is an utility prints a sequence of numbers, one per line (default), from first (default 1), to near last as possible, in increments of incr (default 1).

$ Usage: :seq [-w] [-f format] [-s string] [-t string] [first [incr]] last
$ -f format     Use a printf(3) style format to print each number.
$ -s string     Use string to separate numbers.
$ ...

Example:

  1. Creating a sequence of numbers, one per line in a file
$ seq 100 104 > my_file.txt

=========== To be continued…. ==========

Reference

[1] SED command in Linux

[2] General help using GNU software

[3] How to Create Symbolic Links in Linux Using the ln Command

Note

If you have any constructive criticism or advises, leave the comments below or feel free to email me @qazqazqaz850@gmail.com. Hope this post will help! :)