Common Linux commands II

Source: Internet
Author: User
Tags disk usage

Common Linux commands (continued)
Renaming and moving music video files
Format:
MV (-parameter) original file target file
MV (-parameter) original directory target directory
MV (-parameter) original file target directory
Parameter description
B. Back up data before moving data.
V shows the movement after moving
F will not ask the user if they want to move (if there is the same file)

Example
* Move passwd to the/home/hongqt/Xiaoyu directory.
[Hongqt @ qq hongqt] $ MV passwd XiaoYu
* Rename passwdinto passwd.txt
[Hongqt @ qq hongqt] $ MV passwd passwd.txt
* Move the/home/hongqt/Xiaoyu directory to the/home/hongqt/OK directory and display the movement.
[Hongqt @ qq hongqt] $ MV-V/home/Xiaoyu // home/hongqt/OK
'Xiaoyu '->' OK/Xiaoyu '==========> prompt information displayed on the screen
* Change the directory name and path of the file
[Hongqt @ qq hongqt] $ mV/home/hongqt/OK/home/hongqt/QQ
* Before moving the passwd file, if the target file exists, back up the target file before moving it.
[Hongqt @ qq hongqt] $ MV-B/home/hongqt/passwd/home/hongqt/QQ (assume that a file with the same name already exists in the QQ directory) when using the LS command in/home/hongqt/QQ, we will see the following two files:
Passwd and passwd ~ . Passwd ~ Is a pre-backup file.

Ln connects to a file
Existing in (-parameter) files or directories to be connected
Parameters:
The S-symbolic links connection method can be used to connect different file systems, or to connect directories, so that one directory has another alias.
Preparations:/home/hongqt/QQ/Xiaoyu/has a file passwd.
The current working directory is/home/hongqt.
* The following command creates a connection file (shortcut) for the file/home/hongqt/QQ/Xiaoyu/passwd and stores it in the current working directory.
Ln-S/home/hongqt/QQ/Xiaoyu/passwd pass
VI pass directly Modifies/home/hongqt/QQ/Xiaoyu/passwd, but if you use the DELETE command
Rm-F pass only deletes the connection file, but does not delete the actual file.

Rm deletes a file or directory
Usage
Rm (-parameter) file or directory
Parameter description
R. Delete all directories, and delete the directories and files under them.
I. the user confirmed the deletion before deleting the directory.
F means that no confirmation is performed during deletion, and no error information is generated. The user is required to confirm whether to delete the operation. However, if option F is available, no confirmation is performed.

Example
* All files except directories and hidden files are deleted. However, you need to confirm the deletion of each file.
[Hongqt @ qq hongqt] $ RM *
* Delete all the directories and files under the Buf and the Buf, without requiring the user to confirm the operation.
[Hongqt @ qq hongqt] $ Rm-RF Buf/

* *** Reading text file commands is incomplete ****
* Cat displays the File Content
CAT (-parameter) (file)
Eg:
Display the content of the/etc/passwd file. If the content cannot be displayed on one screen, use command 2 or command 3 to display the content on one screen.
CAT/etc/passwd -----------------> command 1
CAT/etc/passwd | more ---------------> command 2
More/etc/passwd ------------------> command 3
* Use the cat command to create a file
Cat> OK .txt (use Ctrl + D to end editing) ---- similar to copy con OK .txt in DOS Commands
* Use the cat command to merge two text files
Cat OK .txt test.txt OK .txt
* Use the cat command to append new content to the end of a text file.
Cat> OK .txt
Enter the new content and press Ctrl + D to finish editing.

* Head command
You can use the head command to view the beginning of a text file.
Command Format:
Head <FILENAME>
Head is a useful command, but because it is limited to the first few lines of the file, you cannot see how long the file actually exists. By default, you can only read the first 10 rows of the file. You can change the number of rows to be displayed by specifying a number option, as shown in the following command:
Head-20 <FILENAME>

Tail command
The opposite of the head command is the tail command. Using the tail command, you can view ten lines at the end of the file. This helps you to view the last 10 lines of log files to read important system messages. You can also use tail to observe the log file update process. With the-F option, tail automatically displays new messages in the open file to the screen in real time. For example, to actively observe/var/log/messages, enter the following command at the shell prompt as the root user:
Tail-F/var/log/messages
 
Grep command
The grep command is useful for finding the specified string in the file. For example, if you want to find every place in the passwd file that mentions "hongqt", you can type:
Grep hongqt passwd
You will see each line with "hongqt" in the file.
Hongqt: 500: 500:/home/hongqt:/bin/bash
Therefore, we can use this command to check whether an account exists in the system.

* ******** Instructions on the file system and disk space *********
DF reports disk space remaining
Format:
DF (-parameter)
Common parameter explanation
A lists all the file systems and the disk usage of each partition.
H. display the size of each partition and the size of the mounted file partition.
T. List the file system names of each partition.

Example
* List the disk space usage of each partition. The default value is bytes.
[Root @ qq etc] # DF
Filesystem 1k-blocks used available use % mounted on
/Dev/sda2 3834496 942804 2696904 26%/

[Root @ jkx-Linux ISO] # DF-B m
Filesystem 1m-blocks used available use % mounted on
/Dev/hda2 2950 2022 779 73%/
/Dev/hda1 84 11 69 14%/boot
/Dev/hdb1 6100 453 5338 8%/jkxftp

[Root @ jkx-Linux ISO] # DF-H
Filesystem size used avail use % mounted on
/Dev/hda2 3.1 GB 2.2 GB 816 MB 73%/
/Dev/hda1 88 MB 11 mb 73 MB 14%/boot
/Dev/hdb1 6.4 GB 475 MB 5.6 GB 8%/jkxftp
None 32 MB, 0 32 MB, 0%/dev/SHM
/Dev/hda4 27 Gbit/s 35 Mbit/s 26 Gbit/s 1%/home

* List file system names
[Root @ qq etc] # DF-T
Filesystem type 1k-blocks used available use % mounted on
/Dev/sda2 ext3 3834496 942804 2696904 26%/

Du calculates the total size of all files in the directory (in KB)
[Hongqt @ qq hongqt] $ du/bin
4700/bin

Find
Usage
Find start Directory Search Condition action
Start Directory: default directory
Because this command is very complex, we only give a few typical examples to understand its basic usage.
Example
* Search for all "*. conf" files in the/etc directory.
$ Find/etc-name "*. conf"-print
* Search for all files starting with an uppercase letter in the/etc directory
$ Find/etc-name "[A. Z] *"-print

* In the/home directory, find the file whose owner is hongqt.
$ Find/home-user hongqt
* Search for files with no file owner in the/Home Directory
$ Find/home-nouser
* Find the files in the/home directory whose owner is hongqt.
$ Find/home-group hongqt

Search for files based on the Change Time
* Search for files whose modification time is less than 5 days in/home.
$ Find/home-mtime-5
* Search for files whose modification time is earlier than 3 days in/home.
$ Find/home-mtime + 3

Use the type option
* Find all directories in/home
$ Find/home-type D

** Locate a file
** Whereis: locate a command

* ******* Instructions for viewing system information *********
Change date or view the current time
[Root @ qq root] # date
Sun Nov 16 09:02:13 CST 2003
[Root @ qq root] # date-s "Nov 17"
Mon Nov 17 00:02:00 CST 2003

Cal view calendar
[Root @ qq root] # Cal --> displays the year and month information corresponding to the current system date.
November 2003
Su Mo tu we th fr SA
1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30
[Root @ qq root] # cal-y 2003 shows 2003 calendar year-round
[Root @ qq root] # Cal 3 1974 displays the calendar of March 1974

PS: view the current program execution status
[Root @ qq root] # ps-x | more
PID tty stat Time Command
1? S 0: 05 init [3]
1862 ttyp0 S-Bash
1540? S 0: 00/usr/sbin/vsftpd/etc/vsftpd. conf
[Root @ qq root] # ps-Aux displays processes currently running by all users in the system

Top system status command
Displays the current system resource usage
To view simple information, use the uptime and free commands.

Kill Process Termination command
Common usage
Kill-9 process ID
Killall process name

TIPS: How to exit Linux without leaving traces?
After the user logs on to the system to complete the specified task, use
Kill-9 the process ID corresponding to the Bash used by the user
Additional knowledge: You can use the history command to view your command history and use the up and down cursor arrows to select historical commands you have used. The default value is 500.
Add or modify to/etc/profile
Histsize = 20

Uname: view the core version
Common parameters:
Uname-
[Root @ qq etc] # uname-
Linux QQ 2.4.20-8 #1 Thu Mar 13 17:18:24 est 2003 i686 athlon i386 GNU/Linux
[Root @ qq etc] # uname-R
2.4.20-8

************* ******************

How to use a floppy disk, an optical drive, an USB flash drive, and access a Windows FAT32 partition on Linux
Floppy Disk:
# Mount-T vfat/dev/fd0/mnt/floppy
Detach a floppy disk:
# Umount/dev/fd0

Use the optical drive:
[Root @ qq root] # ls/dev/CDROM-l
Lrwxrwxrwx 1 Root 8 Nov 5/dev/CDROM->/dev/HDC
# Mount-T iso9660/dev/CDROM/mnt/CDROM
# Mount-T iso9660/dev/HDC/mnt/CDROM
Uninstall the optical drive:
# Umount/dev/CDROM

Use USB flash drive:
# Mkdir/mnt/USB
# Mount-T vfat/dev/sda1/mnt/USB
For the virtual Linux system installed on Vmware, refer to help> directory> Search for the USB keyword to find a way to install the USB flash drive on the virtual Linux system.

Access the FAT32 partition of Windows:
# Fdisk/dev/hda
[Root @ qq root] # fdisk/dev/hda

The number of cylinders for this disk is set to 1867.
There is nothing wrong with that, but this is larger than 1024,
And coshould in certain setups cause problems:
1) software that runs at boot time (e.g., old versions of lilo)
2) booting and partitioning software from other OSS
(E.g., DOS fdisk, OS/2 fdisk)

Command (M for help): p

Disk/dev/hda: 15.3 GB, 15364339200 bytes
255 heads, 63 sectors/track, 1867 Cylinders
Units = cylinders of 16065*512 = 8225280 bytes

Device boot start end blocks ID system
/Dev/hda1 1 255 2048256 2D unknown
/Dev/hda2 256 1867 12948390 F Win95 ext 'd (LBA)
/Dev/hda5 256 995 5944018 + 2d unknown
/Dev/hda6 996 1867 7004308 + B Win95 FAT32

# Mkdir/mnt/diske
# Mount-T vfat/dev/hda6/mnt/diske
# Mount-T vfat/dev/hda6-O iocharset = gb2312/mnt/diske (solve the problem of abnormal Chinese Character Display)
(The RedHat 9.0 test fails, but the RedHat 7.2 test fails)

Access NTFS partitions:
The latest kernel provides support for NTFS partitions, but you need to recompile the kernel.
For more information, see: http://linux-ntfs.sourceforge.net/info/ntfs.html

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.