This chapter will introduce the common commands when using the basic version of core electronic devices, advanced general-purpose chips and basic software products desktop operating system, hereinafter referred to as the CAB desktop OS. In this document, all commands will be used in the terminal. The terminal is the interface for human-computer interaction and all commands will be executed in it.
The open mode of the basic version of desktop terminal: Click the "Terminal" button on the taskbar in the desktop to open a terminal. The terminal interface is shown below.
9.1 File and directory management
(1) "ls" List the contents of the directory (List)
"ls" is of high frequency use as a command. The following sections are only a part of the most common use of options. If you want to play a greater measure of “ls” command,please check its help page“ls”—help. ls [Option] File or directory ... ls common options: -l Output file attributes in long list format -R Recursively listed,traverses the entire directory and its subdirectories
--color=[WHEN] According to the property of the output file (file or directory type, etc.), give the project a different color The value of WHEN can be 'always' (default), 'never', 'auto', Meanings in turn are: always, never, automatic -d Only lists the directory, does not list the contents of the directory -h Humanized output, such as using the format K, M, G to mark the file size Examples of usage: ls List the contents of the current directory ls -Rl /home List the details of all files in the /tmp directory and its subdirectories
(2) cd Change working Directory
cd [Directory path] # If the directory path is omitted, it will enter the user's home directory. Examples of usage: cd /tmp cd ~ # enter the user's home directory. In the bash shell, the symbol "~" indicates the user's home directory cd # Omit the path, also enter the user's home directory
(3) touch Create a text file
If the file needs to be created that has already existed,then updates file access time and modification time to the current time. touch [Option] file name 1 ... Examples of usage: touch file1 # If the file1 file does not exist, then create a text file named file1. # Otherwise update its access time and modification time.
(4) cat View the contents of the text file (Concatenate)
If there are multiple files, then output to the standard output in turn. It is equivalent to the contents of several files connected. cat [Option] file name 1 ... cat Common options: -n Display line number Examples of usage: cat /etc/issue # Output the contents of the file / etc / issue to the standard output
(5) cp File and directory copy (Copy)
cp [Option] Source file Target file cp common options: -r Recursively copy, that is, copy the entire directory -v Output the information of copy process -i If the target file already exists, the default action will overwrite the target file. This option requests the user to confirm -n Do not copy files that already exist -u Copy files that are newer than the target file Examples of usage: cp testfile testfile1 # Copy the file named testfile in the current directory and renames the file as testfile1. cp -r dir1 down # Copy the directory named dir1 in the current directory to the down directory
(6)mv File move and rename (Move)
The "mv" command is similar to the file copy command "cp". The difference between them is that if you use "mv" command, the source file will be deleted after completing the operation. Attention:The mv command does not have a recursive option –r. There is no difference between moving directories and moving normal files. mv [option] Source file Target file The common options of mv command: -i By default, mv will overwrite the source file, and this option requests the user to confirm. -n Do not move the existing files. -u Only move the files that are newer than the target file -v Display detailed movement process Examples of usage: mv -vi file1 file2 # Move files interactively. Move files in the same directory, and actually it renames the file.
(7) mkdir Make Directory
If the directory you want to create that has already exists, then do nothing about it. mkdir [option] Directory name 1 ... The common options of mkdir command: -p|--parents When it is necessary, build parent directory -m Set permissions for the created directory -v Output the details of the current operation Examples of usage: mkdir -pv a/b/c # Will be a/b/c hierarchical structure to establish three directories which are named a b c in turn. # Due to the use of the-p option, if a or b directory does not exist, then it will be automatically established together. # If you do not use -p, the system will report an error when the parent directory does not exist mkdir a b c # Establish three directories named a b c in the current directory.
(8) rm Delete a file or directory (Remove)
rm [option] file or directory ... rm common options: -f Mandatory mode Never prompt, and does not require user confirmation -i Interactive mode Ask users to confirm before deleting the file -r Recursively delete Delete the entire directory -v Outputs the details of the current operation Examples of usage: rm -vi file1 # Delete the file file1 rm -vir dir1 # Delete the directory dir1
(9) rmdir Delete empty directory (Remove Rirecotry)
If the directory is not empty, the system prompts the error, does not delete the directory rmdir [option] empty directory ... rmdir common options: -p|--parents If you delete the directory, the parent directory has become an empty directory, then delete it. -v Output the details of the current operation. Examples of usage: rmdir -pv a/b/c # Delete the empty directory c, and if the b directory is empty, then delete the b directory,...
(1) find Search for files
The find command is very powerful and supports regular expressions find Command commonly used to write: find [option] path [other options] The common options of find command: -P Do not follow the symbolic link, that is, ignore the file that the symbolic link points to -L Follow the symbolic link
The other common used options of find command: -type <file_type> Find the specified file type, can be f (common file), d (directory file),c(Character device file),... -name <file_name> Find a specific file. It is sensitive to the capital and small letter of the file. -iname <file_name> Same as –name, but ignore the capital and small letter of the file. -maxdepth level Specify the maximum number of directories to search for(the number of layers), and level is a specific positive number
-mindepth level Specify the minimum directory level to search for and level is a specific positive number -size [-/+] <file_size> Limit the size of the search file, file_size is a specific number,the unit can be c w b k M G. The "-" or "+" sign before the number indicates that the file size is "less than" or "greater than" the number Omitting "-" or "+" indicates that the file size is strictly for the number. -regex pattern Using regular expressions to search for the files. Pattern is the file name expression. -regextype type Setting the standard of resolving regular expression. Type optional values are emacs (default) posix-awk, posix-egrep, posix-extended -exec command \; Executive a command. The contents after -exec are resolved as a part of the command until encounter ";" because the semicolon has special meaning in the Bash Shell, so use the slash "\" escape.
Examples of usage: find . -type f # Find all the files in the current directory find ~ -name .bashrc # Find a file named ".bashrc" in the user directory find /usr -type f -iname "*conf*" # Ignore case to find the files with the file name contains "conf" in the directory /usr find /usr -size +100K -size -2M -regextype posix-egrep -regex ".*png$" # In the /usr directory, find the files whose file size are between 2kB to 2MB and the last three letters of the file name are png. find ~ -type d -size +40M -exec file {} \; # find the files that the file size is more than 40MB in the user directory, and use the file command to check its type.
(1) df List file system usage
df [option] [file] ... df Common options: -a Output all file systems -h User-friendly output information -t <fs_type> Only output the file system type which is limited by fs_type -T Output file system type Examples of usage: df -ht ext4 #Output file system with the type of ext4 df -T # Output file system type df -h /dev/sda1 # Output the usage information of the first partition for the first hard disk
(2) fdisk Disk partition management
This command requires users with privileged user permission fdisk [option] disk The common options of fdisk: -v Print fdisk version information and exit -l List the partition table information for the specified device and exit. If it doesn’t offer device, then use the devices which are mentioned in / proc / partitions. -u Use the number of sectors rather than cylinders to display each partition information in the partition table -s Output the size of the partition (in blocks) to the standard output. Examples of usage: fdisk -l # Output the detailed partitioning information of all hard disks in the current system. fdisk /dev/sda # Enter the hard disk split mode 1.input m Show all commands listed 2.input p Show hard disk segmentation 3. input a Set the hard disk boot area 4. input n Set the new hard disk partition 5. Input t Change the hard disk partition properties 6. input d Delete the hard disk partition properties 7. input q End and does not save the hard disk partition properties 8. input w End and save the hard disk partition properties
(3) mkfs Format the disk
This command requires the permission of privileged user
mkfs [option] Partition The common options of mkfs command: -t Specify the formatted file system type -c Check whether there is a bad block or not before formatting the file system block Specify the size of the block
Examples of usage: mkfs -t ext3 /dev/sda6 #Format the /dev/sda6 partition with the ext3 file type
(4) du Calculate the size of the file / directory
du [option] directory or file ... The common options of du command: -h User-friendly output. The file size is marked by K, M, G -s Output the total occupancy space size of each directory/file Examples of usage: du -h ~ # Output the total occupancy space size of all files and subdirectories in the user's home directory
(5) mount Mount the file system
This command requires the permission of privileged user mount [option] device target directory The common options of mount command: -t Specify the file system type, such as ext3, ext4 and so on -B Mount directory Examples of usage: mount # List all mounted file systems mount -t ext4 /dev/sda6 /mnt # Mount the sixth partition of the first hard disk to the /mnt directory mount -B /media /mnt # mount the directory /media to the directory /mnt
(6) umount uninstall the file system
This command requires the permission of privileged user umount [option] device or directory ... The common option of unmount command: -f Force to uninstall the directory Examples of usage: umount /dev/sda6 # Uninstall the mounted file system /dev/sda6
(1) "top" Display the real-time process list
Once the command top is run, then press the "q" key to exit. top [option] The common options of top command: -p pidlist Only shows dynamic process whose process number in pslist -d num Update interval. Num is the time, Unit is second (s)
Examples of usage: top -d 1 -p 1,2 # Only two processes with process numbers 1 and 2 are monitored and the information is updated once per second
(2) ps List the processes that the current system is running
The command ps accepts three types of options. Some options are conflicting, and some options gets the same function, increasing the difficulty of usage ps [option] The common options of ps command: -e display all processes -a List all processes except the session's first process and the process of unassigned the terminal -u userlist Use the user ID or user name to select the listed process, ID or name in the userlist -p pidlist Only list processes that specify the process number in the pidlist, which can be used multiple times --ppid pidlist Only lists the child processes of the process number that is in pidlist -x List the processes that belong to the current user -ax List all processes. Here 'x' is used in conjunction with 'a' and no other options are available Examples of usage: ps aux oracle # Query oracle process ps --ppid 1 # Lists the process whose parent process is 1
(3) ps List the processes that the current system is running
Pidof Find the process number (pid) based on the process name pidof [option] process name The common options of pidof: -s pidof output the process number as many as possible by the process name, the option is limited that only to output one process number. Examples of usage: pidof lightdm
(4) kill Send a signal to the process
kill [option] pidlist The common options of kill command: -l List the signal name -s signal Specify the signal to be sent, the default is 15 Examples of usage: kill -s 9 <PID> # PID is the specific process number (using the pidof command to find), the signal 9 is the kill process.
(5) killall kill process
killall Kill the process by name killall [option] process name The common options of killall command: -l List all known signal names -v Report whether the signal is sent successfully Examples of usage: killall gedit # Kill all processes which named "gedit"
(1) ifconfig View / set the network (Interface Configure)
This command requires user with the permission of privileged user ifconfig setting the network will not be saved, and all changes will disappear after restarting. Linux network interface can be understood as a network card, cable network card number: eth0 eth1...;Wireless card number:wlan0 wlan1 ... ifconfig [option] [network interface] ifconfig network interface [Protocol address cluster] Option address ...
The common options of ifconfig: -a display all network interfaces up open the network interface down close the network interface netmask set the mask broadcast set the broadcast address Examples of usage: ifconfig -a # Displays all network interface information ifconfig eth0 192.168.1.10 netmask 255.255.255.0 broadcast 192.168.1.254 The above command sets the wired network card IP address to 192.168.1.10, the subnet mask is 255.255.255.0, the broadcast address is 192.168.1.254 ifconfig eth0 down # Close Network card eth0 ifconfig eht0 up # Open Network card eth0
(2) ping The host computer sends the packet
Test the connectivity of the network ping [option] Host The common option of ping: -c By default, the ping is running until the user presses Ctrl+C to abort.The option limits the time of ping. Examples of usage: ping -c 5 127.0.0.1 # Test whether the native TCP/IP protocol is normal or not, 127.0.0.1 has been configured to represent the native machine
(3) netstat View the network status (Network Status)
netstat [option] The common options of netstat: -p display process information -t Only list the entries associated with the tcp protocol -u Only list the entries associated with the udp protocol -n Port, address, etc. use numbers instead of name display -a display all -l only display entries in the listening state
Examples of usage: netstat -atunp # display all the process that use tcp and udp protocol, and the communication address, port number
(1) dpkg Package management tool
This command requires user with the permission of privileged user dpkg is used to manage the system deb package. You can install, uninstall, deb package, deb decompress the system deb package and so on. dpkg [option] deb package The common options of dpkg: -i Install the software package -r Remove the software package -P Delete the package (including the configuration file) -l List the packages that are currently installed on the system Examples of usage: dpkg -i cheese-common_3.10.1-1sid1_all.deb # The installation of the video camera package dpkg -r libmcrypt4 # Uninstall the software package
(2) apt-get Management tool
This command requires user the permission of privileged user
Apt-get is mainly used to automatically search, install, upgrade, and uninstall software or operating system from the Internet's software depot. apt-get [option] command pkg The common command of apt-get: update Retrieve the package list upgrade Update the package install Install new packages remove Remove the package auto remove Automatically remove all unused packages Examples of usage: apt-get upgrade # Update the installed packages apt-get install wine # Install the wine program apt-get remove kolourPaint # Remove the kolourPaint software from the system