Linux/Ubuntu Commands
Use
lshw
(list hardware) to show the computer hardware information.Use
uanme -a
to show system information.tar
1
2
3
4
5
6tar –xvf file.tar # unzip .tar
tar -xzvf file.tar.gz # unzip .gz
tar -xjvf file.tar.bz2 # unzip .bz2
tar –xZvf file.tar.Z # unzip .Z
unrar e file.rar # unzip .rar
unzip file.zip # unzip .zipShow the structure of current directory.
sudo apt install tree
tree -L N
show \(N^{th}\) depth.
#!/bin/bash
indicates the path to shell. It can only be placed at the top of shell script and begun with#!
.#!
is known asshebang
in Unix.- This command is used to instruct our system to use
bash
as default shell.
vim
:set number
to show the line number.vim
comment out a block (in a shell script#
):10,20s/^/#/g
to comment out a block from line 10 to 20:10,20s/#//g
to delete the comments.
vim
delete a line: click the line->exit Insert mode->double press d in your keyboardHow to calculate the time consumption of a shell script. Here is an example. Pay attention to the spaces in this script.
1
2
3
4
5
6
7
8
9
10
11!/bin/bash
startTime=`date +%s`
for ((i=1; i<=100; i++)); do
a=$[$i%20]
if [ $a -eq 0 ]; then
echo "i: $i"
fi
done
endTime=`date +%s`
consumedTime=$[ $endTime - $startTime ]
echo "Time consumed: $consumedTime seconds"How to show the folder size in terminal.
du
: summarize disk usage of the set of files, recursively for directories.1
2
3du -sh # show the size of current folder
du -h # show the sizes of all subfolders/files (recurssively)
du -h <folder name> # show the sizes of indicated folder/filesfind .|xargs grep -ri "characters you want to find"
search all files under current directory to find specific characters.The default editor in Ubuntu is GNU nano. You may dislike it, so please use vim in default.
sudo update-alternatives --config editor
- choose
vim.basic
source ~/.bashrc
If you cannot type in terminal, you may happen to press
CTRL+S
which locks screen. Just pressCTRL+Q
to exit.