Learn Together for a Lifetime Here is Programmer Android
This article mainly introduces some knowledge points in Android
development. By reading this article, you will gain the following content:
1. cd command 2. –help command 3. ls command 4. touch command 5. mkdir command 6. pwd command 7. echo command 8. cat command 9. Tab key 10. vi or vim command 11. rm command 12. mv command 13. cp command 14. find command 15. grep command 16. chmod command 17. Compression and decompression commands 18. Top command 19. Find strings in a specific type of file (e.g., *.xml) 20. String replacement command 21. Tree command 22. Display all files in a directory 23. Count the number of files in a directory
1. cd Command
The cd
command is one of the commonly used commands in Linux
, mainly used to enter a directory (equivalent to a folder in Windows)
. For example, if I want to enter the TestLinuxCommond
directory, I can use cd TestLinuxCommond/
programAndroid@ubuntu:~$ cd TestLinuxCommond/
programAndroid@ubuntu:~/TestLinuxCommond$
If I want to exit the TestLinuxCommond
directory, I can use cd ..
programAndroid@ubuntu:~/TestLinuxCommond$ cd ..
programAndroid@ubuntu:~$
If I want to go back two levels, I can use cd ../..
programAndroid@ubuntu:~/TestLinuxCommond/testmv/test$ ls
programAndroid@ubuntu:~/TestLinuxCommond/testmv/test$ cd ../..
programAndroid@ubuntu:~/TestLinuxCommond$
2. –help Command
When we do not know how to use a command, we can use --help
to see what this command does. --help
is equivalent to a user command help manual. For example, if I want to see how to use the cd
command, I can use cd ---help
programAndroid@ubuntu:~/TestLinuxCommond$ cd ---help
-bash: cd: --: invalid option
cd: usage: cd [-L|[-P [-e]] [-@]] [dir]
programAndroid@ubuntu:~/TestLinuxCommond$
If I want to see how to use the ls
command and what parameters it has, I can use ls ---help
programAndroid@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 [email protected]
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'
programAndroid@ubuntu:~/TestLinuxCommond$
3. ls Command
The ls
command is used to display the files or directories (called folders in Windows)
in the current directory. Note: Using ls -l
can display all contents of the current directory in a list format, along with detailed information about the files. For example, if I want to see what files are in the current directory, I can use ls
.
programAndroid@ubuntu:~/TestLinuxCommond$ ls
test.txt
programAndroid@ubuntu:~/TestLinuxCommond$
If I want to see detailed information about the files in the current directory, I can use ls -l
programAndroid@ubuntu:~/TestLinuxCommond$ ls -l
total 0
-rw-rw-r-- 1 programAndroid programAndroid 0 Jul 18 16:24 test.txt
programAndroid@ubuntu:~/TestLinuxCommond$
4. touch Command
The touch
command is used to create text files, which can have extensions or not, depending on personal preference. For example, if I want to create a testlinux.txt
file, I can use touch testlinux.txt
programAndroid@ubuntu:~/TestLinuxCommond$ touch testlinux.txt
programAndroid@ubuntu:~/TestLinuxCommond$ ls
testlinux.txt test.txt
programAndroid@ubuntu:~/TestLinuxCommond$
5. mkdir Command
The mkdir
command is used to create directories, which in Linux
are equivalent to folders in Windows
. For example, if I want to create a test
directory, I can use mkdir test
programAndroid@ubuntu:~/TestLinuxCommond$ mkdir test
programAndroid@ubuntu:~/TestLinuxCommond$ ls
test testlinux.txt test.txt
programAndroid@ubuntu:~/TestLinuxCommond$
6. pwd Command
The pwd
command is used to display the path of the current directory. For example, if I want to see what the path of my current directory is, I can use pwd
programAndroid@ubuntu:~/TestLinuxCommond$ pwd
/home/programAndroid/TestLinuxCommond
programAndroid@ubuntu:~/TestLinuxCommond$
7. echo Command
The echo
command is mainly used to append content to text files. For example, if I want to write hello Linux
into the testlinux.txt
file, I can use echo "hello Linux" > testlinux.txt
programAndroid@ubuntu:~/TestLinuxCommond$ echo "hello Linux" > testlinux.txt
programAndroid@ubuntu:~/TestLinuxCommond$ cat testlinux.txt
hello Linux
programAndroid@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 contents of testlinux.txt
, I can use cat testlinux.txt
programAndroid@ubuntu:~/TestLinuxCommond$ cat testlinux.txt
hello Linux
programAndroid@ubuntu:~/TestLinuxCommond$
9. Tab Key
The Tab key
in Linux is mainly used to assist input and provide a quick completion function. For example, if we want to see the directories or files starting with test in the current directory, but we forget the full name of the file or directory, we can press the Tab key
after entering the beginning, and the system will list all files or directories starting with test
. Here is an example:
programAndroid@ubuntu:~/TestLinuxCommond$ ls test
test/ testlinux.txt test.txt
programAndroid@ubuntu:~/TestLinuxCommond$
10. vi or vim Command
The vi
or vim
command is mainly used to edit text files through the vim
editor. For example, if we want to edit the testlinux.txt
file, we can use vim testlinux.txt
or vim testlinux.txt
. After entering the command, you need to press i
or a
to perform input operations on the text file.
1. Press i
or a
to insert into the text file
2. Press the Esc key, then enter :
to save the file
Command | Meaning |
---|---|
w |
Save |
q |
Exit |
! |
Force |
wq |
Save and exit |
q! |
Discard changes and force exit |
3. set nu to display line numbers, set nonu to cancel displaying line numbers
Usage format: set nu
or set nonu
set nu
4. /search_string
is used to search for strings
Usage format: /search_string
For example, to search for e
, pressing N key
can globally switch between searching for the previous and next strings.
/search_string
11. rm Command
The rm
command is mainly used to delete files or directories, noting that there is a difference between the two.
Delete files
Usage format: rm filename
For example, if I want to delete test.txt
, I can use rm test.txt
programAndroid@ubuntu:~/TestLinuxCommond$ ls
test testlinux.txt test.txt
programAndroid@ubuntu:~/TestLinuxCommond$ rm test.txt
programAndroid@ubuntu:~/TestLinuxCommond$ ls
test testlinux.txt
programAndroid@ubuntu:~/TestLinuxCommond$
Delete directories
Usage format: rm -r filename
When deleting a directory, you need to add the -r
parameter, which is mainly used to recursively delete all contents within the directory (including directories, files, etc.). For example, if I want to delete the test
directory
programAndroid@ubuntu:~/TestLinuxCommond$ ls
test testlinux.txt
programAndroid@ubuntu:~/TestLinuxCommond$ rm test
rm: cannot remove ‘test’: Is a directory
programAndroid@ubuntu:~/TestLinuxCommond$ ls
test testlinux.txt
programAndroid@ubuntu:~/TestLinuxCommond$ rm -r test
programAndroid@ubuntu:~/TestLinuxCommond$ ls
testlinux.txt
programAndroid@ubuntu:~/TestLinuxCommond$
12. mv Command
The mv
command is mainly used to move or rename files.
Rename
Usage format: mv old_filename new_filename
For example, if I want to rename testlinux.txt
to test.txt
, I can use mv testlinux.txt test.txt
as shown below:
programAndroid@ubuntu:~/TestLinuxCommond$ mkdir testmv
programAndroid@ubuntu:~/TestLinuxCommond$ ls
testlinux.txt testmv
programAndroid@ubuntu:~/TestLinuxCommond$ mv testlinux.txt test.txt
programAndroid@ubuntu:~/TestLinuxCommond$ ls
testmv test.txt
programAndroid@ubuntu:~/TestLinuxCommond$
Move
Usage format: mv file_to_move destination_directory
For example, if I want to move test.txt
from the current directory to the testmv
directory, I can use mv test.txt testmv/
programAndroid@ubuntu:~/TestLinuxCommond$ ls
testmv test.txt
programAndroid@ubuntu:~/TestLinuxCommond$ mv test.txt testmv/
programAndroid@ubuntu:~/TestLinuxCommond$ ls
testmv
programAndroid@ubuntu:~/TestLinuxCommond$ cd testmv/
programAndroid@ubuntu:~/TestLinuxCommond/testmv$ ls
test test.txt
programAndroid@ubuntu:~/TestLinuxCommond/testmv$
13. cp Command
Usage format: cp file_to_copy destination_directory
The cp
command is used to copy files. For example, if I want to copy test.txt
to the test
directory, I can use cp test.txt test
programAndroid@ubuntu:~/TestLinuxCommond/testmv$ ls
test test.txt
programAndroid@ubuntu:~/TestLinuxCommond/testmv$ cp test.txt test
programAndroid@ubuntu:~/TestLinuxCommond/testmv$ cd test/
programAndroid@ubuntu:~/TestLinuxCommond/testmv/test$ ls
test.txt
programAndroid@ubuntu:~/TestLinuxCommond/testmv/test$
To copy and include detailed directory information, use the following method:
programAndroid@programAndroid:$ cp --parents -av tools/releasetools/build_image.py /programAndroid/log/
14. find Command
The find
command is used to search for files. For example, if I want to find a file named test.txt
in the current directory, I can use find . -name test.txt
command to search. Here is an example:
programAndroid@ubuntu:~/TestLinuxCommond$ find . -name test.txt
./testmv/test.txt
./testmv/test/test.txt
programAndroid@ubuntu:~/TestLinuxCommond$
To find a path that includes three levels of directories, use the following command:
find /home/test -type d -maxdepth 3
15. grep Command
The grep
command is used to search for string resources in files.
Case-sensitive
For example, if I want to search for the string Sprocomm
, I can use grep "Sprocomm" -r .
This search is strictly case-sensitive.
programAndroid@ubuntu:~/TestLinuxCommond$ grep "Sprocomm" -r .
./testmv/test.txt:Welcome to Sprocomm
./testmv/test/test.txt:Welcome to Sprocomm
programAndroid@ubuntu:~/TestLinuxCommond$
Case-insensitive
Add -i
to ignore case sensitivity. For example, if I want to search for the string Sprocomm
, I can use grep "Sprocomm" -ri .
programAndroid@ubuntu:~/TestLinuxCommond$ grep "sprocomm" -r .
programAndroid@ubuntu:~/TestLinuxCommond$ grep "sprocomm" -ri .
./testmv/test.txt:Welcome to Sprocomm
./testmv/test/test.txt:Welcome to Sprocomm
16. chmod Command
The chmod
command is mainly used to modify the permissions of directories or files.
programAndroid@ubuntu:~/TestLinuxCommond$ ls -l
total 4
drwxrwxr-x 3 programAndroid programAndroid 4096 Jul 18 17:56 testmv
programAndroid@ubuntu:~/TestLinuxCommond$
Name | Abbreviation | Meaning | Value |
---|---|---|---|
d |
dir | Directory | – |
r |
read | Read file permission | 4 |
w |
write | Write file permission | 2 |
x |
– | Executable permission (usually for sh scripts, library files, etc.) |
1 |
If I want to change the read, write, and execute
permissions for all files in the testmv
directory, I can use chmod 777 -R .
programAndroid@ubuntu:~/TestLinuxCommond$ ls -l
total 4
drwxrwxr-x 3 programAndroid programAndroid 4096 Jul 18 17:56 testmv
programAndroid@ubuntu:~/TestLinuxCommond$ chmod 777 -R .
programAndroid@ubuntu:~/TestLinuxCommond$ ls -l
total 4
drwxrwxrwx 3 programAndroid programAndroid 4096 Jul 18 17:56 testmv
programAndroid@ubuntu:~/TestLinuxCommond$
17. Compression and Decompression Commands
tar Compression and Decompression Command
Compression command format: tar -cvf *.tar files_to_compress
For example, if I want to compress a testmv.tar
, I can use tar -cvf test.tar testmv/
programAndroid@ubuntu:~/TestLinuxCommond$ tar -cvf test.tar testmv/
testmv/
testmv/test.txt
testmv/test/
testmv/test/test.txt
programAndroid@ubuntu:~/TestLinuxCommond$ ls
testmv test.tar
programAndroid@ubuntu:~/TestLinuxCommond$
Decompression command format: tar -xvf test.tar
For example, if I want to decompress a test.tar
, I can use tar -xvf test.tar
programAndroid@ubuntu:~/TestLinuxCommond$ rm -rf testmv/
programAndroid@ubuntu:~/TestLinuxCommond$ ls
test.tar
programAndroid@ubuntu:~/TestLinuxCommond$ tar -xvf test.tar
testmv/
testmv/test.txt
testmv/test/
testmv/test/test.txt
programAndroid@ubuntu:~/TestLinuxCommond$ ls
testmv test.tar
programAndroid@ubuntu:~/TestLinuxCommond$
zip Compression Command
programAndroid@programAndroid:/programAndroid/log$ zip -r test.zip test.bat
adding: test.bat (stored 0%)
programAndroid@programAndroid:/programAndroid/log$
18. Top Command
Usage of the Top command
adb shell top -n 30 -m 10 -k -%CPU > top1.txt
19. Find Strings in a Specific Type of File (e.g., *.xml)
find . -type f -name "*.xml" | xargs grep "xxx"
20. String Replacement Command
Command to replace all strings in a directory
For example, replace WLAN with WiFi
sed -i 's/WLAN/WiFi/g' `grep WLAN . -rl`
21. Tree Command
E:\AOSP\android_10_0_0_r40\frameworks\av\camera>tree
Volume in drive Document's folder
Volume serial number is 00000233 65F3:3762
E:.
├─aidl
│ └─android
│ └─hardware
│ └─camera2
│ ├─impl
│ ├─params
│ └─utils
├─camera2
├─cameraserver
├─include
│ └─camera
│ ├─android
│ │ └─hardware
│ └─camera2
├─ndk
│ ├─impl
│ ├─include
│ │ └─camera
│ └─ndk_vendor
│ ├─impl
│ └─tests
└─tests
E:\AOSP\android_10_0_0_r40\frameworks\av\camera>
22. Display All Files in a Directory
find -type f -print
Usage example:
$ find -type f -print
./Android.bp
./Barrier.h
./BufferLayer.cpp
./BufferLayer.h
./BufferLayerConsumer.cpp
./BufferLayerConsumer.h
./BufferQueueLayer.cpp
./BufferQueueLayer.h
./BufferStateLayer.cpp
./BufferStateLayer.h
23. Count the Number of Files in a Directory
The command is as follows: ls -lR |grep '^-' |wc -l
Usage example:
/e/AOSP/android_10_0_0_r40/frameworks/native/services/surfaceflinger (master)
$ ls -lR |grep '^-' |wc -l
294
This concludes this article. The article is a repost from the internet, and the author finds it excellent. Please click to read the original text and support the original author. If there is any infringement, please contact the author to delete it. Your suggestions and corrections are welcome. We look forward to your attention. Thank you for reading!
Give a thumbs up for the big guy!