More on CLI

about me

  • Peter
  • fb.me/petercheng.tech

why need permissions?

Users & groups

users

show users currently logged

similar to: who

groups [OPTION]... [USERNAME]..

e.g.

peter : peter adm cdrom sudo plugdev lpadmin

id

e.g.

uid=1000(peter) gid=1000(peter) groups=1000(peter),4(adm),24(cdrom),

27(sudo),30(dip),46(plugdev)

Permissions

(755)?

ls -l

e.g.

total 112
-rw-r--r--  1 peter peter 33858 Oct  1 03:41 a.png
drwxr-xr-x  3 peter peter  4096 Nov 18 21:31 Desktop
drwxr-xr-x  2 peter peter  4096 Jul 25 07:59 Documents
drwxr-xr-x  4 peter peter  4096 Nov 20 14:49 Downloads
 

source: 鳥哥

source: 鳥哥

what is 755?

interpret file permission as binary

r: 4

w: 2

x: 1

rwx: 7

r-x: 5

==> -rwxr-xr-x: 755

$ chmod

change permissions?

e.g.

chmod -x file

chmod -R 777 file

chmod 644 file

chmod +w file

$ chown [-R] <user>:<group> file

change file owner

e.g.

chown peter file

chown peter:admin file

Sudo

what if we need more then our privilege?

use sudo

sudo + command

Links

soft link v.s. hard link

source:

https://askubuntu.com/questions/108771/what-is-the-difference-between-a-hard-link-and-a-symbolic-link

make links

$ ln [-s] origin-file link-file

e.g.

ln myfile hard-link

ln -s myfile soft-link

monitor your server

ps

not photoshop

list process

$ ps [option]

e.g.

ps -a

ps -au

ps -aux

what if i see strange process

kill it!!

[just kidding]

kill command

$ kill -<signal> process-id

kill -TERM webserver

kill -9 myprogram

usefull software

htop

multiple screen

tab?

tmux

automation?

no no

just shell script

shell

a shell command interpreter

Variable

only string t

  • show environment variables

$ env

  • show one variable

$ echo $myvar

  • assign variable

$ myvar=var1

simplest idea

  • collect the command you always use
  • write them into one file
  • execute it

io redirection

pipe

redirect the io

  • cat <( ls -l ) #redirect input
  • ls -l | cat #redirect output

iterate through args

  • xargs
  • ls | xargs -n1 <cmd>

usefull software

  • crontab

Makefile

  • make
  • write Makefile
  • automate build process
  • check dependency for you

Q&A

More on CLI

By Peter Cheng

More on CLI

  • 854