Mac OS Terminal Command Summary command turn on the lock screen set shortcut keys

Source: Internet
Author: User
Tags clear screen diff file type file mkdir require disk usage
OSX file system
The Unix file system used by OSX, all files are hung under the directory /, so there is no need to have a drive letter concept under Windows.
The hard drives you see on your desktop are all mounted under / Volumes.
For example, when a mobile hard disk called USBHD is connected, a hard disk icon will be displayed on the desktop. Where is it actually?
Run ls / Volumes / USBHD in the terminal and see if the contents of the removable hard disk are displayed.
The root directory location is / core Mach_kernel is here,
Driver location / Systme / Library / Extensions
User folder location / User / username
Desktop location / User / username / Desktop
File wildcards are asterisks *
Note: Uppercase and lowercase characters are distinguished on Unix systems, and A.txt is not equal to a.txt.
The root directory sign / is not optional, cd / System means go to the system under the directory, and cd System means go to the system under the current directory
————————————————————————————————————————————
How to enter command line operation mode
In the graphical interface, use finder to open the application "Utilities" Terminal
If you can't even access the graphical interface (for example, the wrong display driver is installed), press F8 when booting, start with the -s parameter, and then enter the command mount -uw /

Get permission
In order to prevent accidental operation and damage to the system, if the user does not have permission to the important files of the operating system, the root permission must be obtained first.
sudo-s
Then enter the password, there is no echo when entering the password, there is no asterisk, just press Enter after entering.
————————————————————————————————————————————

Basic commands
List files
ls parameter directory name Example: see what is in the driver directory: ls / System / Library / Extensions
Parameter -w displays Chinese, -l details, -a includes hidden files
2.Convert the directory

cd Example: Think of a walk around the drive directory cd / System / Library / Extensions

3.Create a new directory
mkdir directory name Example: Create a backup directory under the drive directory backup mkdir / System / Library / Extensions / backup
Create a backup directory backup mkdir / User / username / Desktop / backup on the desktop

4.Copy files
cp parameter source file target file Example: want to copy the desktop's Natit.kext to the drive directory cp -R /User/username/Desktop/Natit.kext / System / Library / Extensions
The parameter R indicates a recursive operation on the directory. In the graphical interface, kext looks like a file, but it is actually a folder.
Back up all files in the drive directory to the desktop backup
cp -R / System / Library / Extensions / * / User / username / Desktop / backup

5.Delete files
rm parameter file Example: want to delete the driver's cache rm -rf /System/Library/Extensions.kextcache rm -rf /System/Library/Extensions.mkext
The parameter -rf means recursion and coercion. Be careful to use it. If you execute rm -rf / your system will be gone.

6.Move files
mv file Example: want to move AppleHDA.Kext to the desktop mv /System/Library/Extensions/AppleHDA.kext / User / username / Desktop
Want to move AppleHDA.Kext to the backup directory mv /System/Library/Extensions/AppleHDA.kext / System / Library / Extensions / backup

7.Text editing
nano file name Example: edit natit Info.plist nano /System/Library/Extensions/Natit.kext/Info.plist

 

Directory operations

Command name Function description Example

mkdir creates 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 show the contents of the current directory ls -la

 

File operations

Command name Function description Example

cat Display or concatenate the file cat filename

 

 

od display the contents of a non-text file od -c filename

cp copy file or directory cp file1 file2

rm delete file or directory rm filename

mv change file name or directory mv file1 file2

find Find files using match expression find. -name "* .c" -print

file show file type file filename

Select operation

Command name Function description Example

head shows the first few lines of the file head -20 filename

tail shows the last few lines of the file tail -15 filename

cut shows some fields in each line of the file cut -f1,7 -d: / etc / passwd

colrm delete several columns from standard input colrm 8 20 file2

diff compares and displays the differences between two files diff file1 file2

sort Sort or merge files sort -d -f -u file1

uniq remove duplicate lines in a file uniq file1 file2

comm shows the public and non-public lines of two ordered files comm file1 file2

wc counts the number of characters, words, and lines in a file wc filename

nl add line number to file nl file1> file2

Process operation

Command name Function description Example

ps shows the current status of the process ps u

kill kill process kill -9 30142

 
Time operation

Command name Function description Example

date shows the current date and time of the system date

cal show calendar cal 8 1996

time counts the execution time of the program 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 execute specified command on remote host rsh f01n03 date

ftp transfers files between localhost and remote hosts ftpftp.
sp.net.edu.cn

rcp Copy files between local host and remote host rcp file1 host1: file2

ping sends a response request to a network host ping hpc.sp.net.edu.cn

mail read and send email mail

write send a message to another user write username pts / 1

mesg Allow or deny receiving messages mesg n

Korn shell commands

 Command name Function description Example

history lists the most recently executed commands and their numbers

r Repeats a recently executed command r -2

alias Define an alias for a command alias del = rm -i

unalias undefine an alias unalias del

Other commands

Command name Function description Example

uname Displays information about the operating system. uname -a

clear clear screen or window content clear

env displays all currently set environment variables env

who lists all users currently logged in who

whoami displays the username of the user who is currently operating whoami

tty displays the name of the terminal or pseudo terminal tty

stty display or reset control key definitions stty -a

du query disk usage du -k subdir
df / tmp displays the total and free space of the file system

w Display total information about current system activity

 
Mac OS X terminal command enable function

1.Lion display library under Lion
method one:
display
Enter the following command in Terminal:
chflags nohidden ~ / Library /

hide
Enter the following command in Terminal:
chflags hidden ~ / Library /

Method Two:
Open the Finder, select Go in the menu and hold down the option key to display the library items (you need to repeat the operation each time you open).

2.Finder shows hidden files
Show hidden files
Enter the following command in Terminal:
defaults write com.apple.finder AppleShowAllFiles -bool true
killall Finder

Recover hidden files
Enter the following command in Terminal:
defaults write com.apple.finder AppleShowAllFiles -bool false
killall Finder

3.Xcode uninstall
Enter the following command in Terminal:
sudo / Library / uninstall-devtools? mode = all

This is the actual installation directory. Xcode is installed in the / Developer directory by default.
sudo / Developer / Library / uninstall-devtools? mode = all

4. Show full path in Finder title bar
Enter the following command in Terminal:
defaults write com.apple.finder _FXShowPosixPathInTitle -bool YES
killall Finder

5. Remove the shadow of the window screenshot
When you take a screenshot of the window (Command-Shift-4, space), a circle of shadows is automatically added around the resulting image.
If you don't like the effect of this shadow, you can turn it off.
Enter the following command in Terminal:
defaults write com.apple.screencapture disable-shadow -bool true
killall SystemUIServer

6. Force Safari to open the webpage in a new tab
Safari supports tabbed browsing by default. However, when we click on a link on a page or in another application,
Safari often opens a new window, which causes too many Safari windows on the page and is difficult to manage. With this little trick below,
We can make Safari open the webpage in a new tab by default.
Enter the following command in Terminal:
defaults write com.apple.Safari TargetedClicksCreateTabs -bool true

7. Change the save location of the screenshot
Mac OS provides very convenient screenshot shortcuts that allow us to take screenshots of the entire screen, some screens, or application windows very quickly. However, this screenshot function has a disadvantage that it can only save screenshot images to the desktop. If we take too many pictures, it will make the desktop look messy. Is there any way to modify the default save location of the screenshot? Have. The method is very simple, just enter the following command in Terminal.
defaults write com.apple.screencapture location
killall SystemUIServer

When entering the command, replace the "storage location" with a real folder. For example, if you want to save it to the Screenshots folder of your user directory, enter
defaults write com.apple.screencapture location ~ / Screenshots

 

 
Mac lock screen settings shortcuts

If you want to leave the computer for a while, you can choose to close the notebook directly. However, the process that was originally running will hang or end. If it is downloading, the download will be suspended (sometimes it cannot be resumed). If the network service is being provided, then because the network is down, no one can connect to your laptop. . The lock screen can solve this problem. Under Windows, you can use the Win + L shortcut key to lock the screen, but there is no default shortcut key under Mac OS X.

For novices like me, don't mention setting lock screen shortcuts, even if I want to use other lock screen methods, I have to go online to find them. One way is to first find the "Keychain Access" utility in Finder (the specific location is / Applications / Utilities / Keychain Access.app), and then select "Show Keychain Status in the menu bar" ". At this time we found that the system menu has a small icon like a lock. Just click on it to find the lock screen.

The above method achieves the lock screen, but the goal of controlling the lock screen by a shortcut key has not been achieved. Nevertheless, its effect gives us a lock screen idea. First, we require that the screen saver must enter a password when recovering, and then the lock screen problem becomes a problem of starting the screen saver. Lock the screen via a keyboard shortcut This article describes the specific implementation method.

The first step is to find "Security and Privacy" under "System Preferences", and tick "Require a password immediately after entering sleep or starting a screen saver" on the "General" page.

The second step is to start the screen saver with a shortcut, which is a bit more complicated. Find "Automator" in "Applications". Create a new service, find "Start Screen Saver" in "Utilities" under "Actions", drag this operation to the right, and select "No Input" and "Any Application", as shown below . Then save the service with a name you define.


Mac OS terminal command summary Command enable Lock screen setting shortcuts-mac os lock screen shortcuts



Finally, find "Keyboard" in "System Preferences", and then configure shortcut keys for the service just defined. I set it to Command + Control + L.
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.