Common commands on Mac OS X

Source: Internet
Author: User
Tags clear screen dbx

In the Mac OS X operating system of apple, there are many ways to hide the display of files. The simplest method is to enter commands on the Mac terminal. The command for displaying/hiding a Mac hidden file is as follows (note the spaces and make them case sensitive ):

Command for displaying Mac hidden files: Defaults write com. Apple. Finder appleshowallfiles-bool
True

Command for hiding Mac hidden files: Defaults write com. Apple. Finder appleshowallfiles-bool
False

Or

Command for displaying hidden Mac files: Defaults write com. Apple. Finder appleshowallfiles Yes

Command for hiding Mac hidden files: Defaults write com. Apple. Finder appleshowallfiles No


After entering the key, click Enter to exit the terminal and restart the finder.

Restart finder: Click the apple icon in the upper left corner of the window --> force exit --> finder --> restart

Mac OS X terminal clear screen shortcut: cammand + K (clear is actually useless)

Linux clear screen shortcut: Ctrl + L (reset)

Windows command line clear command: CLS

OS X is a UNIX file system. All files are mounted under the root directory/. Therefore, the drive letter concept in Windows is no longer available.

The hard disks you see on the desktop are all mounted on/volumes.
For example, if you connect a mobile hard drive named usb hd, a hard drive icon will be displayed on the desktop. Where is it actually?
Run ls/volumes/usbhd on the terminal to check whether the content of the mobile hard disk is displayed.

The root directory is/Core mach_kernel,
Driver location/Development me/library/extensions
User folder location/user/User Name
Desktop location/user name/desktop

The file wildcard is asterisk *

Note: In the unixsystem, A. txt is not the same as a.txt.
The root directory flag/is not dispensable. CD/system indicates to go to the system under the same directory, and CD system indicates to go to the system under the current directory.

----------------------------------------------
How to enter the command line operation mode
Then, use the Finder to open the application utility terminal.
If you cannot connect to the graphic interface (for example, if you have installed an incorrect display driver), press F8 at startup, start with the-S parameter, and then enter the command Mount-UW/

Get Permissions
In order to prevent misoperation and damage to the system, if the user does not have the permission to operate important files of the system, the user must first obtain the root permission.
Sudo-S
Then enter the password. When you enter the password, there is no echo and no star number. Just press Enter.

----------------------------------------------
Basic commands
List objects
Ls parameter directory name
For example, I want to see what is in the directory,
Ls/
Want to see what is in the driver directory,
Ls/system/library/extensions
Parameter-W displays Chinese characters,-l details,-A includes hidden files
Conversion directory
CD
For example, think of a loop in the driver directory.
CD/system/library/extensions

Create a new directory
Mkdir directory name
For example, create a backup directory backup under the driver directory.
Mkdir/system/library/extensions/backup
Create a backup directory backup on the desktop
Mkdir/user name/desktop/backup

Copy an object
CP parameter source file target file
For example, you want to copy the natit. kext file on the desktop to the driver directory.
CP-r/user name/desktop/natit. kext/system/library/extensions
The R parameter indicates recursive operation on the directory. kext looks like a file on the GUI, but actually a folder.
Back up all files in the driver directory to the desktop backup
CP-r/system/library/extensions/*/user name/desktop/backup

Delete an object
Rm parameter file (RM-RF folder)
For example, you want to delete the driver cache.
Rm-RF/system/library/extensions. kextcache
Rm-RF/system/library/extensions. mkext
Parameter-RF indicates recursion and force. Be careful when using this parameter. If you run Rm-RF/your system, it's all gone.

Move files
MV File
For example, you want to move applehda. kext to the desktop.
MV/system/library/extensions/applehda. kext/user name/desktop
I want to move applehda. kext to the backup directory.
MV/system/library/extensions/applehda. kext/system/library/extensions/backup

Change File Permissions
Chmod parameter permission file (# Add ch stands for change)
For example, set all files in the driver directory to root for read and write, while other users are read-only.
Chmod-r 755/system/library/extensions
The R parameter indicates recursion, and 755 indicates the permissions of each user.

Change file owner
Chown parameter User: group file
For example, change the owner of all files in the driver directory to the root user.
Chown-r root: wheel/system/library/extensions
The R parameter indicates recursive operation.

Fix file permissions in the entire system
Diskutil repairpermissions/
Strictly speaking, this is not a Unix Command, but an OSX software. Remember to modify or add the driver and execute it once.

Text editing
Nano file name
For example, edit natit info. plist.
Nano/system/library/extensions/natit. kext/info. plist
After editing, press Ctrl + O to save the disk, and press Ctrl + X to exit.
Another text editing software is VI, which has some odd operations and is very easy to use. It is also used in all UNIX-like systems.

Run the script command
Sh script file name
For example, after the driver is modified, all required operations are saved as a script. After the driver is modified, you only need to run the script once.
1. Run 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. Press Ctrl + O to save the disk, press Ctrl + X to exit
4. Run sh/clean once on the terminal as long as the driver is activated.

------------------------------------
Tips

Use the tab key to automatically complete the command
For example, enter CD/sy in the/system directory and press the tab key. The command is automatically merged into CD/system.

Operate files and directories with spaces in names
The space is written as a space in the command. For example, to enter my documents, the command is CD my documents ENTs.

View Detailed Help of commands
Man command name (# Add manual)
For example, to view the detailed usage of the LS command, execute man ls

------------------------------------
Typical operation process
(Assuming that the cleanup script has been prepared, remember that Sudo-s obtained the system permission before each operation)

Assume that you have downloaded a graphics card driver natit.zip and obtained a natit. kext file from the desktop. How can this problem be solved?

To be safe, back up all drivers first.
Mkdir/user name/desktop/backup create a backup folder on the desktop
CP-r/system/library/extensions/*/user name/desktop/backup driver File

Now you can install it with peace of mind.
CP-r/user name/desktop/natit. kext/system/library/extensions copy it to the system driver directory
SH/clean: Execute the cleanup script. The operation is complete.

An error occurred while restarting the desktop. I found that the driver should not be installed. How can I restore it?
Press f8. start with the-S parameter.
Run Mount-UW/
Rm-RF/user name/desktop/natit. kext Delete this driver
SH/clean: Execute the cleanup script. The operation is complete.

Restart and return to the original status. Don't worry. How can I do without special effects? I heard that I need to modify the info. plist file of natit.
CP-r/user name/desktop/natit. kext/system/library/extensions copy it to the system driver directory
Nano/system/library/extensions/natit. kext/info. plist
After editing, press Ctrl + O to save the disk, and press Ctrl + X to exit.
SH/clean: Execute the cleanup script. The operation is complete.

Restart. By the way, all the video effects are available. It's time to get the sound card. You know what will happen, and you have to protect the existing results.
Mkdir/user name/desktop/gooddrivers create a directory for the effective driver
CP-r/system/library/extensions/natit. kext/user name/desktop/gooddrivers backup

This sound card requires that applehda. kext be deleted and edited. Who knows if applehda will be used in the future.
Mkdir/system/library/extensions/disabled
MV/system/library/extensions/applehda. kext/system/library/extensions/disabled move past
Nano/system/library/extensions/natit. kext/appleazaliaaudio. kext/info. plist
After editing, press Ctrl + O to save the disk, and press Ctrl + X to exit.
SH/clean: Execute the cleanup script. The operation is complete.
After successful, back up the modified driver and copy the copied content to the clipboard code:

The following is a Unix Command Line for your reference.

Directory operations

Command name
Function Description
Example

Mkdir
Create a directory
Mkdir dirname

Rmdir
Delete a directory
Rmdir dirname

Mvdir
Move or rename a directory
Mvdir dir1 dir2

CD
Change current directory
CD dirname

PWD
Display the path name of the current directory
PWD

Ls
Display the content of the current directory
Ls-la

Dircmp
Compare the contents of two directories
Dircmp dir1 dir2

File Operations

Command name
Function Description
Example

Cat
Display or connect files
Cat filename

PG
Display file content by PAGE formatting
PG filename

More
Split-screen display of File Content
More filename

Od
Show non-text file content
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
Search for files using matching expressions
Find.-Name "*. c"-print

File
Display file type
File filename

Select Operation

Command name
Function Description
Example

Head
Display the first few lines of the file
Head-20 filename

Tail
Display the last few lines of the file
Tail-15 filename

Cut
Display certain fields in each row of a file
Cut-F1, 7-D:/etc/passwd

Colrm
Delete several columns from standard input
Colrm 8 20 file2

Paste
Horizontally connected File
Paste file1 file2

Diff
Compare and display the differences between the two files
Diff file1 file2

Sed
Non-interactive stream Editor
Sed "s/red/green/g" filename

Grep
Search by mode in files
Grep "^ [A-Za-Z]" filename

Awk
Find and process the mode in the file
Awk '{print $1 $1}' filename

Sort
Sort or merge files
Sort-D-f-u file1

Uniq
Remove duplicate rows from the file
Uniq file1 file2

Comm
Display public and non-public rows of two ordered files
Comm file1 file2

WC
Number of characters, words, and lines in the Statistical File
WC filename

NL
Add the row number to the file
NL file1> file2

Security Operations

Command name
Function Description
Example

Passwd
Change User Password
Passwd

Chmod
Change file or directory permissions
Chmod ug + x filename

Umask
Define the permission mask of the created File
Umask 027

Chown
Change the owner of a file or directory
Chown newowner filename

Chgrp
Change the group of a file or directory
Chgrp staff filename

Xlock
Lock the terminal
Xlock-remote

Programming

Command name
Function Description
Example

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 operations

Command name
Function Description
Example

PS
Display current process status
PS u

Kill
Terminate a process
Kill-9 30142

Nice
Change the priority of the command to be executed
Nice CC-C *. c

Renice
Change the priority of a running process
Renice + 20 32768

Time Operation

Command name
Function Description
Example

Date
Displays the current date and time of the system.
Date

Cal
Show Calendar
Cal 8 1996

Time
Statistical Program Execution time
Time A. Out

Network and communication operations

Command name
Function Description
Example

Telnet
Remote Login
Telnet hpc.sp.net.edu.cn

Rlogin
Remote Login
Rlogin hostname-l Username

Rsh
Run the specified command on the remote host
Rsh f01n03 date

FTP
Transfers files between the local host and remote host
FTP ftp.sp.net.edu.cn

RCP
Copy files between the local host and 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 emails
Mail

Write
Send messages to another user
Write username pts/1

Mesg
Allow or reject receiving packets
Mesg n

Korn shell command

Command name
Function Description
Example

History
Lists the commands and numbers that have been executed recently.
History

R
Repeat the execution of a recent command.
R-2

Alias
Define an alias for a command
Alias del = Rm-I

Unalias
Cancels the definition of an alias.
Unalias del

Other commands

Command name
Function Description
Example

Uname
Displays information about the operating system.
Uname-

Clear
Clear screen or window content
Clear

Env
Display All currently set Environment Variables
Env

Who
List all users currently logged on
Who

Whoami
Displays the username currently performing the operation
Whoami

Tty
Display terminal or Pseudo Terminal name
Tty

Stty
Display or reset control key definitions
Stty-

Du
Query disk usage
Du-K subdir

DF
Displays the total space and available space of the file system.
DF/tmp

W
Displays the total information of the current system activity.
W

Related Article

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.