Common commands in Linux

Strongly Recommend Articles: Welcome to Collection
Android Dry Goods Sharing

Read for five minutes, ten o'clock a day, and study with you for life. Here's Android, a programmer.

This article mainly introduces some knowledge points in Android development. By reading this article, you will gain the following contents:

I. cd command
2. help Order
3. ls command
IV. touch command
5. mkdir command
6. pwd command
VII. echo Order
8. cat command
9. Tab Bond
10. vi or vim commands
XI. rm Order
12. mv command
13. Command of cp
14. find command
15. Naming grep
16. chmod command
17. Compression and decompression commands

I. cd command

The cd command is one of the common commands in Linux, which is mainly used to enter directories (equivalent to windows folders).
For example, I want to enter the TestLinuxCommond directory.
You can use CD Test Linux Commond/

wangjie@ubuntu:~$ cd TestLinuxCommond/
wangjie@ubuntu:~/TestLinuxCommond$ 

For example, I want to exit the TestLinuxCommond directory.
You can use cd..

wangjie@ubuntu:~/TestLinuxCommond$ cd ..
wangjie@ubuntu:~$ 

If you want to return a two-tier directory, you can use cd. /..

wangjie@ubuntu:~/TestLinuxCommond/testmv/test$ ls
wangjie@ubuntu:~/TestLinuxCommond/testmv/test$ cd ../..
wangjie@ubuntu:~/TestLinuxCommond$ 

2. help Order

When we don't know how to use a command, we can use -- help to see what this command is for.
- Help is equivalent to a manual for users to command help.
For example, I want to see how the cd command is used. You can use cd - - help

wangjie@ubuntu:~/TestLinuxCommond$ cd ---help
-bash: cd: --: invalid option
cd: usage: cd [-L|[-P [-e]] [-@]] [dir]
wangjie@ubuntu:~/TestLinuxCommond$ 

For example, I want to see how ls commands are used and how parameters are used, using ls - - help

wangjie@ubuntu:~/TestLinuxCommond$ ls --help
Usage: ls [OPTION]... [FILE]...
List information about the FILEs (the current directory by default).
Sort entries alphabetically if none of -cftuvSUX nor --sort is specified.

Mandatory arguments to long options are mandatory for short options too.
  -a, --all                  do not ignore entries starting with .
  -A, --almost-all           do not list implied . and ..
      --author               with -l, print the author of each file
  -b, --escape               print C-style escapes for nongraphic characters
      --block-size=SIZE      scale sizes by SIZE before printing them.  E.g.,
                               '--block-size=M' prints sizes in units of
                               1,048,576 bytes.  See SIZE format below.
  -B, --ignore-backups       do not list implied entries ending with ~
  -c                         with -lt: sort by, and show, ctime (time of last
                               modification of file status information)
                               with -l: show ctime and sort by name
                               otherwise: sort by ctime, newest first
  -C                         list entries by columns
      --color[=WHEN]         colorize the output.  WHEN defaults to 'always'
                               or can be 'never' or 'auto'.  More info below
  -d, --directory            list directory entries instead of contents,
                               and do not dereference symbolic links
  -D, --dired                generate output designed for Emacs' dired mode
  -f                         do not sort, enable -aU, disable -ls --color
  -F, --classify             append indicator (one of */=>@|) to entries
      --file-type            likewise, except do not append '*'
      --format=WORD          across -x, commas -m, horizontal -x, long -l,
                               single-column -1, verbose -l, vertical -C
      --full-time            like -l --time-style=full-iso
  -g                         like -l, but do not list owner
      --group-directories-first
                             group directories before files.
                               augment with a --sort option, but any
                               use of --sort=none (-U) disables grouping
  -G, --no-group             in a long listing, don't print group names
  -h, --human-readable       with -l, print sizes in human readable format
                               (e.g., 1K 234M 2G)
      --si                   likewise, but use powers of 1000 not 1024
  -H, --dereference-command-line
                             follow symbolic links listed on the command line
      --dereference-command-line-symlink-to-dir
                             follow each command line symbolic link
                             that points to a directory
      --hide=PATTERN         do not list implied entries matching shell PATTERN
                               (overridden by -a or -A)
      --indicator-style=WORD  append indicator with style WORD to entry names:
                               none (default), slash (-p),
                               file-type (--file-type), classify (-F)
  -i, --inode                print the index number of each file
  -I, --ignore=PATTERN       do not list implied entries matching shell PATTERN
  -k, --kibibytes            use 1024-byte blocks
  -l                         use a long listing format
  -L, --dereference          when showing file information for a symbolic
                               link, show information for the file the link
                               references rather than for the link itself
  -m                         fill width with a comma separated list of entries
  -n, --numeric-uid-gid      like -l, but list numeric user and group IDs
  -N, --literal              print raw entry names (don't treat e.g. control
                               characters specially)
  -o                         like -l, but do not list group information
  -p, --indicator-style=slash
                             append / indicator to directories
  -q, --hide-control-chars   print ? instead of non graphic characters
      --show-control-chars   show non graphic characters as-is (default
                             unless program is 'ls' and output is a terminal)
  -Q, --quote-name           enclose entry names in double quotes
      --quoting-style=WORD   use quoting style WORD for entry names:
                               literal, locale, shell, shell-always, c, escape
  -r, --reverse              reverse order while sorting
  -R, --recursive            list subdirectories recursively
  -s, --size                 print the allocated size of each file, in blocks
  -S                         sort by file size
      --sort=WORD            sort by WORD instead of name: none -U,
                             extension -X, size -S, time -t, version -v
      --time=WORD            with -l, show time as WORD instead of modification
                             time: atime -u, access -u, use -u, ctime -c,
                             or status -c; use specified time as sort key
                             if --sort=time
      --time-style=STYLE     with -l, show times using style STYLE:
                             full-iso, long-iso, iso, locale, +FORMAT.
                             FORMAT is interpreted like 'date'; if FORMAT is
                             FORMAT1<newline>FORMAT2, FORMAT1 applies to
                             non-recent files and FORMAT2 to recent files;
                             if STYLE is prefixed with 'posix-', STYLE
                             takes effect only outside the POSIX locale
  -t                         sort by modification time, newest first
  -T, --tabsize=COLS         assume tab stops at each COLS instead of 8
  -u                         with -lt: sort by, and show, access time
                               with -l: show access time and sort by name
                               otherwise: sort by access time
  -U                         do not sort; list entries in directory order
  -v                         natural sort of (version) numbers within text
  -w, --width=COLS           assume screen width instead of current value
  -x                         list entries by lines instead of by columns
  -X                         sort alphabetically by entry extension
  -Z, --context              print any SELinux security context of each file
  -1                         list one file per line
      --help     display this help and exit
      --version  output version information and exit

SIZE is an integer and optional unit (example: 10M is 10*1024*1024).  Units
are K, M, G, T, P, E, Z, Y (powers of 1024) or KB, MB, ... (powers of 1000).

Using color to distinguish file types is disabled both by default and
with --color=never.  With --color=auto, ls emits color codes only when
standard output is connected to a terminal.  The LS_COLORS environment
variable can change the settings.  Use the dircolors command to set it.

Exit status:
 0  if OK,
 1  if minor problems (e.g., cannot access subdirectory),
 2  if serious trouble (e.g., cannot access command-line argument).

Report ls bugs to bug-coreutils@gnu.org
GNU coreutils home page: <http://www.gnu.org/software/coreutils/>
General help using GNU software: <http://www.gnu.org/gethelp/>
For complete documentation, run: info coreutils 'ls invocation'
wangjie@ubuntu:~/TestLinuxCommond$ 

3. ls command

lsUsed to display which files or directories are in the current directory(Window Call Folder Down).
Remarks:
Use ls -l You can display all the contents of the current directory in a list form, and display the details of the file at the same time.
For example, I would like to see what files are in the current directory, which can be usedls.

wangjie@ubuntu:~/TestLinuxCommond$ ls
test.txt
wangjie@ubuntu:~/TestLinuxCommond$

For example, I would like to see the details of the files in the current directory, using ls-l.

wangjie@ubuntu:~/TestLinuxCommond$ ls -l
total 0
-rw-rw-r-- 1 wangjie wangjie 0 Jul 18 16:24 test.txt
wangjie@ubuntu:~/TestLinuxCommond$ 

IV. touch command

touch is used to create text files, which can be suffixed or not, depending entirely on personal preferences.
For example, I want to create a testlinux.txt file that can be used to touch testlinux.txt

wangjie@ubuntu:~/TestLinuxCommond$ touch testlinux.txt
wangjie@ubuntu:~/TestLinuxCommond$ ls
testlinux.txt  test.txt
wangjie@ubuntu:~/TestLinuxCommond$ 

5. mkdir command

mkdir is used to create directories, and directories under linux are equivalent to folders under Windows.
For example, I want to create a test directory that can use mkdir test

wangjie@ubuntu:~/TestLinuxCommond$ mkdir test
wangjie@ubuntu:~/TestLinuxCommond$ ls
test  testlinux.txt  test.txt
wangjie@ubuntu:~/TestLinuxCommond$ 

6. pwd command

pwd is used to display the path of the current directory.
For example, I'd like to see what path my current directory is in, and I can use pwd.

wangjie@ubuntu:~/TestLinuxCommond$ pwd
/home/wangjie/TestLinuxCommond
wangjie@ubuntu:~/TestLinuxCommond$ 

VII. echo Order

The echo command is mainly used to append content to text files.
For example, if I want to write Hello Linux to the testlinux.txt file, I can use echo "hello Linux" > testlinux.txt.

wangjie@ubuntu:~/TestLinuxCommond$ echo "hello Linux" > testlinux.txt 
wangjie@ubuntu:~/TestLinuxCommond$ cat testlinux.txt 
hello Linux
wangjie@ubuntu:~/TestLinuxCommond$ 

8. cat command

The cat command is mainly used to display the contents of text files.
For example, if I want to display the content in the text of testlinux.txt, I can use cat testlinux.txt.

wangjie@ubuntu:~/TestLinuxCommond$ cat testlinux.txt 
hello Linux
wangjie@ubuntu:~/TestLinuxCommond$ 

9. Tab Bond

Tab key stay Linux The following functions are mainly used to assist input and quickly complete.
For example, we would like to look at the current directory test When we start a directory or file, but we forget the full name of the file or directory, we can press it at the beginning of the input.Tab key,The system will be listed as followstestAll files or directories at the beginning.
Examples are as follows:

wangjie@ubuntu:~/TestLinuxCommond$ ls test
test/          testlinux.txt  test.txt       
wangjie@ubuntu:~/TestLinuxCommond$ 

10. vi or vim commands

vi or vim commands, mainly through the vim editor to edit text files.
For example, we want to edit the file testlinux.txt, which can be used at this time vim testlinux.txt or vim testlinux.txt.
After entering the command, you need to input the text file according to i or a.

1. Insert text file process by i or a

2. Press the Esc key and enter: (colon) Save the file

command Significance
w Preservation
q Sign out
! force
wq Save and exit
q! Abandon modification and compulsory withdrawal

3. Setnu Display Line Number Setnonu Cancel Display Line Number

The format is as follows:
set nu or set nonu

4. / Find strings to find strings

The format is as follows:
/ Find strings
For example, to find e, pressing the N key at this time can switch globally to find the upper and lower strings.

XI. rm Order

The rm command is mainly used to delete files or directories. Note that there are differences between the two.

Delete files

The format is as follows:rm file name
For example, I want to delete test.txt and use rm text.txt

wangjie@ubuntu:~/TestLinuxCommond$ ls
test  testlinux.txt  test.txt
wangjie@ubuntu:~/TestLinuxCommond$ rm test.txt 
wangjie@ubuntu:~/TestLinuxCommond$ ls
test  testlinux.txt
wangjie@ubuntu:~/TestLinuxCommond$ 
Delete the directory,

The format is as follows:
Rm-r filename
When deleting a directory, you need to add the parameter - r, which is mainly used to recursively delete all the contents of the directory (including directories, files, etc.).
For example, I want to delete the test directory

wangjie@ubuntu:~/TestLinuxCommond$ ls
test  testlinux.txt
wangjie@ubuntu:~/TestLinuxCommond$ rm test
rm: cannot remove 'test': Is a directory
wangjie@ubuntu:~/TestLinuxCommond$ ls
test  testlinux.txt
wangjie@ubuntu:~/TestLinuxCommond$ rm -r test
wangjie@ubuntu:~/TestLinuxCommond$ ls
testlinux.txt
wangjie@ubuntu:~/TestLinuxCommond$ 

12. mv command

mv is mainly used to move or rename files.

rename

The format is as follows:
New name of mv old name file
If I want to rename testlinux.txt to test.txt, I can use MV testlinux.txt test.txt
Examples are as follows:

wangjie@ubuntu:~/TestLinuxCommond$ mkdir testmv
wangjie@ubuntu:~/TestLinuxCommond$ ls
testlinux.txt  testmv
wangjie@ubuntu:~/TestLinuxCommond$ mv testlinux.txt  test.txt
wangjie@ubuntu:~/TestLinuxCommond$ ls
testmv  test.txt
wangjie@ubuntu:~/TestLinuxCommond$ 

move

The format is as follows:
mv files to be moved to the destination of the files to be moved
For example, I want to move test.txt from the current directory to the test MV directory, using mv test.txt testmv/

wangjie@ubuntu:~/TestLinuxCommond$ ls
testmv  test.txt
wangjie@ubuntu:~/TestLinuxCommond$ mv test.txt testmv/
wangjie@ubuntu:~/TestLinuxCommond$ ls
testmv
wangjie@ubuntu:~/TestLinuxCommond$ cd testmv/
wangjie@ubuntu:~/TestLinuxCommond/testmv$ ls
test  test.txt
wangjie@ubuntu:~/TestLinuxCommond/testmv$ 

13. Command of cp

The format is as follows:
The destination of the file to be copied by mv
The cp command is used to copy files.
For example, if I want to copy text.txt to the test directory, I can use cp test.txt test.

wangjie@ubuntu:~/TestLinuxCommond/testmv$ ls
test  test.txt
wangjie@ubuntu:~/TestLinuxCommond/testmv$ cp test.txt test
wangjie@ubuntu:~/TestLinuxCommond/testmv$ cd test/
wangjie@ubuntu:~/TestLinuxCommond/testmv/test$ ls
test.txt
wangjie@ubuntu:~/TestLinuxCommond/testmv/test$ 

14. find command

find Used to find search files.
For example, I want to find the name of the current directory.test.txtDocuments
have access tofind . -name test.txt Command lookup.
Examples are as follows:

wangjie@ubuntu:~/TestLinuxCommond$ find . -name test.txt
./testmv/test.txt
./testmv/test/test.txt
wangjie@ubuntu:~/TestLinuxCommond$ 

15. Naming grep

The grep command is used to find string resources in files.

Case-sensitive

For example, if I want to find the string Sprocomm, I can use grep "Sprocomm" -r.
At this point, the search is strictly case-based.

wangjie@ubuntu:~/TestLinuxCommond$ grep "Sprocomm" -r .
./testmv/test.txt:Welcome to Sprocomm
./testmv/test/test.txt:Welcome to Sprocomm
wangjie@ubuntu:~/TestLinuxCommond$ 
Case insensitive

Add - i, ingore ignores case.
For example, if I want to find the string Sprocomm, I can use grep "Sprocomm" -ri.

wangjie@ubuntu:~/TestLinuxCommond$ grep "sprocomm" -r .
wangjie@ubuntu:~/TestLinuxCommond$ grep "sprocomm" -ri .
./testmv/test.txt:Welcome to Sprocomm
./testmv/test/test.txt:Welcome to Sprocomm

16. chmod command

chmod Commands are mainly used to modify directory or file permissions.

wangjie@ubuntu:~/TestLinuxCommond$ ls -l
total 4
drwxrwxr-x 3 wangjie wangjie 4096 Jul 18 17:56 testmv
wangjie@ubuntu:~/TestLinuxCommond$ 
Name Abbreviation Representational significance numerical value
d dir Catalog -
r read Read File Permission 4
w write Write File Permission 2
x - Executable permissions (usually sh scripts, library files, etc.) 1

Join me to change the read and write permissions of all files under testmv.
You can use Chmod 777-R.

wangjie@ubuntu:~/TestLinuxCommond$ ls -l
total 4
drwxrwxr-x 3 wangjie wangjie 4096 Jul 18 17:56 testmv
wangjie@ubuntu:~/TestLinuxCommond$ chmod 777 -R .
wangjie@ubuntu:~/TestLinuxCommond$ ls -l
total 4
drwxrwxrwx 3 wangjie wangjie 4096 Jul 18 17:56 testmv
wangjie@ubuntu:~/TestLinuxCommond$ 

17. Compression and decompression commands

tar compression decompression command

Compression command format:
Files to be compressed by tar-cvf*.tar
For example, I want to compress a testmv.tar, using tar -cvf test.tar testmv/

wangjie@ubuntu:~/TestLinuxCommond$ tar -cvf test.tar testmv/
testmv/
testmv/test.txt
testmv/test/
testmv/test/test.txt
wangjie@ubuntu:~/TestLinuxCommond$ ls
testmv  test.tar
wangjie@ubuntu:~/TestLinuxCommond$ 

Unzip command format
tar -xvf test.tar
For example, I want to decompress a test.tar, using tar -xvf test.tar

wangjie@ubuntu:~/TestLinuxCommond$ rm -rf testmv/
wangjie@ubuntu:~/TestLinuxCommond$ ls
test.tar
wangjie@ubuntu:~/TestLinuxCommond$ tar -xvf test.tar  
testmv/
testmv/test.txt
testmv/test/
testmv/test/test.txt
wangjie@ubuntu:~/TestLinuxCommond$ ls
testmv  test.tar
wangjie@ubuntu:~/TestLinuxCommond$ 

So far, this article is over. If there are any mistakes, you are welcome to make suggestions and corrections. At the same time look forward to your attention, thank you for reading, thank you!

Tags: Android Ubuntu Linux vim shell

Posted on Mon, 02 Sep 2019 03:05:37 -0700 by Dark_Archon