Linux commonly used commands and methods of use

1.# indicates a privileged user (such as root), $ indicates a normal user.
Boot prompt: Login: enter the user name
password: enter the password. The user is a registered user of the system and can enter the corresponding user environment after successfully logging in.
Exit the current shell, enter: exit

2.useradd netseek Add a netseek user
passwd netseek to set a password for the user netseek.
(/etc/passwd /etc/group)
userdel netseek delete the account
userdel -r netseek delete the account and its own directory.
[For more detailed operations, please refer to the man page , And account management]

3. View the command
ls -l to display the file list
ls -al -a to display all files and directories (ls defaults to regard file names or directory names beginning with "." as hidden files and will not be listed)
ls -al |grep '^d' Display the directory
ls -al |grep' [ d]' Query all files in a directory that do not contain the directory
ls -sh (man ls see man help.)

Linux several file types:
d means this file is a directory

  • Indicates that this file is an ordinary file
    b Indicates that this file is a special block device I/O file
    c Indicates that this file is a special character device I/O file
    l Indicates that this file is a connection file. The file name is followed by the path and name of the file connected to it

The file command determines the file type by detecting the content of the file

4. Create files and directories
touch 1.txt
cat> 2.txt (use the directional character to create a file, fill in the content, press ctrl+d to save the content)
mkdir mywork create the mywork directory

5. Copy file or directory
cp filename1 filename2
cp -r dir1 dir2 copy directory
cp -rf parameter f is to delete the existing target file without prompting
cp -i parameter i and f, on the contrary, prompts will be given before overwriting the target file The user confirms that the target file will be overwritten when answering y, which is an interactive copy.

6.Delete files and directories (delete files or directories can be done with rm)
rm 1.c //Delete the file 1.c
rm -rf (Forcibly delete files or directories, do not prompt when deleting.)

7. Remove the directory or change the file name
mv [opitons] source file or directory target file or directory
[options] main parameter
-i: interactive mode operation, if the mv operation will lead to the overwriting of the existing target file, the system Ask whether to rewrite, ask the user to answer "y" or "n",
so as to avoid overwriting files by mistake.
-f: Disable interactive operations. When the mv operation wants to overwrite an existing target file, no instructions are given. After this parameter is specified, the i parameter will no longer work.
mv hello …/ Move the hello directory or file to the upper level.

8.alias alias
alias dir='ls -l' Enter dir, which is actually equivalent to executing ls -l

9. Permission control (rwx 421)
chmod +x hello.sh assigns executable permissions.
(Details about permissions control)
chmod command permission modification usage: chmod an octal number filename (rwx 421)
 eg: chmod u+x filenmame just want to run it, others can only read
chown netseek.netseek mydir change user group

u: Indicates the file owner
g: Indicates users in the same group
o: Indicates other users
a: Indicates that all users
opt is a representative operation, which can be:
+: add a certain permission
-: cancel a certain permission
=: give a given permission , And cancel the original permissions,
while mode represents permissions:
r: readable 4
w: writable 2
x: executable 1

10.pwd Display the full path of the current directory and change the directory
cd netseek enter the netseek directory
cd exit the current directory
cd …/ enter the upper directory.

cd-return to the last directory
cd ~ return to the main directory

  1. The cat,more,less command
    displays the content of a file. The difference between the two commands is that cat prints the content of the file all the time, while more displays the content of the file.
    Less can scroll up and down to view the content.
    cat> 1.txt is OK Fill in or copy the content, press ctrl+d to save
    cat 1.c
    more 1.c
    head -n filename display the content of the Nth line
    tail -n filename display the content of the last N line
    tail -n 20 /var/log/message display the latest 20 lines of log

12. Set the Linux time and date
date command ("date MMDDhhmmYYYY.ss")
July 24, 2006 12:37, 30 seconds
date 072412372006.30
date -s 20:30:30 #Set the system time to 20: 30:30
date -s 2006-7-24 #Set the system period to 2006-7-24
clock -r #Read the time parameter in the system Bios
clock -w #Write the system time (such as the time set by date) into Bios

13. View and find files
Several introductions:
find path-name file name

find /etc -name named.conf

locate is a tool for searching files by file name (you must first create an index database through updatedb)
localte named.conf
whereis is to find binary files, and also find its help file
which is similar to where, but is set in the environment variables we set Find in the path; for example;

14. Check and kill the process
ps aux
ps -ef |grep
kill -9 to
see which process occupies the largest memory
ps -aux|sort +5n

Put the program in the front and background to execute
cp file1 file2 &
& and ctrl+z You can use & or ctrl+z to execute the command in the background.
fg is to put the program that is executed in the background back to the foreground.
jobs

15.dd command backup
dd if="input_file" of="out_file" bs="block_size" count="number"
Parameter:
if: is the input file can be the device
of: is the output file can also be the device
bs: planned one The size of the block, if it is not set, the default is 512bytes
count: how many bs means.

dd if=/etc/password of=/tmp/passwd.bak 备份

16.mount to load a hardware device
  Usage: mount [parameter] Mount point of the device to be loaded
  eg: mount /dev/cdrom
  cd /mnt/cdrom //Enter the CD directory
U disk:
mkdir /mnt/usb; (Note: create Mount directory)
mount /mnt/sda1 /mnt/usb; (Note: mount the USB flash drive)
Now you can use the USB flash drive, the content in the /mnt/usb directory is the content in the USB flash drive;
after use , Use the following command to uninstall the U disk.
umount /mnt/usb
mount List all partitions of the system
mount -t iso9660 /dev/cdrom /mnt/cdrom mount CD-ROM
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: Moved to http ://www.linux-ntfs.org/Moved to http://www.linux-ntfs.org/
umount /mnt/hda3 Unmount
Note: Before mounting the device, please take a look at fdisk -l.

17.su switch to another identity without logging out.
Usage: su -l username (if the username is default, switch to root state)
  eg: su -l netseek (switch to netseek this user, change (Prompt for password), plus-means switch to the user's environment variable.

sudo uses his permission to execute root execution

18.whoami,id,w,lastlog,users,groups
w View user login information
who View current login user
last last month user login status
lastlog Check the last login time of a specific user, and format the last login log/ The content of var/log/lastlog
whoami confirms his identity.
id prints out his UID and GID. (UID: unique user identity identification. GID: unique user group identity identification. Each user can only have a unique UID and GID. )
users
groups query the user group to which the user belongs;
finger -l netseek root
finger -s or direct finger
can let the user query the data of some other users
  eg: finger //View the usage data of the user used
  finger root //View root data of

19. The commands used by the user and the commands executed in the execution history
history show the commands used by the user in the past
!! Execute the most recent command

20.uname View linux system information
Parameters: -a all information -r version number -n host name

21. Establish a soft connection
ln [-sf] source target

ln souce-file hard-link

ln -sf source-file soft-link
s means soft link, f means that if there is a file with the same name, it will be overwritten.
Note: Hard links cannot be created for directories, only files can create hard links.

22. View the directory
du -sh directory or file
du -m The default output of the system is KB, and the parameter -m is displayed in MB.
cat /etc/fstab View the partition list
fdisk -l
df -h
df -ah

23. View the resources occupied by the linux system (top, free, uptime)
top View background programs, monitor system performance
top -d 2 List a new one every two seconds
top -d -2 -p3690 View a certain PID
top -b -n 2 >/tmp/top.txt Carry out top information twice, and then output the result to /tmp/top.txt

free -m View system memory usage

uptime displays the current system boot time (check how long it was booted, how many people logged in, and the system load in the past 1,5,15 minutes)

24. File ratio software:
cmp cmp (abbreviation of "compare") command is used to briefly indicate whether there are differences between two files, and its use authority is all users

diff The diff command is used to compare two files, and point out the difference between the two, and its use authority is all users

25. Remote operation and file transfer
ssh [email protected]
scp [email protected]:/remote/path /local/path
scp /local/path [email protected]:/remote/path

26. Compile the c/c++ file
gcc
gcc -v View the GCC version
gcc -o test test.c 2>errfile If there is an error message when compiling test.c, the error message will be redirected to errfile

27. chattr +i filename prohibits deleting, chattr -i filename cancels prohibiting
lsattr from viewing hidden file attributes

28. Automated execution
at Execute
crontab once and execute the program crontab periodically.
Introduction
1 Log in as root
2 # crontab -e
3 Add a line
1 */12 * * * /usr/sbin/ntpdate http://pool.ntp.org
minutes ( 0-59)
hour (0-23)
date (1-31)

Month (1-12)

Week (0-6) //0 means Sunday

29. Shutdown and restart:
shutwond [-t seconds] [-rkhncff] time [warning information]
-t seconds: set the delay time (seconds) between warning and deleting the signal before switching to a different runlevel
-k issues a warning message, but it is not really necessary to shut down
-r shutdown and reboot
-h shutdown and reboot
-n does not go through init, the shutdown command itself does the boot work (not recommended)
-f when rebooting , Skip the fsck command and do not check the file system.
-F When restarting, force a fsck check.
-c Cancel the
shutdown action already in progress -h now Shut down immediately, where now is equivalent to time 0,halt,poweroff also You can shut down, or directly init 0
shutdown -h 20:30 The system will be shut down at 8:30 tonight
shutdown -h +10 The system will automatically shut down after another ten minutes.
shutdown -t3 -r now reboot immediately, but the warning And delete the process,
shutdown -k now'Hey! Go away! now...' issued a warning message, but did not actually shut down.

reboot:
shutdown -r now is almost the same as reboot, it is recommended to use reboot as follows: shutdown -r +
30'The system wiil reboot'
shutdown -r + 10'Hey !Go away!' The system will restart after 10 minutes.
#sync ; sync; sync; reboot Note: sync writes data synchronously to the hard disk. The
halt command is equivalent to shutdown -h now, which means to shut down immediately.

The reboot command is equivalent to shutown -r now, which means to reboot immediately.

30. How to change the operating level of the startup mode
vi /etc/inittab
change 5 to 3, and it can become character mode after startup.
Startx or init 5 can enter the graphical interface.
runlevel displays the current run level

How to switch to single-user mode
Use telinit or init (in fact, telinit is just a synbol link to init)
telinit 1 or init S, of course telinit S is also possible.

How to disable the ctrl+alt+del three-key #vi
/etc/inittab
add a comment # before ca::ctrlaltdel:/sbin/shutdonw -t3 -r now
and execute #telinit q, the parameter q is to restart telinit Check /etc/inittab once

31. TAB Use the tab key cleverly. When you don't know the full name of a file or command, please press the tab key twice.

32.clear clear screen

33.dmesg |more Display boot information (check hardware information when the system starts)

34. Change the excellent level of program execution.
Set the priority nice -n -5 vi & use root to give a nice value of -5 to execute vi
renice to adjust the existing priority

35. Module related commands

lsmod displays the modules that have been loaded into the system

depmod analyzes the dependency of the loadable system
modinfo displays the information of the kernel module
insmod loads the module
modprobe automatically processes the loadable module
rmmod deletes the module

36. chkconfig --list shows the status of various services, using chkconfig can easily manage init scripts.

37. Several decompression commands
of linux
compress aaa compress aaa files into aaa.Z compress -d aaa.z compress aaa.z files into aaa

gzip aaa compression command
gzip -d aaa.gz decompression command

bzip2 -z filename compression, as above, add -d parameter to decompress
bzcat filename.bz to view the contents of the compressed file

tar czvf aaa.tar.gz aaa Compress the directory aaa into aaa.tar.gz
tar -N '2007/03/01' -zcvf home.tar.gz /home in /home, newer than 2007/03/01 Only files are backed up.
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-
Unpack /etc/ 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 Unzip aaa.tar.gz to the /var/www directory

cpio -covB> [file|device] backup
cpio -icduv <[file|device] restore

38. The network command
ifconfig displays or sets the network device, you can view the current ip, similar to the ipconfig
service network restart in windows (/etc/rc.d/init.d/network restart) restart the network card
ifdown eth0 close the network card
ifup eth0 open the network card
route -n View routing table
route add -net 192.168.20.1 netmask 255.255.255.0 dev eth0

netstat view network connection status
netstat -i display network card operation status
netstat -r view host routing list

traceroute

hostname displays the host name
hostname -i displays the IP of the current host name.

39. System integration management menu.
setup system service management command
ntsysv set system service

40.fdisk /mbr delete GRUB

41. 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.

启动Oracle
su - oracle
$lsnrctl stop
$lsnrctl start
sqlplus /nolog
conn /as sysdba(connected)
startup

42. Install the package
rpm package installation:
rpm -ivh xxx.rpm Install the rpm package
rpm -qa --last | less Display the installed packages according to the installation date
rpm -qa |grep mysql -i Query whether the system is installed with the mysql package (- i, ignoring case)
rpm -e delete the installed software package
rpm -e mysql* --nodpes force delete the related software package
rpm --test test installation
rpm -qi query mysql package description data
rpm -qpl xxx.rpm view The contents of the rpm package.
rpm -qc[d] Configuration file and help file
rpm -Uvh Upgrade installation
rpmbuild --bb SPECS/xxx.spec Reinstall and compile xxx.spec into rpm package.

rpmbuild --rebuild packagename.src.rpm Recompile .src.rpm into rpm package.

Source code compilation and installation (classic)
./configure Check system information (./configure --help | more help information, you can see related parameter settings)
make clean clear the files left before
make compile
make install install

Guess you like

Origin blog.csdn.net/qq_44944641/article/details/104466977