which ??
where ?? has been installed; show the full path of shell commands
pwd
where am I
ls -a or -l
-a all, including .file ; -l more details
ls *.txt
list all(*) .txt file
cd -
Back to the previous folder
cd ..
Go up one upper directory layer
!cd
the last command with cd; ! can be used with the other commands
cd ~
Go to $home director
history
check commands that I have used
mkdir
create a directory
cp * .
copy somthing to . (one dot means here-this folder; 2 dots mean the upper layer)
rm sth
remove something
mv ../a ./b
rename or move ../a to ./b (file/folder, including path)
mv a b
rename a to be b
cat myfile.txt
show the file content
cat myfile.txt | less
print less or more
print more
check the last/first few lines
tail myfile.txt
head myfile.txt
tail -n 4 myfile.txt
show the last four lines
wc -l myfile.txt
check how many lines are there
cat myfile.txt| cut -c 2-9
see the specific digits
cat myfile.txt| awk '{if ($1>10), print $line}'
print $line if satisfy the condition
cat myfile.txt| awk '{split($1,a,"/") split ($2,b,"/"); printf "%f %f \n%f %f", a[1], a[2], b[1], b[2]}'
split by given symbols and print
cat myfile.txt| sort -nk 5 -r
sort by the 5th column (-r: reverse); -n (list according to numerical order); -k field (which column)
print $1" "$2
printf '%s %d %.2f', string_test,$2,$3
print with formats
echo "my_notes" > note.txt
write "my_notes" in a new file note.txt
echo "do not cover the existed content in olde file" >> note.txt
by two ">>"
vi myfile.txt
vi or vim to enter the vi mode
Use the following commands to play with the file
i
start to edit, insert words, editing mode
:wq!
save and leave =:x
:q!
leave without save
Esc
leave editing mode
dd
delet the whole line
yy
copy the whole line
p
paste
u
recover the previous step
/keword
n
show next keyword
The last line G
The #n line 1gg
157gg
The #n column in given line n|
:%s/pattern/replacement
Replace the first occurrence of "pattern" with "replacement" on all lines
:[range]s/{pattern}/{string}/[flags] [count]
The command looks for a "{pattern}" on each line in [range] and replaces it with a {string}. The instruction is multiplied by a positive integer called [count]
date
system time variable
grep keywords *
find keywords in all files in this folder
grep -c "linux" long.txt
count (-c) the number of times the pattern repeats
sed SCRIPT INPUTFILE...
sed -i 's/to_be_replaced/replace/' /path/file.txt
replace string by new string in file.txt
find [flags] [path] -name [expression]
searches for files in a directory hierarchy based on a regex expression
nohup commands &
running at the background and would not be interrupted
top
check all operating procedures
htop
check machine’s resources
ps
check the processes your current shell session is running
kill PID
kill project ID
killall -u myname
kill all procedures started by -u username
chmod +x file.txt
make the file exacutable
chmod 700 myfolder
only myslef can rwx, other has no authority for all
r (read=4) w (write=2) x (execute=1) -(nono=0)
owner, ther group member, the others
https://ftp.kh.edu.tw/Linux/Redhat/en_6.2/doc/gsg/s1-navigating-chmodnum.htm
https://www.cs.nccu.edu.tw/~lien/UNIX/Command/chmod.htm
ssh -X, -Y
sshpass -p <my_password> ssh <username>@<hostname>
sshpass -p <my_password> scp <username>@<hostname>:folder/file .
ssh -t XXX001@140.112.XX.XX ssh -t yyyy@140.112.y.yy
go to y station through x station
up/download single file
then, enter password
up/download folder
add -r scp -r
rsync
synchronize data on disk with memory
rsync -P -r
rsync -n source where_to_store
-n skip repeated files
-P, –progress,show progress
-a, –archive
-v, –verbose
-z, –compres
-u, –update
wget
url
git clone
from github
tar
Unzip various file formats
x-> uncompress
c-> compress
lsblk
list unpartitioned and unmounted disks
free -m
RAM size
lscpu
check cpu
df
check hard disk storage
df -h
show for human
df -m
show by MB
du /folder/
check given folder
du -s -h /path_to/folder/
-s summary of this folder
du -h ./folder/ | sort -rn
-rn (reverse), rank according to the size of files in this folder
du -h folder -d 1
show how many layers of directories: -d
or --max-depth=
grep 'core id' /proc/cpuinfo |wc -l
check number of cpu
tree
show the directory tree structure, sudo apt install tree
tree /path/to/directory
add users
sudo useradd
sudo paaword
sudo useradd -f 45 newusr
only 45 days for this newusr
sudo userdel --remove newusr
delet the user and its home directory
sudo usermod -aG sudo newuser
assign newuser as a superuser
su - newuser
switch user
passwd
change password
last username
login history
sudo umount -f
-f force
mount
mount
reformat
RAID mdadm
ln -s ../foler/store ./link
create a soft link: the "link" will point to "store"
IPtable