Ad

Sunday, June 17, 2018

Command Line basics


$less
space commands take us to the end of an document

$cat can take two files separated by a space
nano full screen program. Mainly used to edit a file

Move is very powerful for moving files around and renaming them. Move is also very powerful for moving directories.

$mv within the same directory

mv filename1.txt filename2.txt is just like rename

if instead say

mv filename.txt documents/ it is just to move doc to new directory

dot is a short cut for the current directory

cp can leave the original file in place, just like copy.

cp hello.txt hi.txt

Can't just copy a directory, but need to copy recursively,

$cp -r sourcedirectoryname destination directoryname

$rm command is very dangerous via command console

make directory $mkdir

cannot recurse, creating nested directory lil document/notes/console

mkdir -p documents/notes/console/part_1
this chaining works for nested directories


Create User Managing Users
console command:
print out the name of the user
$whoami

add a new user

$sudo adducer user_name

switch user

$su user_name

switch back to the previous user

$su previous_name

or can use exit which stops the previous su command


$exit

User permission
rwx read write execute
ugo user group other
drwxrwxrwx  d for directory, 9 permissions in ufo order
chmod change mode also changes permission
e.g.
$ chmod o+w hello.txt
$ chmod o-w hello.txt
$ chmod +x hello.txt (add execution for everyone)

Octal Notation:
01234567
10 11 12 13
one eight
one eight one one
one eight two one

r = 4 w = 2 x =1
first digit  = u
2nd digit = g
3rd digit = o

rwx = 7 --- = 0
r-x = 5, -w- = 2

e.g. chmod 751 hello.txt

File Owner Ship
$sudo chown username filename.txt
will be prompted for password
$cat filename.txt
$nano filename.txt
but with nano not able to write, only view after changing owner
CHANGING GROUP NAME
$sudo chown username:groupname filename.txt
$su username
CAN NOW MODIFY because username is the same as the owner. Before when looking at ano with a the old owner which no longer have write permission
$nano filename.txt

$sudo
a super user command, run as root super user without having to know the password etc, sudo grants permission to other users, will requires own password not the root user password,

$!! runs the previous command
$sudo !!

Process
When running nano which is a program, creates a process, which is a running instance of the program. There can be multiple instances.
task manager for processes, resources consumed like memory or CPU, process has an ID, owner,
$top
question mark key brings up help function
e.g. sort the processes
capital F allows sorting
q to quit the program

Another program , will list out all the processes, represent running processes
$ps
(can see bash, and ps) ps is itself a program that creates a process, only in the current session
$ps aux
all process for user x, mean all processes for all users. it is not an interactive program. good for knowing what's running and what is the process ID. PID

Getting specific with piping, grep takes some input search for pattern only return lines with the pattern on it. This will also show up in its own ps search.
$ps aux | grep "top"

No comments:

Post a Comment

React UI, UI UX, Reactstrap React Bootstrap

React UI MATERIAL  Install yarn add @material-ui/icons Reactstrap FORMS. Controlled Forms. Uncontrolled Forms.  Columns, grid