Purpose:
Learn to use common Linux commands
LLab requirements:
Familiar with the Linux commands described in this section
LLab equipment:
Software:
Vmwarevm with centos 5.5 installed
Hardware: one PC
LTutorial steps:
1. useradd command
Useradd is used to add users. Usage: useradd [Option] User Name
Example: Use the useradd command to add an SMB User
# Useradd SMB
A common user with the name of SMB is added to the/home directory after being created.
SMB folder. This is the main directory of the SMB User.
2. passwd command
The passwd command is used to set the account password. Usage: passwd [Option] user
Name
For example, use the passwd command to set the SMB account password
# Passwd SMB
3. su command
The su command is used to switch users. Usage: su [Option] [user name]
For example, use the su command to switch to the root user.
$ Su-Root
4. shutdown command
Shutdown command: shutdown [-T sec]
[-Arkhncffhp] time [warning message]
For example, use the shutdown command to immediately shut down
# Shutdown now
5. CP command
CP command is used for copying. Usage: CP [Option] source file or directory target file
Component or directory
For example, run the CP command to copy the test file in the/home directory to the/tmp directory.
Lower
# Cp/home/test/tmp/
For example, run the CP command to copy the dir1 directory under the/home directory to the/tmp directory.
.
# Cp-r/home/dir1/tmp/
6. Mv command
The MV command is used to move or rename a video. Usage: MV [Option] source file or directory
Target file or directory
For example, use the MV command to rename the test file in the/home directory to test1.
# Mv/home/test/home/test1
For example, run the MV command to move (CUT)/tmp the dir1 directory in the/home directory.
Directory
# Mv/home/dir1/tmp/
7. rm command
The RM command is used to delete a file or directory. Usage: Rm [Option] file or directory
For example, run the RM command to delete the test file in the/home directory.
# Rm/home/test
For example, run the RM command to delete the Dir directory in the/home directory.
# Rm-r/home/Dir
8. mkdir
The mkdir command is used to create a directory. Usage: mkdir [Option] Directory Name
For example, run the mkdir command to create the workdir directory in the/home directory.
# Mkdir/home/workdir
For example, run the mkdir command to create the/home/dir1/dir2 directory.
Yes. Create dir1 first
# Mkdir-P/home/dir1/dir2
9. CD command
The CD command is used to change the working directory. Usage: CD
Directory Name
For example, run the CD command to enter the/home directory.
# Cd/home/
10. PWD command
The PWD command is used to view the current path. Usage: pwd
For example, run the PWD command to display the absolute path of the current working directory.
# Pwd
11. LS command
The LS command is often used to view directories. Usage: ls [Option] [directory or file]
For example, use the LS command to display the files and directories in the/Home Directory (excluding the hidden
Hidden files)
# Ls/home
For example, use the LS command to display all files and directories in the/Home Directory (including
Hide files)
# Ls-A/home
For example, use the LS command to display the file and directory details in the/home directory.
# Ls-L/home
For example, use the LS command to display the files and directories in the/home directory.
Inter-order
# Ls-C/home
12. tar command
Tar command is used for packaging and compression. Usage: Tar [Option] directory or file
For example, use the tar command to package all files and directories in the/home/tmpdirectory into a tmp.tar file.
# Tar CVF tmp.tar/home/tmp
For example, use the tar command to unbind the packaging file tmp.tar from the current directory.
# Tar xvf tmp.tar
For example, run the tar command to list all files and directories in the/home/tmp directory.
Package and compress it into a tmp.tar.gz File
# Tar cvzf tmp.tar.gz/home/tmp
For example, use the tarcommand to unbind the compressed tmp.tar.gz file from the current directory.
# Tar xvzf tmp.tar.gz
13. Unzip command
The unzip command is used for decompression. Usage: unzip, unzip, and compressed file name. Zip
For example, unzipcommand is used to decompress the tmp.zip file.
# Unzip tmp.zip
14. chmod command
The chmod command is used to change the access permission. Usage: chmod [who] [+ |-| =]
[Mode] File Name
For example, run the CHMOD command to add the same group of users to the owner of the hello. c file.
Write Permission
# Chmod g + W hello. c
For example, use the CHMOD command to change the access permission of the file hello. C to readable and executable by the file owner, readable and writable by users in the same group of file owners, and executable by other users.
# Chmod 761 hello. c
15. df command
The DF command is used to view disk usage. Usage: DF [Option]
For example, the DF command is used to display disk usage in KB.
# DF-K
16. Du command
The du command is used to view the directory. Usage: Du [Option] Directory
For example, run the du command to display the size of the IPC directory in bytes.
# Du-B IPC
17. ifconfig command
The ifconfig command is used for network configuration. Usage: ifconfig [Option] [network interface]
For example, use the ifconfig command to configure the IP address of the eth0 Nic as 192.168.0.100.
# Ifconfig eth0 192.168.0.100
For example, run the ifconfig command to pause the eth0 Nic.
# Ifconfig eth0 down
For example, run the ifconfig command to restore the eth0 Nic.
# Ifconfig eth0 up
18. netstat command
The netstat command is used to view the network status. Usage: netstat [Option]
For example, run the netstat command to view all network listening ports in the system.
# Netstat-
19. grep command
Use the grep command to search for strings. Usage: grep [Option] string
For example, use the grep command to search for directories that contain files in the current directory and Its subdirectories.
String File
# Grep "file"
./-Rn
For example, run the grep command to view all ports used for TFTP.
# Netstat-A | grep TFTP
20. RPM command
The RPM command is used for software installation. Usage: rpm [Option] [Installation File]
For example, use the RPM command to install a file named tftp-server-0.42.1.i386
# Rpm-IVH tftp-server-0.42.1.i386.rpm
For example, run the RPM command to list all installed RPM packages.
# Rpm-Qa
For example, run the RPM command to find the TFTP package in all installation packages.
# Rpm-Qa | grep TFTP
For example, run the RPM command to uninstall an RPM package named tftp-server-0.42-3.1
# Rpm-etftp-server-0.42-3.1
21. mount command
Mount command is used for mounting. Usage: Mount [Option] device Source Target
Recording
For example, use the mount command to mount the optical drive to the/mnt directory.
# Mount/dev/CDROM/mnt
22. umount command
The umount command is used to uninstall the target directory of umount.
For example, use the umount command to cancel mounting the optical drive to/MNT.
Umount/mnt
23. Find command
The find command is used to find files. Usage: Find
Path Name 'filename'
For example, use the find command to search for the TMP name in the current directory and Its subdirectories.
.
# Find./-name 'smb *'
For example, use the find command to find the file named test in the current directory and Its subdirectories.
# Find./-name 'test'
24. Top Command
TOP command is used to dynamically view CPU usage. Usage: Top
For example, use the top command to view the CPU and memory usage of processes in the system.
# Top
25. ps command
The ps command is used to view processes. Usage: PS [Option]
For example, run the ps command to view all processes in the system.
# Ps aux
26. Kill command
The kill command is used to kill processes. Usage: Kill [Option] process number
For example, run the TOP Command on one terminal, and then run the ps command on the other terminal.
Aux, view the process number generated by the top command, and use the kill command to kill this
Process.
# Kill-s sigkill 10670
27. Man command
The man command is used to view the usage information of a command or function. Usage: Man
Command name
For example, run the man command to view how to use the grep command.
# Man grep
For example, run the man command to view how to use the ping command.
# Man Ping