记录自己在使用linux中渐渐使用的命令和一些方法。
在一个终端中打开另一个窗口
ctrl + shift + t
回到上一次目录
cd -
列出当前登录用户
w
Linux进出sudo的方法
进入
sudo
mode =sudo -i
退出sudo
mode =ctrl + d
grep(general regular expression print)
ls | grep "linux"
= List file that its name includes string “linux”.Clear commands history
history -c
终端锁定与退出锁定(终端无法输入的假死问题)1
- 终端锁定
ctrl + s
- 退出锁定
ctrl + q
- 终端锁定
File permission
chmod
Change mode. 10number =d
(directory) or-
(that represents file) Permission =r
= (100)2 //4w
= (010)2 //2x
= (001)2 //1 eg.chmod 777 file/dir
// Give file/dir rwx permission.
chgrp
Change file group.chown
Change file owner.
Change font size in terminal
Change bigger =
ctrl -
Change smaller =ctrl +
Rename
将test.jpg改成test1.jpg
mv {test,test1}.jpg
在linux中跳出很深的文件夹,如果没有记住文件路径,就要一层层
cd
过去,浪费很多的时间。解决方法1 在
/etc/profile.d/
目录下新建例如dd.sh
文件,文件内容如下alias dd='cd /media/folder1/folder2/.../'
接下来保存退出
source dd.sh
效果 = 在命令行中输入
dd
即可实现挑入指定目录。 并且重启之后在命令行中依然生效。解决方法2 在
~/.bashrc
中添加alias dd='cd /media/folder1/folder2/.../'
也可以有同样的效果。
Linux光标移动
ctrl + a
= 行首ctrl + e
= 行尾ctrl + f
= 光标右移ctrl + b
= 光标左移esc + f
= 右移一个单词esc + b
= 左移一个单词Linux
mv
功能 (1) 修改名称 (2) 移动文件Bash (1) 注释 =
#
(2)#!/bin/bash
的意义 以#
代表是个注释,但是#!
并不是注释了,它用来指明这个脚本所需要的Shell
(3) shell变量类型 变量类型只有字符串caps -> ctrl(reference 32)
Download video in CLI (1) you-get (2)youtube_dl
du(disk usage)
ctrl + u
= 从光标处删除文本直到行首ctrl + k
= 从光标处删除文本直到行尾alt + f
= 向后一个单词alt + b
= 向前一个单词重复使用上一个命令:
!!
dstat
View the net speed in late 10 seconds and other functions.Symbolic links
I/O redirection
I/O redirection allows us to change where output goes and where input comes from. Normally, output goes to the screen and input comes from the keyboard, but with I/O redirection we can change that.
The Letter-Based Method
In addition to the method described above there is a second way to change permissions. Chmod uses either the hexadecimal representation of the permissions or a letter-based representation. The letter-based representation is [ugoa][+-][rwx]. This is one of the letters u (user=file owner), g (group), o (others), a (all users, groups and others); followed by + or - to add or remove permissions; and then the symbolic representation of the permissions in the form of r(read) w(write) x(execute). To extend Write permissions to all for the file “file.txt”,
For example, you would type
chmod a+w file.txt
uptime
Tell how long the system has been running.Change user
su [username]
退出此用户:
exit
Add user
useradd [username] passwd [username]
Delete user
userdel [-r] [username]
-r = remove the home dir of [username]
Print current effective user
whoami
linux将cpas->ctrl
(1) Edit
/etc/default/keyboard
# KEYBOARD CONFIGURATION FILE # Consult the keyboard(5) manual page. XKBMODEL="pc105" XKBLAYOUT="cn" XKBVARIANT="" - XKBOPTIONS="" + XKBOPTIONS="ctrl =nocaps" BACKSPACE="guess"
(2) 运行如下命令,设置生效
sudo dpkg-reconfigure keyboard-configuration
cp 排除某个目录 例. 有目录b, c, 复制到
/f
下,排除bcp -r !(b) /f
在linux下弹出u盘命令(假设u盘设备是sdb1)
sudo eject -s /dev/sdb1
ccat
内置的
cat
查看命令没有语法高亮,但是使用ccat
可以有这个作用。下载二进制代码文件
wget https =//github.com/jingweno/ccat/releases/download/v1.1.0/linux-amd64-1.1.0.tar.gz
解压
tar xfz linux-amd64-1.1.0.tar.gz
将
ccat
文件复制到/usr/local/bin/
文件夹下cp linux-amd64-1.1.0/ccat /usr/local/bin/
使用
ccat
命令查看文件会发现文件显示变成彩色的了。ssh & public key
(1) 本地生成公钥
ssh-keygen -t rsa
之后全部默认回车即可。
(2) 将本地公钥
~/.ssh/id_rsa.pub
复制到远程主机~/.ssh/autoorized_keys
文件中,如果目录和文件皆不存在,直接创建新的文件。 (3) 重启ssh服务service ssh restart
之后与主机相连就不必再输入密码。
ls
的-S
选项sort by WORD instead of name = none (-U), size (-S), time (-t), version (-v), extension (-X)
准确来说就是将文件从大到小进行排序。
tab
- 命令补全 = tab接在一串指令的第一个字的后面
- 文件补齐 = tab接在一串指令的第二个字的后面
find
$ find dir_name -name filename_to_be_searched
在 bash 里,使用
Ctrl-R
而不是上下光标键来查找历史命令。使用
man ascii
来查看 ASCII 表。命令行注释命令:
alt + #
Linux各目录
/etc
- 含义: and so on
- 功能: 存放零零碎碎的东西
linux各种解压命令汇总
.tar.xz
$xz -d filename.tar.xz
$tar -xvf filename.tar
tar.gz
tar -zxvf xxx.tar.gz
.rar
unrar e file.rar # e = 解压压缩包中的全部问价至文件夹
今天因要下载win10 iso文件,奈何文件太大,只好利用winrar软件将4g的iso文件分成了4个1g的小文件,转到linux下后,直接将4个小文件提取了出来,但问题是4个提取出来的文件并没有合并在一起,这可不是我想要的结果,百度一查,赶紧在linux安装了rar,只需用rar e name.part1.rar
,提取后的文件就是合并后的文件了。
Problems
在ubuntu19.01上安装curl出现问题curl = Depends: libcurl4 (= 7.58.0-2ubuntu3.8) but 7.65.3-1ubuntu3 is to be installed
问题如下
The following packages have unmet dependencies =
curl = Depends: libcurl4 (= 7.58.0-2ubuntu3.8) but 7.65.3-1ubuntu3 is to be installed
E: Unable to correct problems, you have held broken packages.
解决方法:
sudo apt-get purge libcurl4
接下来就可以正常安装curl
了。
linux升级gdb
gdb官网下载太慢,清华大学镜像站可以下载。