Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

What are the common commands and usage of Linux?

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >

Share

Shulou(Shulou.com)06/02 Report--

This article introduces what are the common commands and usage of Linux, the content is very detailed, interested friends can refer to it, I hope it can be helpful to you.

1.# indicates the authorized user (such as root), and $represents the ordinary user

Boot prompt: Login: enter user name

Password: the user who enters the password is the registered user of the system who can enter the corresponding user environment after successfully logging in.

Exit the current shell and enter: exit

2.useradd netseek add a netseek user

Passwd netseek sets the password for the user netseek.

(/ etc/passwd / etc/group)

Userdel netseek deletes an account

Userdel-r netseek deletes the account along with its own directory.

[for more details, please see man page, and account Management]

3. View command

Ls-l displays a list of files

Ls-al-a displays all files and directories (ls internally starts the file name or directory name with "." As a hidden file and will not be listed)

Ls-al | grep'^ d' display directory

Ls-al | grep'^ [^ d] 'queries all files in a directory that do not contain directories

Ls-sh (man ls views man help)

Several file types of linux:

D indicates that this file is a directory

-indicates that this file is a normal file

B indicates that this file is a special block device Imax O file.

C indicates that this file is a special character device Igamo file.

L indicates that this file is a connection file. Its file name is followed by the path and name of the file to which it is connected

The file command determines the file type by probing the contents of the file

4. Create files and directories

Touch 1.txt

Cat > 2.txt (create a file with an orientator, fill in the content, and then press ctrl+d to save the content)

Mkdir mywork set up the mywork directory

5. Copy a file or directory

Cp filename1 filename2

Cp-r dir1 dir2 replication directory

The cp-rf parameter f deletes the existing target file without prompting

On the contrary, cp-I parameters I and f will prompt the user to confirm before overwriting the target file, and when answering y, the target file will be overwritten and is an interactive copy.

6. Delete files and directories (delete files or directories can be done with rm)

Rm 1.c / / delete the 1.c file

Rm-rf (forcibly delete a file or directory, without prompting when deleting.)

7. Remove the directory or change the file name

Mv [opitons] Source file or directory destination file or directory

[options] main parameters

-I: interactive operation, if the mv operation will lead to an overwrite of the existing target file, the system asks whether to rewrite and requires the user to answer "y" or "n", so as to avoid mistakenly overwriting the file.

-f: interoperability is prohibited. The mv operation does not give any indication when it wants to overwrite an existing target file, and the I parameter will no longer work when this parameter is specified.

Mv hello.. / move the hello directory or file to the next level.

8.alias alias

Entering dir in alias dir='ls-l' is actually equivalent to executing ls-l.

9. Control of permissions (rwx 421)

Chmod + x hello.sh is assigned executable permissions.

(describe the control of permissions in detail)

Chmod command permission modification usage: chmod one-digit octal number filename (rwx 421)

Eg: chmod Ubunx filenmame only wants to run it for itself, others can only read it

Chown netseek.netseek mydir changes user affiliation group

U: indicates the owner of the file

G: indicates the same group of users

O: indicates other users

A: represents all users

Opt represents the operation, which can be:

+: add a permission

-: cancel a permission

=: give the given permission and cancel the original permission

Mode represents permissions:

R: readable 4

W: writable 2

X: executable 1

10.pwd displays the full path of the current directory and changes the directory

Cd netseek enters the netseek directory

Cd exits the current directory

Cd.. / enter the directory above.

Cd-returns to the previous directory

Cd ~ return to the home directory

11. Cat,more,less command

To display the contents of a file, the difference between the two commands is that cat prints the contents of the file all the time, while more displays it separately.

Less can scroll up and down to view the content.

Cat > 1.txt can be filled in or copied, and press ctrl+d to save

Cat 1.c

More 1.c

Head-n filename displays the contents of line N

The contents of the N lines after tail-n filename display

Tail-n 20 / var/log/message displays the latest 20 lines of log

twelve。 Set linux time and date

Date command ("date MMDDhhmmYYYY.ss")

12:37, July 24th, 2006, 30 seconds

Date 072412372006.30

Date-s 20:30:30 # set the system time to 20:30:30

Date-s 2006-7-24 # sets the system period to 2006-7-24

Clock-r # reads time parameters in system Bios

Clock-w # writes the system time (such as the time set by date) to Bios

13. Check to find files (find,grep,awk for more information, please refer to the man page or shell programming topic explanation

Several introductions:

Find path-name file name

Find / etc-name named.conf

A tool for locate to search for files by file name (to build an index database through updatedb first)

Localte named.conf

Whereis is looking for binaries and will also find its help files

Which is similar to where, except that it is found in the set path in the environment variable we set; for example

14. Investigation and killing process

Ps aux

Ps-ef | grep

Kill-9

See which process takes up the most memory.

Ps-aux | sort + 5n

Put the program in the foreground and background.

Cp file1 file2 &

& with ctrl+z you can use & or ctrl+z to execute commands in the background.

Fg is to put the program executed in the background and back to the foreground.

Jobs

15.dd command backup

Dd if= "input_file" of= "out_file" bs= "block_size" count= "number"

Parameters:

If: that is, input file can be a device

Of: even an output file can be a device

Bs: the size of a planned block. If not set, the default is 512bytes.

Count: how many bs means.

Dd if=/etc/password of=/tmp/passwd.bak backup

16.mount loads a hardware device

Usage: mount [parameter] device load point to be loaded

Eg: mount / dev/cdrom

Cd / mnt/cdrom / / enter the CD directory

U disk:

Mkdir / mnt/usb; (Note: create a mount directory)

Mount / mnt/sda1 / mnt/usb; (Note: mounting a flash drive)

You can use the flash drive now. The contents in the / mnt/usb directory are the contents of the flash drive.

After using it, uninstall the USB disk with the following command.

Umount / mnt/usb

Mount lists all the partitions of the system

Mount-t iso9660 / dev/cdrom / mnt/cdrom mount CD

Mount-t vfat / dev/fd0 / mnt/floppy mount floppy disk

Mount-t vfat-o iocharset=utf8,umask=000 / dev/hda2 / mnt/hda2 mount fat32 partition

Mount-t ntfs-o nls=utf8,umask=000 / dev/hda3 / mnt/hda3 mount ntfs partition

Linux-NTFS Project: http://linux-ntfs.sourceforge.net/

Umount / mnt/hda3 load

Note: please take a look at fdisk-l before mounting the equipment.

17.su switches to another identity without logging out.

Usage: su-l user name (if the user name defaults, switch to root status)

Eg:su-l netseek (switch to the user netseek and will be prompted for a password), plus-to indicate the switch to the user's environment variable.

Sudo takes advantage of his authority to execute root execution

18.whoami,id,w,lastlog,users,groups

W View user login information

Who to view current login users

Login status of last users in the last month

Lastlog checks when a particular user last logged in and formats the contents of the last login log / var/log/lastlog

Whoami confirms his identity.

Id prints out its own UID and GID. (UID: user identity unique ID. GID: user group identity unique ID. Each user can only have a unique UID and GID.)

Users

Query the user group to which the groups user belongs

Finger-l netseek root

Finger-s or direct finger

It allows users to query the data of other users.

Eg: finger / / View the usage information of the users you are using

Finger root / / View the data of root

19. Commands used by the user and commands executed by the execution history

History displays commands that the user has used in the past

!! Execute the most recent order

20.uname View linux system Information

Parameter:-an all information-r version number-n hostname

21. Establish a soft connection

Ln [- sf] source target

Ln souce-file hard-link

Ln-sf source-file soft-link

S for soft connection and f for overwriting if there is a file with the same name.

Note: hard links cannot be created for directories, only files can create hard links.

twenty-two。 View the catalog

Du-sh directory or file

The default output of the du-m du system is KB, and the parameter-m is displayed as MB.

Cat / etc/fstab View Partition list

Fdisk-l

Df-h

Df-ah

23. View the resources consumed by the linux system (top,free,uptime)

Top views daemons and monitors system performance

Top-d 2 new column every two seconds

Top-d-2-p3690 View a PID

Top-b-N2 > / tmp/top.txt carries out the information of top twice, and then outputs the result to / tmp/top.txt

Free-m to view system memory usage

Uptime shows the current boot time of the system (check how long it takes, how many people have logged in, and the load of the system for 15 minutes in the past)

24. File comparison software:

The cmp cmp (abbreviation for "compare") command is used to briefly indicate whether there is a difference between the two files, and its permission is for all users.

The diff diff command is used to compare two files and points out that the difference between the two is that it has the right to use all users

25. Remote operation and file transfer

Ssh user@remote.machine

Scp user@remote.machine:/remote/path / local/path

Scp / local/path user@remote.machine:/remote/path

twenty-six。 Compile the cripple + file

Gcc

Gcc-v View GCC version

Gcc-o test test.c 2 > errfile redirects the error message to errfile when compiling test.c

27.chattr + I filename forbids deletion, chattr-I filename cancels prohibition

Lsattr view hidden file properties

twenty-eight。 Automatic execution

At executes once

Crontab timing loop execution program

Crontab introduction

1 Log in as root

2 # crontab-e

3 add a line

1 * / 12 * / usr/sbin/ntpdate pool.ntp.org

Minutes (0-59)

Hour (0-23)

Daily period (1-31)

Month (1-12)

The week (0-6) / / 0 represents Sunday

twenty-nine。 Shutdown and restart:

Shutwond [- t seconds] [- rkhncff] time [warning]

-t seconds: sets the delay time between warning and deleting signals before switching to a different runlevel (seconds)

-k sends out a warning message, but does not really want to shutdown

-r shutdown reboot after this

-h shutdown power on after this

-n without going through init, boot is done by the shutdown command itself (not recommended)

When rebooting, skip the fsck instruction and do not check the file system.

-F force a fsck check when rebooting.

-c cancel the actions that are already in shutdown

Shutdown-h now shuts down immediately, in which now equals to 0. Now can also be turned off, or directly init 0.

The shutdown-h 20:30 system will shut down at 8:30 tonight.

The shutdown-h + 10 system shuts down automatically in ten minutes.

Shutdown-T3-r now reboots immediately, but when warning and deleting processes

Shutdown-k now 'Hey! Go away! now...' Issued a warning message but didn't really turn it off.

Reboot:

Shutdown-r now is almost the same as reboot, and it is recommended to use reboot as follows:

Shutdown-r + 30 'The system wiil reboot'

Shutdown-r + 10 'Heyweight go awayworthy' 10 minutes after the system restart.

# sync; sync; sync; reboot Note: sync writes data synchronously to the hard disk

The halt command is equivalent to shutdown-h now, which means shutdown immediately.

The reboot command is equivalent to shutown-r now and means to start again immediately.

thirty。 How to change the running level of startup mode

Vi / etc/inittab

Change 5 to 3, which can be changed into character mode after startup.

Startx or init 5 can enter the graphical interface.

Runlevel displays the current runlevel

How to switch to single user mode

Using telinit or init (actually telinit is just a synbol link to init)

Telinit 1 or init S is fine, and so is telinit S.

How to invalidate the triple bond of ctrl+alt+del

# vi / etc/inittab

Add a comment # before ca::ctrlaltdel:/sbin/shutdonw-T3-r now

Then execute # telinit Q, and the parameter Q is for telinit to check / etc/inittab again.

31.TAB uses the tab key skillfully. Press the tab key twice in a row when you don't know the full name of the file or command.

32.clear screen cleaning

33.dmesg | more displays boot information (view hardware information when the system starts)

thirty-four。 Change the excellent level of program execution

Nice sets priority nice-n-5 vi & use root to give a nice value of-5 to execute vi

Priority already exists for renice adjustment

thirty-five。 Module-related commands

Lsmod shows the modules that have been loaded into the system

Depmod Analysis of the dependence of loadable system

Modinfo displays information about the kernel module

Insmod load module

Modprobe automatic processing loadable module

Rmmod delete module

36.chkconfig-list displays the status of various services, and chkconfig allows you to easily manage init scripts.

Several decompression commands of 37.linux

Compress aaa compresses the aaa file into aaa.Z

Compress-d aaa.z compresses aaa.z files into aaa

Gzip aaa Compression Command

Gzip-d aaa.gz decompression command

Bzip2-z filename compression, decompression with-d parameter as above

Bzcat filename.bz to view the contents of a compressed file

Tar czvf aaa.tar.gz aaa compresses the directory aaa into aaa.tar.gz

Tar-N '2007 zcvf home.tar.gz 01'-zcvf home.tar.gz / home in / home, new files are backed up than 2007-03-01.

Tar-- exclude / home/cao-zxvf myfile.tar.gz / home/* / etc to back up / home,/etc, but not / home/cao

Cd / tmp; tar-cvf-/ etc | tar-xvf-package / etc/ and unpack it directly under / tmp without generating files.

Tar zxvf aaa.tar.gz decompression command.

Tar jxvf aaa.tar.bz2 decompression command

Tar zxvf aaa.tar.gz-C / var/www unzips aaa.tar.gz to the / var/www directory

Cpio-covB > [file | device] backup

Cpio-icduv < [file | device] restore

thirty-eight。 Network command

Ifconfig displays or sets network devices. You can view the current ip, which is similar to ipconfig in windows.

Service network restart (/ etc/rc.d/init.d/network restart) restart the network card

Ifdown eth0 shuts down the network card

Ifup eth0 opens the network card.

Route-n View routing tabl

Route add-net 192.168.20.1 netmask 255.255.255.0 dev eth0

Netstat to check network connection

Netstat-I shows the operation of the network card

Netstat-r view the route list of the host

Traceroute

Hostname displays hostname

Hostname-I displays the IP of the current hostname.

thirty-nine。 System integration management menu.

Setup system Service Management Command

Ntsysv setup system Service

40.fdisk / mbr delete GRUB

forty-one。 Database startup

Start mysql:

Service mysqld start (/ etc/rc.d/init.d/mysqld start)

Mysql-uroot-p enter the password to operate the mysql database.

Start Oracle

Su-oracle

$lsnrctl stop

$lsnrctl start

Sqlplus / nolog

Conn / as sysdba (connected)

Startup

forty-two。 Install the package

Rpm package installation:

Rpm-ivh xxx.rpm install RPM package

Rpm-qa-- last | less displays installed packages based on installation date

Rpm-qa | grep mysql-I query whether the system installs mysql packages (- I, ignore case)

Rpm-e removes installed software packages

Rpm-e mysql*-- nodpes forcibly removes related software packages

Rpm-- test test installation

Rpm-qi query mysql package description

Rpm-qpl xxx.rpm to view the contents of the rpm package.

Rpm-qc [d] profile and description file

Rpm-Uvh upgrade installation

Rpmbuild-- bb SPECS/xxx.spec reinstalls the xxx.spec to compile the rpm package.

Rpmbuild-- rebuild packagename.src.rpm recompiles .src.rpm into a rpm package.

Source code compilation and installation (classic)

. / configure check system information (. / configure-- help | more help information, you can see the relevant parameter settings)

Make clean erases the files left before.

Make compilation

Make install installation

Note: when installing the source code package, generally decompress the files first. The installation process is roughly a few steps above. Specify the general opinion and press the directory (INSTALL,READEME description.)

About Linux commonly used commands and how to use what is shared here, I hope that the above content can be of some help to you, can learn more knowledge. If you think the article is good, you can share it for more people to see.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Internet Technology

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report