Ubuntu 百问

来源:互联网 发布:什么牌的网络机顶盒好 编辑:程序博客网 时间:2024/05/21 07:13

001. apt-get upgrade vs apt-get dist-upgrade

apt-get upgrade will not change what is installed (only versions),

apt-get dist-upgrade will install or remove packages as necessary to complete the upgrade

upgrade

upgrade is used to install the newest versions of all packages
currently installed on the system from the sources enumerated in
/etc/apt/sources.list. Packages currently installed with new
versions available are retrieved and upgraded; under no
circumstances are currently installed packages removed, or packages
not already installed retrieved and installed. New versions of
currently installed packages that cannot be upgraded without
changing the install status of another package will be left at
their current version. An update must be performed first so that
apt-get knows that new versions of packages are available.

dist-upgrade

dist-upgrade in addition to performing the function of upgrade,
also intelligently handles changing dependencies with new versions
of packages; apt-get has a “smart” conflict resolution system, and
it will attempt to upgrade the most important packages at the
expense of less important ones if necessary. So, dist-upgrade
command may remove some packages. The /etc/apt/sources.list file
contains a list of locations from which to retrieve desired package
files. See also apt_preferences(5) for a mechanism for overriding
the general settings for individual packages.

002. How do I find all files containing specific text on Linux?

 grep -rnw '/path/to/somewhere/' -e 'pattern'-r or -R is recursive,-n is line number, and-w stands for match the whole word.-l (lower-case L) can be added to just give the file name of matching files.Along with these, --exclude, --include, --exclude-dir or --include-dir flags could be used for efficient searching:

This will only search through those files which have .c or .h extensions:

grep --include=\*.{c,h} -rnw '/path/to/somewhere/' -e "pattern"

This will exclude searching all the files ending with .o extension:

grep --exclude=*.o -rnw '/path/to/somewhere/' -e "pattern"

Just like exclude files, it’s possible to exclude/include directories through –exclude-dir and –include-dir parameter. For example, this will exclude the dirs dir1/, dir2/ and all of them matching *.dst/:

grep --exclude-dir={dir1,dir2,*.dst} -rnw '/path/to/somewhere/' -e "pattern"

003. Delete empty folders in current directory

find . -type d -empty -delete# User this only when you know exactly what you are doing

004. Change file line ending between unix and dos

unix -> dos

awk 'sub("$", "\r")' uniz.txt > windows.txt

dos -> unix

in vi: :1,$s/^M//g
[^M] is [Ctrl]+M

005. Switch GCC version

sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.9 50

使用gcc-4.9替代原gcc版本,Priority=50

update-alternatives --display gcc
列出gcc命令的链接组

update-alternatives --remove name path,其中name与path与install中的一致,如果所删除的链接组中还有其他链接的话,系统将会自动从其他中选择一个priority高的链接作为默认为链接。

006. Run chrome from shell / open .html file in Chrome

google-chrome foo.html

007. File/folder comparison

sudo apt-get install meldmeld diff1.md diff2.md

008. List file size

du -h | sort -hdu -h -d 1# -h for human readable size, like 1M, 4k# -d 1 to search one level
## Check disk usage of directoriessudo du -sh ./*(Output)348K    ./_archive940K    ./docs1.5G    ./_RARs1.6G    ./tracker_benchmark

009. Count file number in current directory

ls -1 | wc -l# 使用-1 每行列出一个文件# wc -l 按行统计

010. Rename files in batch using regex

# using zsh command `zmv`# run this in zshautoload zmvzmv -w '*_*.mat' '$2_raw_$1.mat'

011. Kill processes with specific name

ps aux | grep Matlab | grep -v 'grep' | awk {print $2} | xargs kill -9# grep -v to revert the meaning of matching # since the output of `ps aux` containing the grep process# akw {print $2} to get the process PIE# more short command to be learned

012. Clear/Cancel currernt line in terminal

# [Ctrl] + U to clear in current line# [Ctrl] + C to cancel

013. How to manage packages

http://wiki.ubuntu.org.cn/Apt-get%E4%BD%BF%E7%94%A8%E6%8C%87%E5%8D%97

apt-cache search libffi(Output)libffi-dev - Foreign Function Interface library (development files)libffi6 - Foreign Function Interface library runtimesudo apt-get purge <package-name>apt list --installed #列出安装的apt包dpkg -i foo.deb     #installdpkg -l | grep foo      #check installation statusdpkg -r foo     #remove program, but not configuration dpkg -P foo     #remove all, including configuration

014. Copy multiple files to one destination folder

cp /home/usr/dir/{file1,file2,file3,file4} /home/usr/destination/# https://askubuntu.com/questions/327282/copying-multiple-specific-files-from-one-folder-to-another

015. Mount removeable disk (e.g. TOSHIBA)

sudo mount -t ntfs-3g /dev/sdc1 media/tmp# Not the ntfs format, use ntfs-3g instead

016. Create new user and grant privileges @mysql

# 1. If you don't want to change current validate_password_settingsshow variables like 'validate_password%';create user 'lcar979'@'localhost' identified by 'password here'user mysqlGRANT ALL PRIVILEGES ON * . * TO 'newuser'@'localhost';# The asterisks in this command refer to the database and table (respectively) # that they can access—this specific command allows to the user to read, edit, # execute and perform all tasks across all the databases and tables.FLUSH PRIVILEGES;# Once you have finalized the permissions that you want to set up for your # new users, always be sure to reload all the privileges.# check usersselect * from mysql \G# 2. Or you can set current valdiate_password settingsset global validate_password_length = 6;# then create new users

017. Hot to set default application

在你要设置的文件类型的某个文件上右键

选择Properties-Open With

018. How to delete PPA

# Method 1. Use the --remove flag, similar to how the PPA was added:sudo add-apt-repository --remove ppa:whatever/ppa# Method 2. As a safer alternative, you can install ppa-purge:sudo apt-get install ppa-purge# And then remove the PPA, downgrading gracefully packages it provided# to packages provided by official repositories:sudo ppa-purge ppa_name#Note that this will uninstall packages provided by the PPA, but not#those provided by the official repositories. If you want to remove#them, you should tell it to apt:sudo apt-get purge package_name# Method 3. You can also remove PPAs by deleting the .list files from # /etc/apt/sources.list.d directory.

Last but not least, you can also disable or remove PPAs from the “Software Sources” section in Ubuntu Settings with a few clicks of your mouse (no terminal needed).

019. How to disable zsh glob pattern alert

setopt nonomatch

020. 不锁屏 & 屏幕快捷键

Brightness and lock 中设置不锁屏
Shift + PrintScreen 选择区域截图

Extra

watch -n 10 nvidia-smi 每隔10s执行一次指令

fortune 随机获得一句英文谚语、名言、电影台词等

fortune-zh 获得一句唐诗

(可以结合上面的watch一起用)

sudo !! 以sudo重新执行上一条命令

wget http://….. -q –show-progress
只显示下载进度条