FreeBSD Common commands

Source: Internet
Author: User
Tags ssh server dmesg

1: man online query man ls
2: ls viewing directories and archives ls-la
3: ln creates the link file ln-fs/usr/local/apache/etc/httpd. conf/etc/httpd. conf
4: The more file name is displayed on the page.
5: cd/usr/local/apache switch directory
6: Create a new directory named mkdir/usr/temp.
7: rmdir Delete directory rmdir/usr/temp
8: rm Delete directory or file rm-f file name (if you want to delete directory, add-r)
9: cp copy directory or archive cp source archive target Archive
10: pwd displays the current working directory
11: change the name of the mv directory or file or move the target file of the mv source file
12: find directory or file find/etc-name file name

13 fetch FTP get file fetch ftp://ftp.center.kl.edu.tw/pub/FreeBSD/test.tgz
14. chmod: Change the archive permission. chmod-R 755/usr/local/etc
15 chown changed the archive owner chown-R lin. wheel/usr/local/etc
16 fsck repair File System fsck-y
17. gzip/tar: Compressed or decompressed files or directories tar-czvf: compressed file name .tar.gz directory name
18 mount the file system or device mount/cdrom
19 umount unload the file system or the umount/cdrom Device
20 df query system available archive df
21 du: disk space occupied by the display directory or file du-a quota name (du-sh can be used to obtain the disk space in the current folder)
22 ps Query System process status ps-aux | grep apach *
23 kill A process kill pid
24 su change identity su-root
25 adduser
26 rmuser delete user
27 vipw edit user account
28 passwd Change Password
29 ping detection machine online status ping 210.240.6.9
30 ifconfig network interface settings and Management ifconfig-
31 route you can set the routing table
32 traceroute: list the route traceroute 210.240.8.1
33. netstat can be used to query network usage and online conditions.
34 pkg_add install package pkg_add bash-2.04.tgz
35 pkg_delete remove Installed package pkg_delete bash-2.04
36 pkg_info query installation records
37 sync forces the system to write the cached data back to the hard disk
38 reboot restart the system
39 halt shut down the system
40 shutdown: notifies the user that the system will be shut down
41 init 0 direct Shutdown
Chown-R owner. group file or directory
-R: The owner and group of all files under the table directory will change.

Chmod
Drwxrwxrwx
Lr-rwxr-x
1 2 3 4
D: Table directory
R: Table read
W: Table write
X: The table is executable.
-: Disable the table function.

L: Table linked files
2: Permission to read the file or directory owner
3: Read Permission for the same group of the file or directory owner
4: read permissions of people on the network
-R: the permission to read all files in the table directory is changed.

Gzip/tar
Tar czvf compressed file name .tar.gz directory name
Z: gzip Compression
C: Create a new compression File
V: adopts the verbose mode to watch the compression process.
F: Force

Tar zxvf compressed file name .tar.gz
Z: Decompress with gzip
X: Extract
V: adopts the verbose mode to watch the compression process.
F: Force

Ifconfig
Query all network interfaces
Ifconfig-

Set Network Interface Parameters
Ifconfig de0 192.168.1.10 netmask 255.255.255.0

Stop Network Interface
Ifconfig de0 down

Start Network Interface
Ifconfig de0 up

Route
Gateway for changing routing path
Route change default 192.168.1.254

Netstat
Query a routing table
Netstat-rn

Query network interface traffic statistics
Netstat-I
Query TCP network connection conditions
Netstat-t
Query all online network conditions
Netstat-

Shutdown
How long will the user be notified of shutdown? The administrator needs reboot or halt
Shutdown-k Time Message
How long will the user be notified to restart the system?
Shutdown-r time message
How long will it take to notify the user to shut down the system?
Shutdown-h Time Message

Time: now or + 3 tables three minutes later or yymmddhhmm
Message: enclosed in double quotation marks or prefixed with A-sign

Some common other combined commands:
Shift + g is the same as the END key under win, so that the cursor is at the END of the document.
:/The function is to search for text in a document.
: Find: This is a file search.

========================================================== ======

1. View related directory descriptions
# Man hier
2. Use pw to manage user information
# Pw groupadd group1 add Group
# Pw useradd-n user1-g group1-m-s/bin/csh
-N username/Specify the user name
-G groupname/Specify the group name
-M/automatically create a user directory
-S/Specify the User shell
# Echo | pw useradd-n username-g group-m-s/bin/csh-h 0
The main parameter is-h-0. You can directly create and change the user's password when creating a user;
# Pw userdel-n username-r/delete user
-R: Delete the home directory at the same time.
# Pw groupshow wheel view members of this group
# Pw groupmod wheel-M user1 add user1 user to the wheel group
-M sets this user as the only member in this group.
-M: Add a user to the group
2.1 Add users interactively using commands
Adduser
Rmuser delete user
Chpass tool used to modify user database information
Passwd tool for changing user passwords
Pw tool for modifying user accounts
2.2 Use the id command to display the changed user information
# Id username
# Id root
Uid = 0 (root) gid = 0 (wheel) groups = 0 (wheel), 5 (operator)
3. Use the screensaver program
Add the following information to the/etc/rc. conf file:
Blanktime = "900" is enabled for 15 minutes, in seconds
Saver = "logo" graphic interface (image), daemon (text ).
4. Empty a file.
# True> filename
5.convert the help information of ssh2into A ssh2.txt file;
# Man find | col-B> find. Txt
6. Forgot FREEBSD password Solution
Restart FreeBSD. Select 4 when there is a countdown. after entering the system, run '#/sbin/mount-a'. Now you can use 'passwd' to change the root password.
7. In freebsd, I want to use the su command to switch to the root user. Your user should be in the WHEEL group so that I can SU the user to the ROOT user.
8. mount the disk to the dos/ntfs partition.
# Mount-t msdosfs/dev/ad0s1/mnt
# Mount-t mount_ntfs/dev/ad0s1/mnt
9. When you log on in single-user mode, you are also prompted to enter the password and modify the/etc/ttys file.
Console none unknown off secure
Change the secure to insecure, so that the account information is also provided when a single user logs on.
10. Freebsd directory Architecture
/Etc/defaults system default startup configuration and Script directory
/Etc/periodic directory of the script to be executed
11. Use the pkg_add command to install a breebsd package from a local or network server. A single package must be used. Tgz or. Tbz format.
# Pkg_add XXX-1.11.1.tgz
12. Use pkg_info to list the list and description of all installed software packages.
# Pkg_info
13. Use pkg_version to count all installation packages
14. Use pkg_dalete to delete software installed on the contrary. The complete package name must be provided.
# Pkg_dalete XXX-1.11.1
15. Use the pciconf tool to display detailed hardware output
# Pciconf
16. View CPU:
Sysctl hw. model hw. ncpu
Dmesg | grep "CPU :"

17. view memory:
Dmesg | grep "real memory" | awk-F' [()] ''{print $2, $4, $7, $8 }'
18. view the hard disk:
Dmesg | grep "sector" | awk '{print $1, $2 }'
19. mount a file system:
Mount_msdosfs/dev/ad0s1/mnt
Mount_ntfs/dev/ad0s1/mnt
20. Add or disable the system blocking mark to the file (the directory is not applicable ):
Chflags sunlink file1
Chflags nosunlink file1
21. initialize the disk:
Fdisk-BI ad1
22. Create a FreeBSD partition:
Disklabel-B-w-r ad1s1 auto
23. Create a logical partition:
Disklabel-e ad1s1
24. format the partition and create a file system:
Newfs/dev/ad1s1e
25. Display PCI hardware information:
Pciconf-lv
26. Enable Linux binary compatibility (the simplest way to enable this function is to load the linux KLD module ):
Kldload linux
27. Check whether the KLD module is loaded:
Kldstat
28. statically link to the Linux binary compatibility mode in the kernel, and add the following to the Kernel configuration file:
Options COMPAT_LINUX
29. Modify/etc/rc. conf if you want LINIX compatibility to support starting in the initial process.
Linux_enable = "yes"
30. view the server brand
# Dmegs | grep ACPI
=============== System Management ========================================
1. Nic and nic chipset Information
/Usr/scr/sys/conf/NOTES or/usr/src/sys/arch/conf/NOTES
Nic and chipset information will be provided in these two directories
2. Load the module corresponding to the NIC
# Kldoad
3. use the windows NDIS driver to load the NIC Driver. If you want to use NDISulator, you need three types of windows xp drivers (with the extension. SYS)/windows xp driver configuration file (Extension. inf); in the following example, we use W32DRIVER. SYS and W32DRIVER. INF to indicate these files
A. Use the root user to execute the ndisgen command to load a binary driver into a kernel module.
# Ndisgen/path/to/W32DRIVER. INF/path/to/W32DRIVER. SYS
After the Interactive Test Program is executed, the system will prompt you to enter some other information. After the test is completed, the system will generate the ygie kernel module file in the current directory.
B. Load the new kernel module File.
# Kldload./W32driver. ko
C. In addition to loading new modules, there are two kernel modules: ndis. ko and if_ndis.ko.
# Kldoad ndis. ko load the ndis driver encapsulation Module
# Kldoad if_ndis.ko load the actual network interface
D. automatically load the module, copy W32DRIVER. KO to the/boot/modules directory, and add it to/boot/loader. conf.
W32DRIVER_load = "YES
4. bind multiple IP addresses to a network card, mainly modifying/etc/rc. conf file, but the NIC alias must start from alias0 and increase sequentially. The general description is as follows:
Ifconfig _ Nic name _ alias0 = "inet xxx. xxx netmask xxx. xxx"
For example, my own is
Ifocnfig_lnc0_alias0 = "inet 192.168.137.1 netmask 255.255.255.0 ″
Ifconfig_lnc0_alias1 = "inet 192.168.138.1 netmake 255.255.255.0 ″
5. Run the following command to change the NIC working mode:
Full-duplex
# Ifconfig lnc0 media 100 baseTX mediaopt full-duplex
Half duplex
# Ifconfig lnc0 media 100 base
6. Set the client DNS file/etc/resolv. conf. The record format is as follows:
Nameserver queries the IP address of the DNS server in sequence, up to three
Search for the list of machine names, usually determined by the local domain name
Domin local domain name
Search example.com
Nameserver 202.96.0.133
Nameserver 202.97.16.195
7./etc/hosts file format
[Internet address] [official hostname] [alias1] [alias2]…

8. syslog. conf is the configuration file of syslogd program. It stores a specific log file, newsyslog. conf is a configuration file that is scheduled to run. newsyslog indicates when the log files need to be packaged or reorganized. for example, if logfile is moved to logfile.0 and logfile.0 is moved to the same level as logfile.1, the log writer can also use gzipto compress the log file, whose name is logfile.0.gz. <page 301>
9. sysctl. conf and rc. the conf file style is similar. The configuration is in the form of variable = value. The configuration of this file will be modified after the system enters multi-user mode, not all variables are modified in multi-user mode. for example, you want to disable the record that receives a fatal signal and stop common users from seeing other users' processes.
A. Process exited due to a fatal signal is not recorded
Kern. logsigexit = 0
B. Prevent the user from seeing the process executed as another UID
Seurity. bsd. see_other_uids = 0
10. sysctl can be used to change the running Freebsd system interface. It contains some advanced options for the TCP/IP stack and virtual memory system. At the same time, it can read and set 500 system variables, the sysctl variable is usually set as a string, number, or Boolean (Boolean uses 1 to represent "yes" and 0 to represent "no ")
# View all variables in sysctl-;
# Sysctl kern. maxproc reads a specified variable;
# Sysctl kern. maxfiles = 5000 set a specified variable and use the variable = value Syntax directly;
11. Create a swap file in FreeBSD
1. First create a swap file (swap0)
# Dd if =/dev/zero of =/mnt/swap0 bs = 1024 k count = 64
2. grant appropriate permissions to this file
# Chmod 0600/mnt/swap0
3. Enable the switch file in/etc/rc. conf to love you
Swapfile = "/mnt/swap0" # set to name ofswapfile
4. Takes effect after the machine is restarted
# Mdconfig-a-t vnode-f/mnt/swap0-u o & swapon/dev/md0
12. Use openssh to create a tunnel. In this example, use ssh to create a tunnel for telnet.
# Ssh-2-N-f-L 5023: localhost: 23 user@foo.example.com
Parameter description:
-2 force ssh to use the second version of the protocol
-N indicates that the command line is not used, and only the tunnel is used.
-F force ssh to be executed in the background
-L indicates that a local port is generated: Remote Host: Tunnel in the form of remote port
User@foo.example.com remote ssh Server
13. Restrict ssh Logon
1. Only the root user is allowed to log on to the server from 192.168.1.2:
Modify the/etc/ssh/sshd_conf file and add the following parameters to the file:
AllowUsers root@192.168.1.2
2. Allow admin users to log on from any location
AllowUsers admin
You can also specify multiple users in the same row.
Allowusers root@192.168.1.2 admin
14. Set the ACL of the file
# Getfacl filename
# Setfacl filename: sets the object acl Information
# Setfacl-k filename-k delete all defined ACLs from a file or File System
-B: Keep the items in the acl unchanged.
15. Use dump to back up data through ssh
#/Sbin/dump-0uan-f-/usr | gzip-2 | ssh-c blowfish targetuser@foo.example.com dd of =/mydatefiles/dump-user-10.gz
16. Use pipelines and rsh to send data to a remote tape drive
# Tar cf-. | rsh hostname dd of = tape-device obs = 20b
17. Use the script command to output the information in the execution or compilation process to a file, which is convenient for querying error information.
# Script/var/tmp/mw. out
18. Check whether the kernel supports Serial Port
# Dmesg | grep 'ci'

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.