Mac terminal command Daquan

OSX file system

The UNIX file system used by OSX, all files are hung in directory / below, so they don’t have the disk concept under Windows.

The hard drive you see on the desktop is hanging under / Volumes.

For example, a mobile hard disk called USBHD, a hard disk icon is displayed on the desktop, where is it actually?

Execute LS / Volumes / USBHD in the terminal to see what is displayed is not this mobile hard disk.

The root directory location is / core MACH_KERNEL is here,

Drive location / SYSTME / LIBRARY / EXTENSIONS

User folder location / user / username

Desktop location / user / username / desktop

File wildcard is an asterisk *

Note: A.txt is not equal to A.TXT in the UNIX system.

The root directory logo / is not available, CD / System expresses to the System in the directory, and the CD System represents the SYSTEM in the current directory.

———————————————-

How to enter the command line mode

Under the reproduction graphical interface, open the application “utility” terminal with finder

If the graphical interface can’t enter (such as an error display driver), press F8 when boot, start with the -s parameter, then enter the command mount -uw /

Get permissions

In order to prevent malignancy failure systems, no permission operating system is important files when the user state, so you have to get root permissions.

Sudo -s

Then enter the password, when entering the password, there is no return, and the interposer is not, only the carriage return is lost.

———————————————-

Basic order

List of files

LS parameter directory name

Example: I want to see what I have, what is the directory?

LS /

Want to see what happens in the drive directory.

LS / System / Library / Extensions

Parameter -w Displays Chinese, -L Details, -a includes hidden files

Convert directory

CD

Example: I want to get a circle in the driver directory

CD / system / library / extensions

Establish a new directory

Mkdir directory name

Example: Built a backup directory backup in the driver directory

MKDIR / System / library / extensions / backup

Built a backup directory on the desktop Backup

MKDIR / USER / User Name / Desktop / Backup

Copy file

CP parameter source file target file

Example: I want to copy the Natit.kext of the desktop to the driver directory.

CP -R / User / User Name /Desktop/natit.kext / System / Library / Extensions

The parameter R indicates that the directory is recursively, and Kext looks a file in the graphical interface, which is actually a folder.

Back up all files under the drive directory to desktop backup

Cp -R / system / library / extensions / * / user / username / desktop / backup

Delete Files

RM parameter file

Example: I want to delete the driver cache

Rm -rf /system/library/extensions.kextcache

Rm -rf /system/library/extensions.mkext

Parameters -RF represents recursive and mandatory, must be careful, if the RM -RF / your system is executed

Mobile file

MV file

Example: I want to move Applehda.kext to the desktop

MV /SYSTEM/LIBRARY /EXTENSITIONS/applehda.kext / user / username / desktop

I want to move Applehda.kext into the backup directory.

MV /SYSTEM/LIBRARY /EXTENSITIONS/Applehda.kext / System / Library / Extensions / Backup

Change file permissions

Chmod parameter authority file

Example: Set all the files in the drive directory to root read and write, other users read only

CHMOD -R 755 / System / library / extensions

Parameter r is represented, 755 represents the authority of each user to change the file owner

Chown parameter user: Group file

Example: Transform all files in the drive directory into root users

Chown -r root: Wheel / System / Library / Extensions

Parameter R Represents recursive operation

Repair permissions for files in the entire system

Diskutil RepairPermissions /

Strictly said that this is not a UNIX command, but an OSX software, remember to modify or add the driver to execute it.

Text Editor

Nano file name

Example: Edit Natit Info.plist

Nano /system/library/extensions/natit.kext/info.plist

After the editing is completed, use Ctrl + O store, Ctrl + X exit

Another text editing software is VI, the operation is a certain weird, familiar is very easy to use, and it is not afraid in all the Unix systems.

Run the script command

SH script file name

Example Modify all the required operations after the driver stores a script, after modifying the driver, just run this script, convenient

1. Running nano / clean in the terminal

2. Paste the following code into nano

Rm -rf /system/library/extensions.kextcache

Rm -rf /system/library/extensions.mkext

Chown -r root: Wheel / System / Library / Extensions

CHMOD -R 755 / System / library / extensions

Diskutil RepairPermissions /

Kextcache -k / system / library / extensions /

3. CTRL + O storage, Ctrl + X exits

4. As long as the drive is driven, it is running a SH / CLEAN in the terminal.

————————————

Tips

Automatoth command with TAB keys

For example, if you want to go in the / system directory, enter CD / Sy and press the Tab key, the command will automatically replenish the CD / SYSTEM

Operation with files and directories with spaces in the name

Space is written in a space in the command, for example, to enter my documents, command to cd my documents

See the detailed help of the command

MAN command name

For example, look at the detailed usage of the LS command, perform Man LS

————————————

Typical operational process

(Suppose you have made a cleaning script, remember to get system permissions before each operation)

Assume that a graphics card driver Natit.zip is downloaded, and I get a natit.kext on the desktop. How to do it?

For the sake of insurance, let all drive back up all the drive back

MKDIR / USER / User Name / Desktop / Backup creates a backup folder on your desktop

CP -R / System / library / extensions / * / user / username / desktop / backup backup driver file

I can install peace now.

CP -R / USER / User Name /Desktop/natit.kext / System / Library / Extensions Copy it to the system driver directory location

SH / CLEAN performs cleanup scripts, the operation is complete

Replay the failure, can’t go to the desktop, I found that I should not safely drive, how to recover?

Press F8 to boot, start with -s parameter

Implement mount -uw /

RM -RF / USER / User Name /Desktop/natit.kext Deletes this driver

SH / CLEAN performs cleanup scripts, the operation is complete

Restart, return to the original state, don’t die, there is no special effects, I heard that I need to modify the Natit’s info. PLIST file is only line, ok, come back

CP -R / USER / User Name /Desktop/natit.kext / System / Library / Extensions Copy it to the system driver directory location

Nano /System/Library/extensions/natit.kext/info.pl p ´æ ´æ ´æ, Ctrl + X exit with Ctrl + O

SH / CLEAN performs cleanup scripts, the operation is complete

Restart, this is right, the graphics card special effects have, the sound card, the sky knows what will, you have to protect the existing results.

MKDIR / USER / User Name / Desktop / GoodDrivers are designed for effective driver

Cp -r /system/library/extensions/natit.kext / user / username / Desktop / GoodDrivers backup

This sound card requires applehda.kext to delete and edit the Info.plist file in AppleAzaliaAudio.kext, who knows that I will use Applehda in the future, it is better to temporarily disable it.

MKDIR / System / library / extensions / disabled establishes a disabled directory

MV /SYSTEM/LIBRARY /EXTENSITIONS/applehda.kext / system / library / extensions / disabled mobile past

Nano /system/library/extensions/natit.kext/appleazaliaaudio.kext/info.plist

After the editing is completed, use Ctrl + O store, Ctrl + X exit

SH / CLEAN performs cleanup scripts, the operation is complete

Successful, also put a modified driver backup

Copy content to the clipboard code:

The following is a unix command line for reference.

Directory operation

Command name

Function description

Use

Mkdir

Create a directory

Mkdir Dirname

RMDir

Delete a directory

Rmdir Dirname

Mvdir

Move or rename a directory

Mvdir Dir1 Dir2

CD

Change the current directory

CD DIRNAME

PWD

Display the path name of the current directory

PWD

LS

Show the contents of the current directory

LS -LA

Dircmp

Compare the contents of two directories

Dircmp Dir1 Dir2

File operation

Command name

Function description

Use

Cat

Display or connect files

Cat filename

PG

Page format display file content

PG filename

More

Split screen display file content

More filename

OD

Display content of non-text files

OD-C FileName

CP

Copy file or directory

CP file1 file2

RM

Delete files or directories

RM FileName

MV

Change the file name or the directory

MV file1 file2

ln

Join file

ln -s file1 file2

Find

Find files with matching expressions

Find. -Name “* .c” -print

File

Display file type

File filename

Select operation

Command name

Function description

Use

HEAD

The first few lines showing the file

HEAD-20 FileName

TAIL

The last few lines of displaying files

TAIL-15 filename

CUT

Display some fields in each row

Cut -f1 ,7 -d: / etc / passwd

COLRM

Remove several columns from standard input

COLRM 8 20 file2

Paste

Landscape connection file

Paste file1 file2

DIFF

Compare and display the differences in two files

DIFF file1 file2

Sed

Non-interactive mode stream editor

SED “S / Red / Green / G” FileName

GREP

Find in the file

GREP “^ [A-ZA-Z]” FileName

awk

Find and process mode in the file

awk ‘{Print $ 1 $ 1}’ FileName

sort

Sort or merge file

sort -d -f -u file1

Uniq

Remove the repeated line of the file

Uniq file1 file2

COMM

Show the public and non-public lines of two ordered files

Comm file1 file2

WC

The number of characters, words, and number of rows of statistics documents

WC FileName

NL

Add a line number to the file

NL File1> file2

Safe operation

Command name

Function description

Use

Passwd

Modify user password

Passwd

chmod

Change the permissions of the file or directory

CHMOD UG + X FileName

Umask

Define permission masks for creation files

Umask 027

Chown

Change the owner of the file or directory

Chown newowner filename

chgrp

Change the group of files or directories

Chgrp Staff FileName

xlock

Lock to the terminal

Xlock -Remote

Program operation

Command name

Function description

Use

Make

Maintain the latest version of the executable program

Make

Touch

Update file access and modification time

Touch -m 05202400 filename

DBX

Command line interface debugging tool

DBX A.out

xde

Graphical user interface debugging tool

XDE A.out

Process operation

Command name

Function description

Use

PS

Display process current status

PS U

Kill

Termination process

KILL -9 30142

Nice

Change the priority of the command to be executed

Nice cc -c * .c

renice

Change the priority of the running process

Renice +20 32768

Time operation

Command name

Function description

Use

date

Display the current date and time of the system

date

Cal

Show calendar

Cal 8 1996

Time

Execution time of the statistical program

Time a.out

Network and communication operation

Command name

Function description

Use

Telnet

Remote login

Telnet HPC.sp.Net.edu.cn

rlogin

Remote login

Rlogin Hostname -l UserName

RSH

Execute the specified command at the remote host

RSH F01N03 Date

FTP

Transfer files between local hosts and remote hosts

FTP ftp.sp.net.edu.cn

RCP

Copy files between local hosts and remote hosts

RCP file1 host1: file2

ping

Send a response request to a network host

Ping hpc.sp.net.edu.cn

Mail

Reading and sending emails

Mail

Write

Send a message to another user

Write Username PTS / 1

Mesg

Allow or refuse to receive packets

MESG N

Korn shell command

Command name

Function description

Use

History

List the recently performed several commands and numbers

History

rim

Repeat the recently performed certain command

R -2

Alias

Define an alias for a command

Alias ??del = rm -i

UNALIAS

Cancel the definition of an alias

UNALIAS DEL

Other orders

Command name

Function description

Use

uname

Display information about the operating system

Uname -a

Clear

Clear the screen or window content

Clear

ENV

Display all currently set environment variables

ENV

WHO

List all users currently logged in

WHO

Whoami

Display the username of currently being operated

Whoami

Tty

Display the name of the terminal or psego terminal

Tty

Stty

Display or reset the control key definition

Stty -a

DU

Query disk usage

Du -k subdir

DF

Display the total space and free space of the file system

DF / TMP

w

Shows the total information of the current system activity

How to see the Finder hidden file?

First, open the Terminal window, then enter the following command:

For OS X MAVERICKS 10.9:

Defaults Write Com.apple.finder AppleShowAllFiles True

For previous OS X versions:

Defaults Write Com.apple.finder AppleShowAllFiles True

Then, simply restart the Finder application, then enter a command:

Related Posts