1. 首先用 LiveCD 開機,選擇 Try Ubuntu MATE
3. 接著輸入 sudo mount /dev/sda1 /mnt,將 sda1 掛載到 /mnt 目錄
然後輸入 sudo chroot /mnt,這時提示符號會成為 #
然後輸入 passed root ,更改 root 密碼
如果使用者密碼也需要更改就 passwd user-name
4. 輸入 sudo umount /mnt ,將 /mnt 目錄卸載,重新開機即可。


解答:
#!/usr/bin/awk -f
BEGIN {
}
{
sub(/#.*/,"") # change #.* to ""
for (i=1; i<=NF; i++) {
if ($i ~ /^[0-9]/) { #-----$1 is number
money=$i
if (i==2 || i==3) { #-----money is spends or loses
name=$(i-1)
array[name]=array[name]-money
}
} else { #-----$1 is name
name=$i
money=$(i-1)
array[name]=array[name]+money
}
} #for END
}
END {
for (name in array)
printf("%s has %s\n", name, array[name])
}
執行結果:
解答:
#!/bin/bash
olddir=$PWD
dirdepth=0
function is_last_file {
local flag
let flag=${ary[dirdepth]}-1
if [ $flag -eq 0 ]; then #last file
ch="\\" #as \---
else
ch="|" #as |---
fi
}
function print_file {
is_last_file #check this file is last?
case "$1" in
-D) printf "$ch---$2/\n"
;; #file is directory
-L) printf "$ch---$file --> "
ls -l $file | awk '{ print $11 }'
;; #file is link
-F) printf "$ch---$file\n" #normal file
;; #file is normal file
esac
let ary[dirdepth]=ary[dirdepth]-1
}
function check_file_type {
if [ $dirdepth -gt 0 ]; then
for ((i=0; i<=dirdepth-1; i++)); do
if [ ${ary[i]} -ne 0 ]; then
printf "| " #print | & 3 space
else
printf " " #print 4 space
fi
done # for END
fi
if [ -d "$file" ]; then
print_file -D $file #directory
else
if [ -L $file ]; then
print_file -L $file #symbolic link
else
print_file -F $file #normal file
fi
fi
}
function listfiles {
cd "$1";
f_count=`ls -l | wc -l` #calc total files
let f_count=f_count-1
ary[dirdepth]=$f_count
if [ $f_count -ne 0 ]; then # if dir is empty then exit
for file in *; do
check_file_type $file #call sub
if [ -d "$file" ]; then
let dirdepth=$dirdepth+1
listfiles "$file"
cd ..;
fi
done #for END
fi
let dirdepth=$dirdepth-1
}
#-----Main Program 2017/12/06 update-----
#d=$1
#echo "${d##*/}/"
echo "$(basename "$1")/"
listfiles "$1"
執行結果:
$ ./hanoi 2 # move 2 discs, from A to B by C from A to C from A to B from C to B $ ./hanoi 3 # move 3 discs, from A to B by C from A to B from A to C from B to C from A to B from C to A from C to B from A to B $
解答:
#!/bin/bash
function move_disc {
if [ $1 -ne 0 ]; then
move_disc $(($1-1)) $2 $4 $3
echo from $2 "to" $3
move_disc $(($1-1)) $4 $3 $2
fi
}
#-----Main Program-----
disc=$1
if [ $disc -gt 0 ]; then
move_disc $disc A B C
fi
執行結果:
執行結果:
執行結果:
