0%

Using Terminal

Using Terminal

sudo

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
sudo - execute a command as another user

usage: sudo -h | -K | -k | -V
usage: sudo -v [-AknS] [-g group] [-h host] [-p prompt] [-u user]
usage: sudo -l [-AknS] [-g group] [-h host] [-p prompt] [-U user] [-u user] [command]
usage: sudo [-AbEHknPS] [-C num] [-g group] [-h host] [-p prompt] [-u user] [VAR=value] [-i|-s] [<command>]
usage: sudo -e [-AknS] [-C num] [-g group] [-h host] [-p prompt] [-u user] file ...

Options:
-A, --askpass use a helper program for password prompting
-b, --background run command in the background
-C, --close-from=num close all file descriptors >= num
-E, --preserve-env preserve user environment when running command
-e, --edit edit files instead of running a command
-g, --group=group run command as the specified group name or ID
-H, --set-home set HOME variable to target user's home dir
-h, --help display help message and exit
-h, --host=host run command on host (if supported by plugin)
-i, --login run login shell as the target user; a command may also be specified
-K, --remove-timestamp remove timestamp file completely
-k, --reset-timestamp invalidate timestamp file
-l, --list list user's privileges or check a specific command; use twice for longer format
-n, --non-interactive non-interactive mode, no prompts are used
-P, --preserve-groups preserve group vector instead of setting to target's
-p, --prompt=prompt use the specified password prompt
-S, --stdin read password from standard input
-s, --shell run shell as the target user; a command may also be specified
-U, --other-user=user in list mode, display privileges for user
-u, --user=user run command (or edit file) as specified user name or ID
-V, --version display version information and exit
-v, --validate update user's timestamp without running a command
-- stop processing command line arguments

man

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
man, version 1.6c

usage: man [-adfhktwW] [section] [-M path] [-P pager] [-S list]
[-m system] [-p string] name ...

a : find all matching entries
c : do not use cat file
d : print gobs of debugging information
D : as for -d, but also display the pages
f : same as whatis(1)
h : print this help message
k : same as apropos(1)
K : search for a string in all pages
t : use troff to format pages for printing
w : print location of man page(s) that would be displayed
(if no name given: print directories that would be searched)
W : as for -w, but display filenames only

C file : use `file' as configuration file
M path : set search path for manual pages to `path'
P pager : use program `pager' to display pages
S list : colon separated section list
m system : search for alternate system's man pages
p string : string tells which preprocessors to run
e - [n]eqn(1) p - pic(1) t - tbl(1)
g - grap(1) r - refer(1) v - vgrind(1)

cd

进入指定目录

1
cd directory

mkdir

新建文件夹

1
mkdir [-pv] [-m mode] directory
1
2
3
4
5
6
7
8
9
10
11
12
13
The options are as follows:

-m mode
Set the file permission bits of the final created directory to the specified mode. The mode argument can be in any of the formats specified to the chmod(1) command. If a
symbolic mode is specified, the operation characters ``+'' and ``-'' are interpreted relative to an initial mode of ``a=rwx''.

-p Create intermediate directories as required. If this option is not specified, the full path prefix of each operand must already exist. On the other hand, with this option
specified, no error will be reported if a directory given as an operand already exists. Intermediate directories are created with permission bits of rwxrwxrwx (0777) as mod-
ified by the current umask, plus write and search permission for the owner.

-v Be verbose when creating directories, listing them as they are created.

The user must have write permission in the parent directory.

touch

新建文件

1
touch [-A [-][[hh]mm]SS] [-acfhm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
The following options are available:

-A Adjust the access and modification time stamps for the file by the specified value. This flag is intended for use in modifying files with incorrectly set time stamps.

The argument is of the form ``[-][[hh]mm]SS'' where each pair of letters represents the following:

- Make the adjustment negative: the new time stamp is set to be before the old one.
hh The number of hours, from 00 to 99.
mm The number of minutes, from 00 to 59.
SS The number of seconds, from 00 to 59.

The -A flag implies the -c flag: if any file specified does not exist, it will be silently ignored.

-a Change the access time of the file. The modification time of the file is not changed unless the -m flag is also specified.

-c Do not create the file if it does not exist. The touch utility does not treat this as an error. No error messages are displayed and the exit value is not affected.
hh The number of hours, from 00 to 99.
mm The number of minutes, from 00 to 59.
SS The number of seconds, from 00 to 59.

The -A flag implies the -c flag: if any file specified does not exist, it will be silently ignored.

-a Change the access time of the file. The modification time of the file is not changed unless the -m flag is also specified.

-c Do not create the file if it does not exist. The touch utility does not treat this as an error. No error messages are displayed and the exit value is not affected.

-f Attempt to force the update, even if the file permissions do not currently permit it.

-h If the file is a symbolic link, change the times of the link itself rather than the file that the link points to. Note that -h implies -c and thus will not create any new
files.

-m Change the modification time of the file. The access time of the file is not changed unless the -a flag is also specified.

-r Use the access and modifications times from the specified file instead of the current time of day.

-t Change the access and modification times to the specified time instead of the current time of day. The argument is of the form ``[[CC]YY]MMDDhhmm[.SS]'' where each pair of
letters represents the following:

CC The first two digits of the year (the century).
YY The second two digits of the year. If ``YY'' is specified, but ``CC'' is not, a value for ``YY'' between 69 and 99 results in a ``CC'' value of 19. Otherwise,
a ``CC'' value of 20 is used.
MM The month of the year, from 01 to 12.
DD the day of the month, from 01 to 31.
hh The hour of the day, from 00 to 23.
mm The minute of the hour, from 00 to 59.

rm

删除文件/文件夹

1
rm [-dfiPRrvW] file
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
The options are as follows:

-d Attempt to remove directories as well as other types of files.

-f Attempt to remove the files without prompting for confirmation, regardless of the file's permissions. If the file does not exist, do not display a diagnostic message or
modify the exit status to reflect an error. The -f option overrides any previous -i options.

-i Request confirmation before attempting to remove each file, regardless of the file's permissions, or whether or not the standard input device is a terminal. The -i
option overrides any previous -f options.

-P Overwrite regular files before deleting them. Files are overwritten three times, first with the byte pattern 0xff, then 0x00, and then 0xff again, before they are
deleted.

-R Attempt to remove the file hierarchy rooted in each file argument. The -R option implies the -d option. If the -i option is specified, the user is prompted for confir-
mation before each directory's contents are processed (as well as before the attempt is made to remove the directory). If the user does not respond affirmatively, the
file hierarchy rooted in that directory is skipped.

-r Equivalent to -R.

-v Be verbose when deleting files, showing them as they are removed.

-W Attempt to undelete the named files. Currently, this option can only be used to recover files covered by whiteouts.

The rm utility removes symbolic links, not the files referenced by the links.

It is an error to attempt to remove the files ``.'' or ``..''.

cp

1
2
3
cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file target_file

cp [-R [-H | -L | -P]] [-fi | -n] [-apvX] source_file ... target_directory
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
The following options are available:

-a Same as -pPR options. Preserves structure and attributes of files but not directory structure.

-f If the destination file cannot be opened, remove it and create a new file, without prompting for confirmation regardless of its permissions. (The -f option overrides any pre-
vious -n option.)

The target file is not unlinked before the copy. Thus, any existing access rights will be retained.

-H If the -R option is specified, symbolic links on the command line are followed. (Symbolic links encountered in the tree traversal are not followed.)

-i Cause cp to write a prompt to the standard error output before copying a file that would overwrite an existing file. If the response from the standard input begins with the
character `y' or `Y', the file copy is attempted. (The -i option overrides any previous -n option.)

-L If the -R option is specified, all symbolic links are followed.

-n Do not overwrite an existing file. (The -n option overrides any previous -f or -i options.)

-P If the -R option is specified, no symbolic links are followed. This is the default.

-p Cause cp to preserve the following attributes of each source file in the copy: modification time, access time, file flags, file mode, user ID, and group ID, as allowed by per-
missions. Access Control Lists (ACLs) and Extended Attributes (EAs), including resource forks, will also be preserved.

If the user ID and group ID cannot be preserved, no error message is displayed and the exit value is not altered.

If the source file has its set-user-ID bit on and the user ID cannot be preserved, the set-user-ID bit is not preserved in the copy's permissions. If the source file has its
set-group-ID bit on and the group ID cannot be preserved, the set-group-ID bit is not preserved in the copy's permissions. If the source file has both its set-user-ID and set-
group-ID bits on, and either the user ID or group ID cannot be preserved, neither the set-user-ID nor set-group-ID bits are preserved in the copy's permissions.

-R If source_file designates a directory, cp copies the directory and the entire subtree connected at that point. If the source_file ends in a /, the contents of the directory
are copied rather than the directory itself. This option also causes symbolic links to be copied, rather than indirected through, and for cp to create special files rather
than copying them as normal files. Created directories have the same mode as the corresponding source directory, unmodified by the process' umask.

In -R mode, cp will continue copying even if errors are detected.

Note that cp copies hard-linked files as separate files. If you need to preserve hard links, consider using tar(1), cpio(1), or pax(1) instead.

-v Cause cp to be verbose, showing files as they are copied.

-X Do not copy Extended Attributes (EAs) or resource forks.

-c copy files using clonefile(2)

mv

1
2
3
mv [-f | -i | -n] [-v] source target

mv [-f | -i | -n] [-v] source ... directory
1
2
3
4
5
6
7
8
9
10
The following options are available:

-f Do not prompt for confirmation before overwriting the destination path. (The -f option overrides any previous -i or -n options.)

-i Cause mv to write a prompt to standard error before moving a file that would overwrite an existing file. If the response from the standard input begins with the character
`y' or `Y', the move is attempted. (The -i option overrides any previous -f or -n options.)

-n Do not overwrite an existing file. (The -n option overrides any previous -f or -i options.)

-v Cause mv to be verbose, showing files after they are moved.

ls

to list all files

1
ls [-ABCFGHLOPRSTUW@abcdefghiklmnopqrstuwx1] [file ...]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
The following options are available:

-@ Display extended attribute keys and sizes in long (-l) output.

-1 (The numeric digit ``one''.) Force output to be one entry per line. This is the default when output is not to a terminal.

-A List all entries except for . and ... Always set for the super-user.

-a Include directory entries whose names begin with a dot (.).

-B Force printing of non-printable characters (as defined by ctype(3) and current locale settings) in file names as \xxx, where xxx is the numeric value of the character in
octal.

-b As -B, but use C escape codes whenever possible.

-C Force multi-column output; this is the default when output is to a terminal.

-c Use time when file status was last changed for sorting (-t) or long printing (-l).

-d Directories are listed as plain files (not searched recursively).

-e Print the Access Control List (ACL) associated with the file, if present, in long (-l) output.

-F Display a slash (`/') immediately after each pathname that is a directory, an asterisk (`*') after each that is executable, an at sign (`@') after each symbolic link, an
equals sign (`=') after each socket, a percent sign (`%') after each whiteout, and a vertical bar (`|') after each that is a FIFO.

-f Output is not sorted. This option turns on the -a option.

-G Enable colorized output. This option is equivalent to defining CLICOLOR in the environment. (See below.)

-g This option is only available for compatibility with POSIX; it is used to display the group name in the long (-l) format output (the owner name is suppressed).

-H Symbolic links on the command line are followed. This option is assumed if none of the -F, -d, or -l options are specified.

-h When used with the -l option, use unit suffixes: Byte, Kilobyte, Megabyte, Gigabyte, Terabyte and Petabyte in order to reduce the number of digits to three or less using base
2 for sizes.

-i For each file, print the file's file serial number (inode number).

-k If the -s option is specified, print the file size allocation in kilobytes, not blocks. This option overrides the environment variable BLOCKSIZE.

-L Follow all symbolic links to final target and list the file or directory the link references rather than the link itself. This option cancels the -P option.

-l (The lowercase letter ``ell''.) List in long format. (See below.) If the output is to a terminal, a total sum for all the file sizes is output on a line before the long
listing.

-m Stream output format; list files across the page, separated by commas.

-n Display user and group IDs numerically, rather than converting to a user or group name in a long (-l) output. This option turns on the -l option.

-O Include the file flags in a long (-l) output.

-o List in long format, but omit the group id.

-P If argument is a symbolic link, list the link itself rather than the object the link references. This option cancels the -H and -L options.

-p Write a slash (`/') after each filename if that file is a directory.

-q Force printing of non-graphic characters in file names as the character `?'; this is the default when output is to a terminal.

-R Recursively list subdirectories encountered.

-r Reverse the order of the sort to get reverse lexicographical order or the oldest entries first (or largest files last, if combined with sort by size

-S Sort files by size

-s Display the number of file system blocks actually used by each file, in units of 512 bytes, where partial units are rounded up to the next integer value. If the output is to
a terminal, a total sum for all the file sizes is output on a line before the listing. The environment variable BLOCKSIZE overrides the unit size of 512 bytes.

-T When used with the -l (lowercase letter ``ell'') option, display complete time information for the file, including month, day, hour, minute, second, and year.

-t Sort by time modified (most recently modified first) before sorting the operands by lexicographical order.

-u Use time of last access, instead of last modification of the file for sorting (-t) or long printing (-l).

-U Use time of file creation, instead of last modification for sorting (-t) or long output (-l).

-v Force unedited printing of non-graphic characters; this is the default when output is not to a terminal.

-W Display whiteouts when scanning directories. (-S) flag).

-w Force raw printing of non-printable characters. This is the default when output is not to a terminal.

-x The same as -C, except that the multi-column output is produced with entries sorted across, rather than down, the columns.

The -1, -C, -x, and -l options all override each other; the last one specified determines the format used.

The -c and -u options override each other; the last one specified determines the file time used.

The -B, -b, -w, and -q options all override each other; the last one specified determines the format used for non-printable characters.

The -H, -L and -P options all override each other (either partially or fully); they are applied in the order specified.

By default, ls lists one entry per line to standard output; the exceptions are to terminals or when the -C or -x options are specified.

File information is displayed with one or more <blank>s separating the information associated with the -i, -s, and -l options.

pwd

to show the current path

1
pwd [-L | -P]
1
2
3
4
5
6
7
The options are as follows:

-L Display the logical current working directory.

-P Display the physical current working directory (all symbolic links resolved).

If no options are specified, the -L option is assumed.

cat

1
cat [-benstuv] [file ...]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
The options are as follows:

-b Number the non-blank output lines, starting at 1.

-e Display non-printing characters (see the -v option), and display a dollar sign (`$') at the end of each line.

-n Number the output lines, starting at 1.

-s Squeeze multiple adjacent empty lines, causing the output to be single spaced.

-t Display non-printing characters (see the -v option), and display tab characters as `^I'.

-u Disable output buffering.

-v Display non-printing characters so they are visible. Control characters print as `^X' for control-X; the delete character (octal 0177) prints as `^?'. Non-ASCII characters
(with the high bit set) are printed as `M-' (for meta) followed by the character for the low 7 bits.