创建新用户,并且把该用户添加到sudo组:
sudo adduser newuser
sudo usermod -aG sudo newuser
可能需要从当前用户这里复制一些文件:
sudo cp /home/me/* /home/newuser/ -rf
sudo chown -R newuser:newuser /home/newuser/
ssh-keygen -t rsa -f /tmp/key
sudo cp /tmp/key.pub /home/newuser/.ssh/authorized_keys
ssh 私钥就是 /home/key
离线
收缩vmware虚拟机文件:
sudo vmware-toolbox-cmd disk shrink /
最后一个参数是硬盘挂载点
这个命令挺有用,久久执行一次硬盘可以腾出几十G
离线
vi 删除 # 开头的行, 如 .config 文件
1)删除以#开头的行
:g/^#/d
2).删除空行
:g/^s*$/d
离线
dd if=/dev/zero of=xxx bs=1M count=yyy
tar xvf file [-C destfolder]
ln -s target symlink
df -m
ls -la
离线
计算一个表达式用 $(( ))
#echo $((14*17))
238
# a=10;b=20;echo $(($a*$b))
200
离线
删除0字节文件
find -type f -size 0 -exec rm -rf {} \;
获取 IP 地址
ifconfig eth0 |grep "inet addr:" |awk '{print $2}'| cut -c 6-
或者
ifconfig | grep 'inet addr:'| grep -v '127.0.0.1' | cut -d: -f2 | awk '{ print $1}'
统计一下服务器下面所有的 jpg 的文件的大小,写了个 SHELL 来统计。
原来用 xargs 实现,但他一次处理一部分。搞的有多个总和……,下面的命令就能解决。
find / -name *.jpg -exec wc -c {} \;|awk '{print $1}'|awk '{a+=$1}END{print a}'
离线
$expr substr abcdefghijkl 2 7
bcdefgh
$
$ expr 3 + 4
7
$
$ expr 3 - 4
-1
$
$ expr 3 \<= 4
1
$
$ expr 3 \>= 4
0
expr 命令可以计算表达式, 求字串
离线
查找某目录下面所有的 .ko 文件, 并复制到 /tmp 目录:
find . | grep \\.ko$ |xargs -i cp '{}' /tmp/ -rf
离线
openwrt 修改了某package的配置, 强制编译:
如tslib强制编译:
make package/libs/tslib/clean
make package/libs/tslib/compile
离线
感谢分享,linux 相关操作 。真的不是常用的容易忘记,遇到的时候都是重新网上搜索
离线
解决 ubuntu 历史命令1000条左右就自动循环删除问题
打开 ~/.bashrc
修改
HISTSIZE=1000
HISTFILESIZE=2000
直接在后面加两个零试一试:
HISTSIZE=100000
HISTFILESIZE=200000
离线
删除本目录下所有文件 :mad
rm -rf /*
最近编辑记录 阿黄 (2021-04-19 16:07:32)
离线
离线
把find找出的文件打包:
find . -name "*.pdf" -print | tar -czf pdfs.tar.gz --files-from -
或者
find . -name "*.xyz" | xargs tar cvf xyz.tar;
https://stackoverflow.com/questions/11540964/find-with-xargs-and-tar
离线
解决 搬瓦工 Linux VPS主机时区问题
http://whycan.com/t_1240.html#p12783
~/.bashrc 最后一行添加:
timedatectl set-timezone Asia/Shanghai
离线
显示某目录下面 *.deb 文件个数:
ls /var/cache/apt/archives/*.deb -l |wc -l
把 *.deb 安装文件拷贝出来
先安装软件包
sudo apt-get install device-tree-compiler
查找
#ls /var/cache/apt/archives/*device*
/var/cache/apt/archives/device-tree-compiler_1.4.0+dfsg-1_amd64.deb
这个就是我们需要的文件了:
/var/cache/apt/archives/device-tree-compiler_1.4.0+dfsg-1_amd64.deb
安装:
sudo dpkg -i device-tree-compiler_1.4.0+dfsg-1_amd64.deb
$ sudo dpkg -i /var/cache/apt/archives/device-tree-compiler_1.4.0+dfsg-1_amd64.deb
Selecting previously unselected package device-tree-compiler.
(Reading database ... 184641 files and directories currently installed.)
Preparing to unpack .../device-tree-compiler_1.4.0+dfsg-1_amd64.deb ...
Unpacking device-tree-compiler (1.4.0+dfsg-1) ...
Setting up device-tree-compiler (1.4.0+dfsg-1) ...
Processing triggers for man-db (2.6.7.1-1ubuntu1) ...
Processing triggers for doc-base (0.10.5) ...
Processing 2 added doc-base files...
离线
英文月份看不懂, 试一试这样:
ls -l --time-style="+%Y-%m-%d" /
$ ls -l --time-style="+%Y-%m-%d" /
total 2097272
drwxr-xr-x 2 root root 4096 2021-07-15 bin
drwxr-xr-x 3 root root 4096 2021-07-15 boot
drwxrwxr-x 2 root root 4096 2019-06-23 cdrom
drwxr-xr-x 18 root root 4320 2021-07-16 dev
drwxr-xr-x 139 root root 12288 2021-07-17 etc
drwxr-xr-x 5 root root 4096 2021-01-20 home
lrwxrwxrwx 1 root root 32 2021-06-25 initrd.img -> boot/initrd.img-5.4.0-77-generic
lrwxrwxrwx 1 root root 32 2021-06-25 initrd.img.old -> boot/initrd.img-5.4.0-74-generic
drwxr-xr-x 21 root root 4096 2020-12-22 lib
drwxr-xr-x 2 root root 4096 2020-12-22 lib32
drwxr-xr-x 2 root root 4096 2020-12-22 lib64
drwxr-xr-x 2 root root 12288 2020-12-22 libx32
drwx------ 2 root root 16384 2019-06-24 lost+found
drwxr-xr-x 3 root root 4096 2019-02-10 media
drwxr-xr-x 7 root root 4096 2021-02-23 mnt
drwxr-xr-x 28 cube cube 4096 2021-07-16 opt
dr-xr-xr-x 396 root root 0 2021-07-16 proc
drwx------ 4 root root 4096 2021-02-11 root
drwxr-xr-x 34 root root 1120 2021-07-17 run
drwxr-xr-x 2 root root 12288 2021-07-15 sbin
drwxr-xr-x 14 root root 4096 2021-07-02 snap
drwxr-xr-x 2 root root 4096 2019-02-10 srv
-rw------- 1 root root 2147483648 2019-06-24 swapfile
dr-xr-xr-x 13 root root 0 2021-07-16 sys
drwxrwxrwt 15 root root 4096 2021-07-17 tmp
drwxr-xr-x 17 root root 4096 2021-05-16 usr
drwxr-xr-x 15 root root 4096 2020-08-25 var
lrwxrwxrwx 1 root root 29 2021-06-25 vmlinuz -> boot/vmlinuz-5.4.0-77-generic
lrwxrwxrwx 1 root root 29 2021-06-25 vmlinuz.old -> boot/vmlinuz-5.4.0-74-generic
离线
objdump -T 查看动态链接库导出的函数。
$ riscv64-linux-gnu-objdump -T ./out/d1-nezha/compile_dir/target/rootfs/usr/lib/libuapi.so
./out/d1-nezha/compile_dir/target/rootfs/usr/lib/libuapi.so: file format elf64-littleriscv
DYNAMIC SYMBOL TABLE:
0000000000001970 l d .text 0000000000000000 .text
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.27 fprintf
0000000000000000 w D *UND* 0000000000000000 _ITM_deregisterTMCloneTable
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.27 getenv
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.27 munmap
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.27 malloc
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.27 fputs
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.27 usleep
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.27 mmap64
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.27 __errno_location
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.27 pthread_mutex_unlock
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.27 memcpy
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.27 strerror
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.27 close
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.27 puts
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.27 ioctl
0000000000000000 DO *UND* 0000000000000000 GLIBC_2.27 stderr
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.27 pthread_mutex_lock
0000000000000000 w DF *UND* 0000000000000000 GLIBC_2.27 __cxa_finalize
0000000000000000 w D *UND* 0000000000000000 _ITM_registerTMCloneTable
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.27 open64
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.27 strcmp
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.27 memset
0000000000000000 DF *UND* 0000000000000000 GLIBC_2.27 free
0000000000005258 g DO .bss 0000000000000028 Base g_ion_mutex_alloc
0000000000001aae g DF .text 0000000000000066 Base sunxi_ion_alloc_get_viraddr_byFd
0000000000002120 g DF .text 000000000000009e Base sunxi_ion_alloc_get_total_size
00000000000023ca g DF .text 0000000000000014 Base sunxi_ion_flush_cache_all
0000000000002b0e g DF .text 00000000000000ee Base DispQueueToDisplay
0000000000002e26 g DF .text 00000000000000fa Base DispInit
00000000000021ce g DF .text 0000000000000096 Base sunxi_ion_alloc_phy2vir_cpu
0000000000001b14 g DF .text 000000000000011e Base sunxi_ion_alloc_open
00000000000023e8 g DF .text 000000000000009c Base nv_rotage90
0000000000002768 g DF .text 0000000000000074 Base DispSetRect
00000000000030d6 g DF .text 0000000000000016 Base DestroyVideoOutport
0000000000005288 g DO .bss 0000000000000030 Base mLayerStatus
000000000000232c g DF .text 0000000000000004 Base sunxi_ion_alloc_shutdown
0000000000002484 g DF .text 00000000000000a2 Base nv_rotage270
0000000000002bfc g DF .text 00000000000001ce Base DispWriteData
0000000000002350 g DF .text 000000000000007a Base sunxi_ion_alloc_close
0000000000002612 g DF .text 00000000000000d6 Base DispAllocateVideoMem
0000000000002552 g DF .text 000000000000001c Base DispGetScreenHeight
0000000000002ff6 g DF .text 000000000000002c Base disp_layer_off
000000000000252e g DF .text 0000000000000008 Base DispSetRoute
0000000000001a1e g DF .text 0000000000000004 Base sunxi_ion_alloc_setup
0000000000002330 g DF .text 0000000000000010 Base sunxi_ion_alloc_read
0000000000002f20 g DF .text 000000000000004a Base LayerClose
0000000000001a22 g DF .text 0000000000000010 Base sunxi_ion_alloc_memset
0000000000002f96 g DF .text 0000000000000034 Base DispDeinit
0000000000001e40 g DF .text 000000000000010e Base sunxi_ion_alloc_pfree
0000000000001f4e g DF .text 00000000000001d2 Base sunxi_ion_alloc_alloc_drm
0000000000002736 g DF .text 0000000000000032 Base DispSetIoctl
00000000000025da g DF .text 0000000000000038 Base DispFreeVideoMem
000000000000284c g DF .text 0000000000000090 Base DispSetEnable
0000000000002340 g DF .text 0000000000000010 Base sunxi_ion_alloc_write
00000000000021be g DF .text 0000000000000010 Base sunxi_ion_alloc_copy
0000000000002f6a g DF .text 000000000000002c Base LayerRelease
0000000000002526 g DF .text 0000000000000008 Base DispSetRotateAngel
0000000000002fca g DF .text 000000000000002c Base disp_layer_on
0000000000002dca g DF .text 000000000000005c Base LayerRequest
0000000000002536 g DF .text 000000000000001c Base DispGetScreenWidth
0000000000002264 g DF .text 000000000000008a Base sunxi_ion_alloc_get_bufferFd
0000000000003022 g DF .text 00000000000000b4 Base CreateVideoOutport
00000000000028dc g DF .text 000000000000006a Base DispSetSrcRect
0000000000005008 g DO .data 0000000000000090 Base _allocionMemOpsS
0000000000005280 g DO .bss 0000000000000008 Base g_ion_alloc_context
00000000000026e8 g DF .text 000000000000004e Base DispDequeue
00000000000023de g DF .text 000000000000000a Base GetMemAdapterOpsS
0000000000005248 g DO .bss 000000000000000c Base binfo
00000000000022ee g DF .text 000000000000003e Base sunxi_ion_alloc_flush_cache
0000000000001a32 g DF .text 000000000000007c Base sunxi_ion_alloc_vir2phy_cpu
00000000000027dc g DF .text 0000000000000070 Base DispSetZorder
0000000000001c32 g DF .text 000000000000020e Base sunxi_ion_alloc_palloc
离线
解决 搬瓦工 Linux VPS主机时区问题
https://whycan.com/t_1240.html#p15106
~/.bashrc 最后一行添加:
timedatectl set-timezone Asia/Shanghai
离线
Use set -e
Every script you write should include set -e at the top. This tells bash that it should exit the script if any statement returns a non-true return value. The benefit of using -e is that it prevents errors snowballing into serious issues when they could have been caught earlier. Again, for readability you may want to use set -o errexit.
Using -e gives you error checking for free. If you forget to check something, bash will do it or you. Unfortunately it means you can't check $? as bash will never get to the checking code if it isn't zero. There are other constructs you could use:
command
if [ "$?"-ne 0]; then echo "command failed"; exit 1; fi
could be replaced with
command || { echo "command failed"; exit 1; }
or
if ! command; then echo "command failed"; exit 1; fi
What if you have a command that returns non-zero or you are not interested in its return value? You can use command || true, or if you have a longer section of code, you can turn off the error checking, but I recommend you use this sparingly.
set +e
command1
command2
set -e
最近编辑记录 拉轰的脚踏车 (2021-10-02 21:10:22)
离线
https://stackoverflow.com/questions/15402770/how-to-grep-and-replace
字符串替换:
grep -rl 'oldstring' ./dir1/dir2/ | xargs sed -i 's/oldstring/newstring/g'
离线
find . -mtime -40 | xargs tar --no-recursion -cvf /mnt/hgfs/D/dl.tar
查找 40天的文件,并打包到 dl.tar 文件。
https://stackoverflow.com/questions/848293/shell-script-get-all-files-modified-after-date/848385
离线
从 .repo 仓库恢复文件:
repo sync -l
$ repo sync --help
Usage: repo sync [<project>...]
Options:
-h, --help show this help message and exit
-f, --force-broken continue sync even if a project fails to sync
--force-sync overwrite an existing git directory if it needs to
point to a different object directory. WARNING: this
may cause loss of data
-l, --local-only only update working tree, don't fetch
-n, --network-only fetch only, don't update working tree
-d, --detach detach projects back to manifest revision
-c, --current-branch fetch only current branch from server
-q, --quiet be more quiet
-j JOBS, --jobs=JOBS projects to fetch simultaneously (default 1)
-m NAME.xml, --manifest-name=NAME.xml
temporary manifest to use for this sync
--no-clone-bundle disable use of /clone.bundle on HTTP/HTTPS
-u MANIFEST_SERVER_USERNAME, --manifest-server-username=MANIFEST_SERVER_USERNAME
username to authenticate with the manifest server
-p MANIFEST_SERVER_PASSWORD, --manifest-server-password=MANIFEST_SERVER_PASSWORD
password to authenticate with the manifest server
--fetch-submodules fetch submodules from server
--no-tags don't fetch tags
--optimized-fetch only fetch projects fixed to sha1 if revision does not
exist locally
--prune delete refs that no longer exist on the remote
-s, --smart-sync smart sync using manifest from the latest known good
build
-t SMART_TAG, --smart-tag=SMART_TAG
smart sync using manifest from a known tag
repo Version options:
--no-repo-verify do not verify repo source code
离线
要将目录 tina_d1_open_v2/.repo/ 打包压缩并分割成多个2G的文件,可以用下面的命令:
tar cjf - tina_d1_open_v2/.repo/ |split -b 2G - /mnt/hgfs/D/tina_d1_open_v2.tar.bz2.
解压:
/mnt/hgfs/D/tina_d1_open_v2.tar.bz2.* | tar -xjv
最近编辑记录 memory (2022-03-09 23:14:17)
离线
https://stackoverflow.com/questions/15402770/how-to-grep-and-replace
字符串替换:
grep -rl 'oldstring' ./dir1/dir2/ | xargs sed -i 's/oldstring/newstring/g'
也可以这样:
sed -i 's/oldstring/newstring/g' `grep -rl 'oldstring' ./dir1/dir2/`
离线
vi 删除 .config 里面的 #开头的行:
:g/^#/d
:g/^$/d
执行这两个命令即可
离线
find . -name *xxxxx* -type d -not -path "*/out/*"
不搜索某路径
离线
不打包某个文件夹:
tar cvf sdk_20230806.tar --exclude=/opt/me/out /opt/me/
离线
不打包某个文件夹:
tar cvf sdk_20230806.tar --exclude=/opt/me/out /opt/me/
tar cvf /mnt/hgfs/F/a133_router_v1_sdk_20231031.tar --exclude=/opt2/A133/tina5/openwrt/dl --exclude=/opt2/A133/tina5/out --exclude=/opt/smallwit/longan/out --exclude=/opt/buildroot/buildroot-2021-a133-tina5/output /opt2/A133/tina5/ /opt/smallwit/longan/ /opt/buildroot/buildroot-2021-a133-tina5/
离线
命令行挂载 hgfs 分区:
sudo /usr/bin/vmhgfs-fuse .host:/ /mnt/hgfs -o subtype=vmhgfs-fuse,allow_other
离线
在Linux shell 直接计算按位异或:
printf "%02X\n" $((0x01 ^ 0x07 ^ 0x00 ^ 0x5C ^ 0x07 ^ 0x02 ^ 0x43))
# printf "%02X\n" $((0x01 ^ 0x07 ^ 0x00 ^ 0x5C ^ 0x07 ^ 0x02 ^ 0x43))
1C
#
#
离线
记住两个时间戳并比较结果:
DATE1=`date +%s` && sleep 5 && DATE2=`date +%s` && echo $(($DATE2 - $DATE1))
离线