Mac terminal command Daquan

OSX file system
OSX adopts the Unix file system, all files are hung under the directory /, so there is no need to have the concept of drive letters under Windows.
The hard drives you see on the 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?
Execute ls /Volumes/USBHD in the terminal to see if the contents of the mobile hard disk are displayed.
The root directory location is /Core Mach_kernel right here, the
driver location/Systme/Library/Extensions
User folder location/User/username
Desktop location/User/username/Desktop
file wildcards are asterisks *
Note: On Unix systems In is case-sensitive characters, A.txt is not equal to a.txt.
The root directory flag / is not optional, cd /System means go to the System under the following directory, and cd System means go to the System under the current directory
——————————————— ——————————————————————————————
How to enter the command line operation mode In
the graphical interface, use finder to open the application > utility "Terminal
If you can't even enter the graphical interface (for example, the wrong display driver is installed), press F8 when booting up, use the -s parameter to start, and then enter the command mount -uw /

to obtain permission.
In order to prevent misoperation from destroying the system, the user status There is no permission for important files of the operating system, so you must first obtain root permissions
sudo -s
and then enter the password, there is no echo when entering the password, not even an asterisk, just press Enter after typing.
————————————————————————————————————————————————
Basic Commands
List File
ls parameter directory name
Example : want to see what is in the root directory,
ls /
want to see what is in the driver directory,
ls /System/Library/Extensions
parameter -w display Chinese, -l detailed information, -a include hidden files
Convert directory
cd
Example: think of walking around in the driver directory
cd /System/Library/Extensions
to create a new directory
mkdir Directory name
Example : create a backup directory backup
mkdir /System/Library/Extensions/backup
in the driver directory Create a backup directory on the desktop Backup directory backup
mkdir /User/username/Desktop/backup
copy file
cp parameter source file target file
Example : I want to copy the Natit.kext of the desktop to the drive directory
cp -R /User/username/Desktop/Natit.kext / System/Library/Extensions
The parameter R represents recursive operation on the directory, and kext looks like a file under the graphical interface, but is actually a folder.
Backup all files in the driver directory to the desktop backup
cp -R /System/Library/Extensions/* /User/username/Desktop/backup
delete the file
rm parameter file
Example : want to delete the cache of the driver
rm -rf /System/Library /Extensions.kextcache
rm -rf /System/Library/Extensions.mkext
parameter -rf means recursion and force, must be used carefully, if you execute rm -rf / your system will be gone.

Move file
mv file
Example : want to Move AppleHDA.Kext to desktop
mv /System/Library/Extensions/AppleHDA.kext /User/username/Desktop
Want to move AppleHDA.Kext to backup directory
mv /System/Library/Extensions/AppleHDA.kext /System/Library /Extensions/backup
Change file permission
chmod parameter permission file
Example : Set all files in the drive directory to root read and write, other users read only
chmod -R 755 /System/Library/Extensions
Parameter R means recursion, 755 means the authority of each user
Change file
chown Parameter user: group file
Example : Change the owner of all files in the drive directory to the root user
chown -R root:wheel /System/Library/Extensions
parameter R Represents recursive operation
to repair the permissions of files in the entire system
diskutil repairpermissions /
Strictly speaking, this is not a unix command, but an osx software, remember to modify or add a driver and execute it 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 to disk, and Ctrl + X to exit.
Another text editing software is vi, the operation is a bit strange, familiar It is very easy to use, and in all Unix-like systems, it is not afraid to travel around the world.
Run the script command
sh script file name
Example After modifying the driver, all the required operations are saved as a script. After modifying the driver, you only need to run the script once. Convenient
1. Run nano /clean in the terminal
2. Paste the following code To 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 Save the disk, Ctrl+X to exit
4. As long as the driver is moved in the future, run sh /clean in the terminal
once ——————
Tips
Use the Tab key to automatically complete commands. For
example, if you want to go to the /System directory, enter cd /Sy and then press the Tab key, the command will be automatically completed as cd /System
operation with the name in the name Files and directories with
spaces Spaces are written as spaces in the command. For example, to enter My Documents, the command is cd My Documents to
view the detailed help of the
command man command name. For
example , to see the detailed usage of the ls command, execute man ls
—————— ——————————————————————————————
Typical operation process
(assuming that the cleanup script has been made, remember to get sudo -s before each operation system Authority)
Suppose you have downloaded a graphics card driver Natit.zip and decompressed it on the desktop to get a Natit.kext, what should you do?
To be on the safe side, first back up all the drivers and then
mkdir /User/username/Desktop/backup Create a backup folder on the desktop
cp -R /System/Library/Extensions/* /User/username/Desktop/backup Backup the driver File
Now you can install
cp -R /User/username/Desktop/Natit.kext /System/Library/Extensions with peace of mind Copy it to the system drive directory location
sh /clean Execute the cleanup script, the operation is complete
Reboot fails and cannot enter The desktop is gone, and I found that this driver should not be installed. How to restore it?
Press F8 at boot, start with the -s parameter,
execute mount -uw /
rm -rf /User/username/Desktop/Natit.kext to delete the driver
sh /clean Execute the cleanup script, the operation is completed,
restart , return to the original state, don't give up Ah, how can it work without special effects, and I heard that you need to modify Natit's Info. plist file, okay, then
cp -R /User/username/Desktop/Natit.kext /System/Library/Extensions to copy it to the system Driver directory location
nano /System/Library/Extensions/Natit.kext/Info.plist
After editing, use Ctrl + O to save to disk, Ctrl + X to exit
sh /clean to execute the cleanup script, the operation is completed, and
restart .
mkdir /User/username/Desktop/gooddrivers Create a directory for valid drivers
cp -R /System/Library/Extensions/Natit.kext /User/username/Desktop/gooddrivers Backup
This sound card requires AppleHDA.kext to be deleted and edited The Info.plist file in AppleAzaliaAudio.kext, who knows if AppleHDA will be used in the future, might as well disable it temporarily.
mkdir /System/Library/Extensions/disabled Create a disabled directory
mv /System/Library/Extensions/AppleHDA.kext /System/Library/Extensions/disabled Move past
nano /System/Library/Extensions/Natit.kext/AppleAzaliaAudio.kext/ After the Info.plist is
edited, use Ctrl + O to save to disk, Ctrl + X to exit
sh /clean and execute the cleanup script. The operation is
successful , and the modified driver is also backed up.
Copy the content to the clipboard Code:

The following is the unix command line for reference
Directory operation
command name
Function description
Use example
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
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
Use example
cat
to display or connect files
cat filename
pg
paging formatted display file content
pg filename
more
split screen display file content
more filename
od
display the content of non-text files
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
ln
join file
ln -s file1 file2
find
find file using matching expression
find . -name "* .c" -print
file
display file type
file filename
selection operation
command name
function description
use 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 some of the lines in the file domain
cut -f1,7 -d: /etc/passwd
colrm
remove several columns from standard input
colrm 8 20 file2
paste
Concatenate files laterally
paste file1 file2
diff
compare and show the difference between two files
diff file1 file2
sed
non-interactive stream editor
sed "s/red/green/g" filename
grep
find by pattern in files
grep "^[a-zA -Z]" filename
awk
find and process patterns in files
awk '{print $1 $1}' filename
sort
sort or merge files
sort -d -f -u file1
uniq
remove duplicate lines in files
uniq file1 file2
comm
show two sorted Common and non-common lines of a file
comm file1 file2
wc
Count the number of characters, words and lines of a file
wc filename
nl
Add a line number to the file
nl file1 >file2
Safe operation
Command name
Function description Example of
use
passwd
Modify user password
passwd
chmod
change file or directory permissions
chmod ug+x filename
umask
define the permission mask for creating files
umask 027
chown
change file or directory owner
chown newowner filename
chgrp
change file or directory group
chgrp staff filename
xlock
give Terminal lock
xlock -remote
programming operation
Command name
Function description
Use example
make
maintain the latest version of 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 Example of
use
ps
displays the current state of the process
ps u
kill kills the
process
kill -9 30142
nice
changes the priority of the command to be executed
nice cc -c *.c
renice
changes the priority of the running process
renice +20 32768
time operation
command name function
description example date Display the current date and time of the system date cal display the calendar cal 8 1996 time Count the execution time of the program time a.out Network and communication operations Command name Function description Use example Telnet remote login telnet hpc.sp.net.edu.cn rlogin remote login rlogin hostname -l username rsh executes the specified command rsh f01n03 date on the remote host























ftp
transfers files between local and remote hosts
ftp ftp.sp.net.edu.cn
rcp
copies files between local and remote hosts
rcp file1 host1:file2
ping
sends a response request to a network host
ping hpc.sp. net.edu.cn
mail
read and send e-
mail mail
write
send messages to another user
write username pts/1
mesg
allow or deny receiving messages
mesg n
Korn Shell Command
Command Name
Function
Description List the most recent executions using an example
history
Several commands and their number
history
r
Repeatedly execute a command that was executed recently
r -2
alias
Define an alias for a command
alias del=rm -i
unalias Unalias
an alias
unalias del
Other commands
Command name
Function description
Use example
uname
to display information about the operating system
uname -a
clear
to clear the screen or window content
clear
env
displays all currently set environment variables
env
who
lists all currently logged in users
who
whoami
displays the currently operating user name
whoami
tty
show the name of the terminal or pseudo-terminal
tty
stty
show or reset control keys define
stty -a
du
query disk usage
du -k subdir
df
show the total and free space of the file system
df /tmp
w
show the current system activity General information

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326032267&siteId=291194637