Mac Terminal commands Daquan 1

Source: Internet
Author: User
Tags clear screen dbx diff disk usage

OSX's File system
OSX uses the Unix file system, all the files are hanging in the directory/below, so there is no need to have the concept of the drive letter under Windows.
The hard drives you see on the desktop are hung under/volumes.
For example, after a mobile drive called USBHD, the desktop will show a hard disk icon, where is it actually?
Execute LS/VOLUMES/USBHD in the terminal to see if the contents of this mobile drive are displayed.
root directory location is/core Mach_kernel right here,
Drive Location/systme/library/extensions
User folder location/user/user name
The location of the desktop/user/user name/desktop
File wildcard character Asterisk *
Note: In UNIX systems, there is a difference between uppercase and lowercase characters, and A.txt is not equal to a.txt.
Root flag/Not dispensable, cd/system means to go to the system under the directory, and the CD system means to go to the system in the current directory
——————————————————————————————————————————————
How to enter command line operation mode
In the graphical interface, open the Application utility terminal with the Finder
If even the graphical interface can not be entered (such as the wrong display driver), when the boot press F8, start with the-s parameter, and then enter the command MOUNT-UW/

Get permission
In order to prevent misoperation to destroy the system, then the user state when there is no permission operating system important files, so first to get root permissions
Sudo-s
Then enter the password, enter the password without any echo, even the asterisk is not, just lose the return on the line.
——————————————————————————————————————————————
Basic commands
List files
LS parameter directory name
Example: Want to see what is in the directory,
LS/
Want to see what's in the drive directory,
Ls/system/library/extensions
Parameter-W displays Chinese,-l details,-a including hidden files
Converting catalogs
Cd
Example: Think of a drive directory to stroll around
Cd/system/library/extensions
Create a new directory
mkdir Directory Name
Example: Create a backup directory in the driver directory
Mkdir/system/library/extensions/backup
Build a backup directory on the desktop back up
mkdir/user/User name/desktop/backup
Copy files
CP parameter source file destination file
Example: Want to copy the desktop Natit.kext to the drive directory
Cp-r/user/User Name/desktop/natit.kext/system/library/extensions
The parameter R indicates a recursive operation of the directory, and Kext looks like a file under the graphical interface, which is actually a folder.
Back up all files in the drive directory to desktop backup
Cp-r/system/library/extensions/*/user/User name/desktop/backup
deleting files
RM parameter File
Example: To delete a driver's cache
Rm-rf/system/library/extensions.kextcache
Rm-rf/system/library/extensions.mkext
Parameter-RF is recursive and mandatory, be careful to use, if executed RM-RF/your system is gone

Moving files
MV File
Example: Want to move Applehda.kext to the desktop
mv/system/library/extensions/applehda.kext/user/User name/desktop
Want to move the Applehda.kext to the backup directory
Mv/system/library/extensions/applehda.kext/system/library/extensions/backup
Change file permissions
chmod parameter Permission file
Example: Set all files in the drive directory to root read/write, other users read only
Chmod-r 755/system/library/extensions
The parameter R is recursive, and 755 represents the permissions of each user
Change file Owner
Chown parameter User: Group file
Example: Change all the files in the drive directory to the root user
Chown-r root:wheel/system/library/extensions
Parameter r indicates a recursive operation
Fix permissions on files throughout the system
Diskutil repairpermissions/
Strictly speaking, this is not a Unix command, but OSX is a software that remembers the modification or addition of the driver to execute once.
Text editing
Nano file name
Example: Edit Natit info.plist
Nano/system/library/extensions/natit.kext/info.plist
After editing, use Ctrl +o to save, ctrl+x exit
Another text editing software is VI, the operation is a bit odd, cooked is very useful, and in all Unix-like systems, it is not afraid to go all over the world.
Run script command
SH Script file name
Example to modify the driver after all the required operations into a script, after the driver has been modified to run once this script is OK, convenient
1. Running Nano/clean in terminal
2. Paste the following code into the 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 disk, ctrl+x exit
4. Once the driver is moved, run it once in the terminal Sh/clean
————————————————————————————————————
Little Tricks
Use the Tab key to auto-complement commands
For example, think of the/system directory, enter the Cd/sy and then press the TAB key, the command will automatically fill into equal Cd/system
Manipulate files and directories with spaces in the name
Spaces are written in the command, for example, to enter My Documents, the command is CD My Documents
View detailed help for a command
Man command name
For example, to see the detailed use of the LS command, execute the man ls
————————————————————————————————————
Typical Operating Procedures
(assuming you've made a clean script, remember to sudo-s get system permissions before each operation)
Suppose you download a video card driver Natit.zip, the desktop decompression to get a natit.kext, how to do it?
For the sake of insurance, back up all the drivers first.
mkdir/user/User name/desktop/backup Create a backup folder on the desktop
Cp-r/system/library/extensions/*/user/User name/desktop/backup backup driver file
Now you can install it safely.
Cp-r/user/user name/desktop/natit.kext/system/library/extensions copy it to the system-driven directory location
Sh/clean Execute cleanup Script, Operation complete
Re-boot failed, into the desktop, found that should not be the driver, how to recover it?
Power on F8, start with-s parameter
Execute MOUNT-UW/
rm-rf/user/User name/desktop/natit.kext Delete this driver
Sh/clean Execute cleanup Script, Operation complete
Restart, back to the original state, do not forget Ah, no special effects how to do it, and heard the need to modify the Natit Info. plist file is fine.
Cp-r/user/user name/desktop/natit.kext/system/library/extensions copy it to the system-driven directory location
Nano/system/library/extensions/natit.kext/info.plist
After editing, use Ctrl +o to save, ctrl+x exit
Sh/clean Execute cleanup Script, Operation complete
Restart, this time, the Carter effect has been, the sound card, God knows what will happen, we have to protect the existing results.
mkdir/user/User name/desktop/gooddrivers to create a directory for valid drivers
Cp-r/system/library/extensions/natit.kext/user/user name/desktop/gooddrivers backup
This sound card requires Applehda.kext to delete and edit the Appleazaliaaudio.kext in the Info.plist file, who knows later will not still use AppleHDA it, rather temporarily disable it.
mkdir/system/library/extensions/disabled Creating a disabled directory
Mv/system/library/extensions/applehda.kext/system/library/extensions/disabled move Past
Nano/system/library/extensions/natit.kext/appleazaliaaudio.kext/info.plist
After editing, use Ctrl +o to save, ctrl+x exit
Sh/clean Execute cleanup Script, Operation complete
Successful, but also put the modified driver back up
Copy content to Clipboard code:

The following is the UNIX command line, for reference
Directory Operations
Command name
Function description
Examples of 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
Displays the path name of the current directory
Pwd
Ls
Display the contents of the current directory
Ls-la
dircmp
Compare the contents of two directories
DIRCMP Dir1 Dir2
File operations
Command name
Function description
Examples of Use
Cat
Show or connect files
Cat filename
Pg
Paging formatted display of file contents
PG filename
More
Split-screen display of file contents
More filename
Od
Display the contents of a non-text file
od-c filename
Cp
Copy a file or directory
CP file1 File2
Rm
Delete a file or directory
RM filename
Mv
Change the file name or directory
MV File1 File2
ln
Join file
Ln-s file1 file2
Find
Finding files using matching expressions
Find. -name "*.C"-print
File
Show file types
File filename
Select action
Command name
Function description
Examples of Use
Head
Show the first few lines of a file
head-20 filename
Tail
Display the last few lines of a file
tail-15 filename
Cut
Display some fields in each row of a file
Cut-f1,7-d:/etc/passwd
Colrm
Remove several columns from standard input
COLRM 8 File2
Paste
Cross-connect files
Paste File1 file2
Diff
Compare and display the differences of two files
diff File1 File2
Sed
Non-interactive mode flow editor
Sed "s/red/green/g" filename
Grep
Find in Files by pattern
grep "^[a-za-z]" filename
Awk
Find and manipulate patterns in files
awk ' {print '} ' filename
Sort
Sort or Merge files
sort-d-f-u File1
Uniq
Remove duplicate rows from a file
Uniq file1 file2
Comm
Public and non-public rows showing two ordered files
Comm File1 File2
Wc
The number of characters, words, and lines of a statistic file
WC filename
nl
Add a line number to a file
NL file1 >file2
Safe operation
Command name
Function description
Examples of Use
passwd
Modify User Password
passwd
chmod
Change permissions for a file or directory
chmod ug+x filename
Umask
Define a permission mask to create a file
Umask 027
Chown
Change the owner of a file or directory
Chown newowner filename
Chgrp
Change the owning group of a file or directory
CHGRP staff filename
Xlock
To lock the terminal
Xlock-remote
Programming operations
Command name
Function description
Examples of Use
Make
Maintaining the latest version of an executable program
Make
Touch
Update file access and modification times
Touch-m 05202400 filename
Dbx
Command line interface Debugging Tools
DBX a.out
Xde
Graphical user interface Debugging Tools
Xde a.out
Process actions
Command name
Function description
Examples of Use
Ps
Show the current status of the process
PS u
Kill
Terminating a process
Kill-9 30142
Nice
Change the priority of the pending command
Nice cc-c *.c
Renice
Change the priority of a running process
Renice +20 32768
Time operation
Command name
Function description
Examples of Use
Date
Displays 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 operations
Command name
Function description
Examples of Use
Telnet
Telnet
Telnet hpc.sp.net.edu.cn
Rlogin
Telnet
Rlogin hostname-l username
Ts.
Execute the specified command on the remote host
RSH f01n03 Date
Ftp
Transferring files between a local host and a remote host
FTP ftp.sp.net.edu.cn
Rcp
Copying files between a local host and a remote host
rcp file1 host1:file2
Ping
Send a response request to a network host
Ping hpc.sp.net.edu.cn
Mail
Read and send e-mail
Mail
Write
Send a message to another user
Write username PTS/1
Mesg
Allow or deny receiving of messages
MESG N
Korn shell command
Command name
Function description
Examples of Use
History
List several recently executed commands and numbers
History
R
Repeatedly executes a command that has been recently executed
R-2
Alias
To define an alias for a command
Alias Del=rm-i
Unalias
To cancel the definition of an alias
Unalias del
Other commands
Command name
Function description
Examples of Use
Uname
Displays information about the operating system
Uname-a
Clear
Clear screen or window contents
Clear
Env
Show all currently set environment variables
Env
W.H.O.
List all users who are currently logged on
W.H.O.
WhoAmI
Displays the user name that is currently in action
WhoAmI
Tty
Displays the name of the terminal or pseudo terminal
Tty
Stty
Display or reset control key definitions
Stty-a
Du
Querying disk usage
Du-k SubDir
Df
Displays the total and free space of the file system
Df/tmp
W
Displays the total information for the current system activity

Mac Terminal commands Daquan 1

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.