在Linux中变量#, @,0 ,1,2, *, $$, $?
的含义:
# Standardouput.sh
echo "Number of parameters passed to the script:$#"
echo "The name of the script itself:$0"
echo "The first parameter passed to the shell script:$1"
echo "The second parameter passed to the shell script:$2"
echo "List of all parameters passed to the script:$@"
echo "Display all the parameters passed to the script in a single string:$*"
echo "ID number of the current process the script runs:$$"
echo "Is to display the exit status of the last command. 0 indicates no error, and others indicate error: $?"
~ % bash Standardoutput.sh 1 2 3
source
:使刚修改过的文件生效
source .vimrc
sed
: stream editor
系统安全
scutil
: Manage system configuration parameters
scutil --get ComputerName # get computer name
sudo scutil --set ComputerName xxx # set computer name
scutil --get HostName
sudo scutil --set HostName xxx # set host name
scutil --get LocalHostName
passwd
: modify a user’s password
install
: install binaries
sudo
: substitute user identity
chown
:change file owner and group
chmod
:change file modes or Access Control Lists →博文
reboot
: stopping and restarting the system
shutdown
: close down the system at a given tim
帮助命令
xxx --help
: 查看命令xxx的帮助。
man xxx
:format and display the on-line manual pages
常用命令
ls
:list directory contents.
ls -a # 列举当前目录所有文件,包括隐藏文件
ls -r # 正常列举顺序反序化输出
ls -t # 按照文件修改时间排序输出
ls -s # 按文件大小排序输出
ls -l # 列举文件名、文件权限、所有者、文件大小等信息
cd
:切换目录
cd - # 切换上次目录
cd ~ # 切换到主目录
cd / # 切换到根目录
cd . # 切换到当前目录
cd .. # 切换到上一级目录
显示信息
env
: set environment and execute command, or print environment.
history
:GNU History Library. ↑
/↓
clear
: clear the terminal screen.
系统信息
who
: display who is logged in.
whoami
: display effective user id.
tty
:print the file name of the terminal connected to standard input.
stty
:change and print terminal line settings. stty -a
du
:estimate file space usage. du -k subdir
df
:report file system disk space usage.df /tmp
du -sh pytorch_model.bin # 查看某个文件大小
文件操作
pwd
:return working directory name
tree
list contents of directories in a tree-like format. tree dirname
mkdiir
make directories.
rmdir
remove empty directories.
rm
remove files or directories.
rm file # 删除文件
rm -f file # 强制删除文件
rm -r dir # 删除目录下所有文件,包括目录本身
rm -rf dir # 强制删除目录下所有文件,包括目录本身
cp
copy files and directories.
cp file1 file2 #
cp -f file1 file2 # 若目标文件已存在,则会直接覆盖原文件
cp -i file1 file2 # 若目标文件已存在,则会询问是否覆盖原文件
cp file1 file2 dir/ # 复制多个文件到指定目录下
cp -r dir1 dir2/ # 递归复制文件和目录
mv
move files or rename.
mv file1 file2 # rename file2
mv file1 ../dir/
mv -r ../dir1 ../lizhong/dir2
mv -b file1 ../dir/ # 覆盖之前先备份
mv -f file1 ../dir # 强制覆盖文件
mv -i file1 ../dir # 覆盖文件之前会先询问
open
:open files and directories
open . # 打开当前目录
open file1 # 使用默认程序打开文件
open *.txt # 使用默认程序打开批量文件
open -a application file #使用指定程序打开文件
# linux 三个主要变动时间:
# mtime(modification time) 当文件的内容变更时,更新该时间。(不是文件的属性或权限)
# ctime(status time) 当文件的状态改变时,更新该时间。(eg. 文件权限与属性)
# atime(access time) 当文件的内容被读取是,更新该时间。(eg. cat命令读取文件)
head
output the first part of files.
tail
output the last part of files.
cat
concatenate and print files.
tac
concatenate and print files in reverse.
more
file perusal filter for crt viewing.
less
opposite of more.
touch
change file access and modification times.
head -n 5 file1 # 输出文件的前5行
head -c 5 file1 # 显示文件的前5个字符
cat -n file1 # 显示文件行号
touch test.txt # 创建一个空文件
more # space 代表向下翻1页 enter 代表向下翻1行 /字符串 向下搜索关键字
#f 显示文档名, 目前显示行数
less # 功能更强大
#?字符串 向上搜索关键字
file
determine file type. file filename
nl
line numbering filter.
wc
word, line, character, and byte count.
nl filename
wc filename
colrm
remove columns from a file.
diff
compare files line by line.
diff -r dir1 dir2
diff file1 file2
comm
: select or reject lines common to two files
uniq
: report or filter out repeated lines in a file
sort
:sort or merge records (lines) of text and binary files
awk
: pattern-directed scanning and processing language
paste
: merge corresponding or subsequent lines of files
xxd
xxd` file1 # 以十六进制形式显示文件
iconv
-f gb2312 -t utf-8 filename1 > filename2:文件编码转换
cut
: cut out selected portions of each line of a file
cut -c num1-num2 filename 显示文件每行从头开始 num1 到 num2 的字符
批文件:GBK—>UTF-8
mkdir newdir # 新建文件夹,放置批文件
find *.find *.txt -exec sh -c "iconv -f gbk -t utf-8 {} > {}.txt" \;
编程操作
make
:维护可执行程序的最新版本
touch -m 05202400 filename
:更新文件的访问时间和修改时间
时间操作
date
: display or set date and time
cal
: displays a calendar and the date of Easter
cal 6 1996
time
: time command execution
time a.out
网络通信
ping
: send ICMP ECHO_REQUEST packets to network hosts
ping baidu.com
mail
: send and receive mail
ifconfig
: configure network interface parameters
top
:display sorted information about processes
ps
: process status
w
:display who is logged in and what they are doing
kill
: terminate or signal a process
查找命令
which
: locate a program file in the user’s path + 在环境变量$PATH
设置的目录里查找 which java
, which python
whereis
:The whereis utility checks the standard binary, and manual page directories
for the specified programs, printing out the paths of any it finds.
whereis java
whereris python
locate
: Postfix local mail delivery
find
:walk a file hierarchy
find . -name ‘*.md’
mdfind
: finds files matching a given query
sed
grep
:The grep utility searches any given input files, selecting lines that match one or more patterns.
==grep "root" /etc/passwd==
docker
命令