It is possible to install Linux on cloud server too.
But now we are not going into this topic.
tty
know how to open tty. (ctrl+alt+f2)
linux file management
all things in linux is files, and there is only one root directory : /
e.g. /usr/bin (space is valid in linux)
root files (command ls /):
bin dev home lib64 mnt proc run srv tmp var
boot etc lib media opt root sbin sys usr
root
/ / | \ \
home dev bin etc usr
/ / \ \
mo(~) ... bin lib games
users’ private directory: /home/mo
mnt–>mount
opt–>optional application
sbin–>system binary
srv–>service
tmp–>temporary
usr–>Unix Software Resource
how to locate current directory: pwd (print working directory), which+ command (locate program pos)
Common File commands
1.ls
some args: -a –> all (include hidden files) .–>current directory ..–>previous directory
2.-l list files with details
cols: 1–>prority 2–> link 3–> owner 4–> group 5–>size cols after this–> date created
3.-h human readable
4.-t sort according time
5. cd change directory
it is important to know diffs between absolute/relative path
6. du disk usage
7. cat/less show file content
more–> too old command, forget it!
[space]–> next page, [enter]–> one line, [d]–>half page, [b]–>prev page, [y]–>prev line, [u]–>prev half page, [q]–> exit, [=]–> show page pos, [h]–>help,[/]–>search, [n]–>next search res,
Regular expression is valid in less.
8. head/tail show file head/tail
9.touch/mkdir create file, make directory
mkdir -p one/two/three/…
10.cp/mv copy and move
cp [file_name] [file_name_copy]
cp [file_name] [directory] or cp [file_name] [directory]/[file_name_copy]
how to copy dir: cp -r [directory_name]
*universal symbol: .txt
mv just move the file does not make copies, it can be used to rename the file
mv [file_name] [renamed_file_name] [new_directory_path]
11.rm remove
args: -i ask delete or not -f forced to delete file -r delete recursively
if you wan to delete a directory recursively, use:
1 | sudo rm -rf [directory_name]/ |
12.ln link
physical: linked file share the same content (cannot linked to dir)
symbolic: can linked to dir
n file1 file2 (ls -i can show inode detail) physical one
ln -s file1 file2 symbolic one
file= [file_name]+[priority]+[content], content–> ‘inode’ marked
Authority and priority (system security)
1. sudo (substitute user do)
root user > groups–> family, friends…
2. log in as root user–> sudo su / su root (or su - or just su)
3. some command for root user:
useradd [user_name]
passwd [user_name]
userdel -r (means –remove) [user_name]
4. Groups management:
groupadd [group_name]
usermod -g [group_name] [user_name] –>used to modify user’s account (-l rename, -g re-group)
e.g. add to multiple groups: usermod -G friends,happy,funny jen
add one account to another group without leaving current group: usermod -aG happy mo
groups [user_name]–> locate group
groupdel [group_name]
chown [user_name] [file_name]–> change owner (-R,recursively set child directory and child files)
chgrp [user_name] [file_name]–> change group
e.g. a complex one: chown mo:friends file.txt–> change the owner of file to mo and group to friends
e.g. if you want to take all the files of your friends jen…
chown -R mo:mo /home/jen
chmod –> change access authority (you can use this when you are the owner of this file)
d: directory, l:link, r:read ,w:write, x:execute ‘.’ on 11th pos: SElinux security label
d/l/- (file type: directory, link, normal file) rwx (owner) rwx(group users) rwx (other users)
r=4, w=2, x=1, the sum of rwx represent access types
777–> rwxrwxrwx
or you can use alphabets: u, g, o. +-=
e.g chmod u+rx file –> user add read and x rights
chmod u+r go-r file–>?
chmod +x file–> all users add x rights
chmod u=rwx,g=r,o=- file –> user has rwx, group user has read, others have nothing
-R–> chmod recursively e.g. chmod -R 700 /home/mo–> change all files on PC so that only I can operate them
Nano text editor
some useful args:
-m–> activate mouse
-i–> activate auto tab
-A–> smart Home
.nanorc settings file (usually seting file end of ‘rc’–>run command)
you can write it yourself:
set mouse
set autoindent
set smarthome
global nanorc settings: /etc/nanorc (use sudo to modify)
bash terminal settings: .bashrc (priority greater than) global one:/etc/bashrc
profile setting (config file for tty interface)
*important: activate the modified setting files immediately: source .bashrc
Software Repository (install software safely)
in windows: .exe
in centOS: Package: .rpm (RED HAT PACKAGE MANAGER) for other family debian/Ubuntu :.deb
Dependencies: libs (e.g. GIMP import other libs)
Problem: how to find the closest repository to improve the update of system?
change the repository settings using nano in /etc/yum.repos.d/CentOS-Base.repo
find the source in: CentOS Mirrors
graphical manager: application installer
rpm manager: yum
args: update/upgrade install/remove/autoremove
local rpm packages:
sudo rpm -i [package_name].rpm–> install
sudo rpm -e [package_name]–> remove
RTFM handbook (read the fucking manual)
man (update manual: sudo mandb)
man+#+[func_name]
args in man: learn how to read manual
search specific command: apropos [command_name]
other options: -h –help or whatis[something]
How to search file
locate (it will only look at file database–>include file lists and locations but no really on the hard disk, Linux will update this database every 24 hours, but we can use updatedb to do it)
find (find exact hard disk)
find [where] -name [what][do-what]
e.g. find file named “syslog” in directory /var/log (might need root)
find /var/log -name “syslog”
how to find things in entire drive: find / -name “XXX”
find based on size: sudo find /var -size +10M (files greater than 10 Mb, likewise, less than is ‘-‘)
based on access time: find -name “*.txt” -atime -7 (txt files accessed in less than 7 days)
based on type: -type d/f (this write after file_name)
ops on the search res:
-printf “format”–> print the result
-delete –>delete resultant files
-exec–> execute built-in commands e.g. find one -name “*.txt” -exec chmod 600 {} ;
(-exec can be subtitute as -ok)``