-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnotes.txt
238 lines (183 loc) · 6.97 KB
/
notes.txt
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
ls
-- list the contents of the directory
ls -l
-- list, long (the contents of the directory)
-- permissions: read/write/execute status
** -- drwxrwxrwx (directory, read, write, execute ... )
** -- drwx...... the user permissions (who created it)
** -- d...rwx... the group permissions
** -- d......rwx the public permissions
-- user setting
-- group setting
-- size
-- date
-- filename
ls -a
-- list, all (the contents of the directory)
-- shows hidden files (dot-files)
ls /etc
-- list, the contents of the etc directory
clear
-- clear the contents of the console
less filename.txt
-- opens a simple text editor like vi or nano.
more filename.txt
-- opens a simple text editor like vi, nano, or less.
cat filename.txt another_file.txt
-- displays the output of multiple files (as though they
were concatenated)... if you only list one file it
will concatenate it with nothing, and it's just used
to print out the files. If you don't save the output
to a new file, cat will not automatically save it for you.
nano filename.txt
-- opens a simple text editor like vi, more, or less.
mv oldname.txt newname.txt
-- move the file from one location (name) to another (name).
This can be used to rename a file.
mv oldname.txt directoryname/
-- move the file from the current directory to the new directory
using the same name. This command will move oldname.txt from
the current directory to directoryname/oldname.txt
mv directoryname/oldname.txt .
-- move oldname.txt to the current directory ( . )
mv oldname.txt directoryname/newname.txt
-- move the file and rename it
mv old_dir/ new_dir/
-- move (rename) the directory from old_dir/ to new_dir/
cp oldfile.txt newfile.txt
-- copies the file from oldfile.txt to newfile.txt
cp old_dir/ new_dir/
-- NO... copy will not work on directories without the
recursive flag (see below)
cp -r old_dir/ new_dir/
-- copies a directory (and all the files within it) into a
new directory
rm filename.txt
-- remove (delete) the file, permanently
rm old_dir/
-- NO... remove will not work without the recursive flag
rm -r old_dir/
-- remove the directory (and all the files within it), permanently
mkdir new_dir/
-- makes a directory named new_dir
mkdir new_dir/sub_dir/subsub_dir/
-- NO... make directory won't make nested directories without the
-p flag (paths? permissions?)
mkdir -p new_dir/sub_dir/subsub_dir/
-- make nested directories
whoami
-- print the name of the current user (probably displayed in the pompt)
sudo
-- superuser do, a method for running a command that requires permissions
greater than the permissions assigned to the current user
sudo adduser newusername
-- add a user to the system named newusername. It creates a user 'newusername'
it also creates a group 'newusername' and it creates a new user 'newusername'
with the group 'newusername.' It also creates a new directory for 'newusername'
which is the home directory for this user. Creating a user also prompts us to
enter information about the user: password, full name, room number, work phone
home phone, and other.
su newusername
-- switch user to 'newusername.' It seems like it's kinda 'virtual' because if
you exit from the switch user command you return to the user you were in before
exit
-- will pull you out a switch user (su) command. It will also log you out of an
ssh connection.
PERMISSIONS
-- r = read
-- w = write
-- x = execute
-- u = user level permissions
-- g = group level permission
-- o = other (world) level permission
-- drwx-rwx-rwx (d = it's a directory, no d = it's a file)
-- drwx-rwx-rwx (dir) (user) (group) (other)
-- if a permission is written it's true, if it's a dash it's false.
chmod [u/g/o][+/-][rwx] filename
-- change the mode (permissions) of the file
Example: chmod o+w filename
Octal Permissions
-- r = 4
-- w = 2
-- x = 1
rwx = 7
rw- = 6
r-x = 5
r-- = 4
-wx = 3
-w- = 2
--x = 1
--- = 0
chmod [1-7/1-7/1-7] filename
-- change the mode (permissions) of the file using octal codes. The first set of
octal codes is for the user. The second for the group. The third for other.
chown username filename
-- change the owner of the file. If you don't have the proper permissions you
may need run the command as a superuser (i.e. sudo chown username filename)
chown username:group filename
-- change the owner and the group of the file. You may need sudo.
notes on the root user
-- root is all powerful, this user can override all permissions on every file
and directory on the computer.
sudo
-- allows you to run a command as the root user, without explicitly switching
to root or knowing the root password
!!
-- run the last command I ran again (double bang)
sudo !!
-- append the last command to sudo, so that I don't have to retype everything
if i realize I needed sudo
top
-- a process manager that shows you real-time info about processes running
on the computer
ps
-- shows the processes that are running
ps aux
-- aux are options, usually they'd be passed with hyphens, but not here.
aux will show all of the processes running on the computer, for all
the users
ps aux | grep "top"
-- show all the processes and then pipe "|" the results to a grep search
which looks for the pattern "top" and then only returns results that match
[Control-Z] (or Command-Z since I remapped it)
-- a shortcut for pausing a process and making it a job that I can start
and stop when I want to move between programs
fg
-- foreground brings the (most recently used) job to the foreground
fg [1-n]
-- bring job [number] to the foreground
jobs
-- list all the jobs running
[command] &
-- placing the ampersand "&" after a command will automatically move it to
the background and place it in the jobs list. ... There seems to be an
error with getting my system to place the job in the background instead
of stopping it.
kill [PID]
kill -TERM [PID]
kill -SIGTERM [PID]
-- Kills the process that matches the process ID. By default it shuts down
the process and allows it to exit gracefully (close files, etc.). Find
the PID using "top" or "ps aux" or "ps aux | grep PROGRAMNAME"
kill -KILL [PID]
kill -SIGKILL [PID]
kill -9 [PID]
-- Kills the process that matches the process ID. Forces the process to
quit. It seems like the force quit option in OSX's Activity Monitor
kill -STOP [PID]
-- Kills the process that matches the process ID and stops the job. It's
similar to hitting Control-Z and pausing the process.
env
-- Print the environmental variables
$ENVNAME
-- The value of an environmental variable
ENVNAME="Value of the environmental variable"
-- Set/create the environmental variable with that value
echo
-- Echo back (print) the arguments that are passed to it. (e.g. echo $HOME)
returns the value of the HOME variable
export ENVNAME="new value"
-- Set the environmental variable and save it to .bashrc (or .bash_profile)
export PATH=/new/path/to/bin:$PATH
-- Add a new dir path to the PATH variable, and then append the existing
PATH variable by calling the variable ($PATH)