recentpopularlog in

aries1988 : bash   84

« earlier  
Initiation au Shell
Quand on parle du Shell, on fait souvent référence à l'interpréteur de commande, autrefois nommé sh (contraction de shell), et qui a ensuite donné naissance à tout un éventail d'interpréteurs tels que bash, csh, zsh, ksh… qu'il ne faut pas confondre avec un émulateur de terminal comme xterm, eterm, gnome-terminal qui est un outil graphique qui permet d'avoir accès au shell.
primer  bash  definition 
december 2018 by aries1988
A Beautifully Productive Terminal Experience
Every developer can benefit from using the command line. Whether you use it to bounce between projects or create complex scripts, getting familiar with the c...
bash  tool 
september 2018 by aries1988
Stephen  on Twitter
“youtube-dl 真好用~支援一大堆網站影片下載,YouTube、B 站、蘋果日報、愛奇藝通通有~”
tool  bash  download  youtube  video 
september 2018 by aries1988
macos - OS X / Linux: pipe into two processes? - Stack Overflow
As tee copy to each file and also to standard output , and as >() will be see by tee as files, you have to write: prg1 | tee >(prg2) > >(prg3) to not dump the ouptut of prg1 on console (notice the supplementary >). – F. Hauri Oct 1 '13 at 21:00
bash  tee  explained  tips 
july 2018 by aries1988
vim - How to insert spaces up to column X to line up things in columns? - Stack Overflow
If you are using a unix-like environment, you can use the command line tool column. Mark your lines using visual mode, then:

:'<,'>!column -t
bash  column  vim  howto 
march 2018 by aries1988
regex - Regular Expression usage with ls - Stack Overflow
You are confusing regular expression with shell globbing.
bash  explained  regex 
january 2018 by aries1988
快速学习Bash - Vamei
在Bash中,为了把一段包含空格的文本当做单一参数,就需要用到单引号或双引号。你可以在双引号中使用变量。比如:

为了避免变量名和尾随的普通文本混淆,我们也可以换用${}的方式来标识变量。比如说:

$echo $varIsGood

在Bash中,数字和运算符都被当做普通文本。所以你无法像C语言一样便捷地进行数学运算。

在Bash中,你还可以通过$(())语法来进行数值运算。在双括号中你可以放入整数的加减乘除表达式。Bash会对其中的内容进行数值运算。比如

$echo $((2 + (5*2)))

按照Linux惯例,当程序正常运行完毕并返回时,将返回整数0。因此,C程序中返回0的语句,都出现在C程序中main函数的最后一句

你还可以把多行的Bash命令写入一个文件,成为所谓的Bash脚本。当Bash脚本执行时,Shell将逐行执行脚本中的命令。编写Bash脚本,是我们开始实现Bash代码复用的第一步。

还是按照惯例,脚本正常退出时返回代码0。在脚本的末尾,我们可以用exit命令来设置脚本的返回代码。

在for语法中,我们也可以使用自己构建一个由空格分隔的文本。由空格区分出来的每个子文本会在循环中赋值给变量。比如:

Bash和C的相似性,也来自于它们共同遵守的编程范式——面向过程编程。支持面向过程编程的语言,一般都会提供类似于函数的代码封装方式。函数把多行指令包装成一个功能。只要知道了函数名,程序可以通过调用函数来使用函数功能,最终实现代码复用。

除了相似性,我们还应该注意到Bash和C程序的区别。Bash的变量只能是文本类型,C的变量却可以有整数、浮点数、字符等类型。Bash的很多功能,如加减乘除运算,都是调用其他程序实现的。而C直接就可以进行加减乘除运算。可以说,C语言是一门真正的编程语言。C程序最终会编译成二进制的可执行文件。CPU可以直接理解这些文件中的指令。

所谓的Bash编程,只是命令解释器程序提供的一种互动方法。Bash脚本只能和Bash进程互动。它不能像C语言一样,直接调用CPU的功能。因此,Bash能实现的功能会受限,运行速度上也比不上可执行文件。
bash  tutorial 
december 2017 by aries1988
Clink
New keyboard shortcuts;
Paste from clipboard (Ctrl-V).
Incremental history search (Ctrl-R/Ctrl-S).
Powerful completion (TAB).
Undo (Ctrl-Z).
Automatic “cd ..” (Ctrl-Alt-U).
Environment variable expansion (Ctrl-Alt-E).
(press Alt-H for many more…)
windows  bash  cmd  tool  moi 
march 2017 by aries1988
osx - How to change the terminal prompt to just current directory? - Stack Overflow
.bashrc is ONLY excuted when starting a sub-shell. bash login shell uses the following initialization scripts:

.bash_profile
.bash_login
.profile
bash  explained  bashrc 
november 2015 by aries1988
bash - Find directories that DON'T contain a file - Ask Ubuntu
Case 2: You want to be more flexible

You're not sure of the case, and the extension might be jPg, png...

find base_dir -mindepth 2 -maxdepth 2 -type d '!' -exec sh -c 'ls -1 "{}"|egrep -i -q "^cover\.(jpg|png)$"' ';' -print
Explanation:

You need to spawn a shell sh for each directory since piping isn't possible when using find
ls -1 "{}" outputs just the filenames of the directory find is currently traversing
egrep (instead of grep) uses extended regular expressions; -i makes the search case insensitive, -q makes it omit any output
bash  explained 
november 2015 by aries1988
ubuntu 12.04 - How to run rsync without staying logged in? - Server Fault
Run the command within GNU Screen. Basically:

Install screen: $ sudo apt-get install screen
Run screen: $ screen ... at which point, you'll have a shell running from within screen.
Run your command.
Press Ctrl-A,d, which will detach you from the screen session and your command will continue running.
When you want to re-attach, just ssh in as the user who owns the screen session and then:

$ screen -RD
bash  terminal 
july 2015 by aries1988
What’s the Difference Between Single and Double Quotes in the Bash Shell?
Double Quotes

Use when you want to enclose variables or use shell expansion inside a string.
All characters within are interpreted as regular characters except for $ or ` which will be expanded on the shell.
Single Quotes

All characters within single quotes are interpreted as a string character.
bash  explained 
may 2015 by aries1988
version control - Detect the OS from a Bash script - Stack Overflow
platform='unknown'
unamestr=`uname`
if [[ "$unamestr" == 'Linux' ]]; then
platform='linux'
elif [[ "$unamestr" == 'FreeBSD' ]]; then
platform='freebsd'
fi
os  bash  example 
march 2013 by aries1988
scripting - How do I do if statement arithmetic in bash? - Stack Overflow
read n
if ! ((n % 4)); then
echo "$n divisible by 4."
fi
The (( )) operator evaluates expressions as C arithmetic, and has a boolean return.

Hence, (( 0 )) is false, and (( 1 )) is true. [1]

The $(( )) operator also expands C arithmetic expressions, but instead of returning true/false, it returns the value instead. Because of this you can test the output if $(( )) in this fashion: [2]

[[ $(( n % 4 )) == 0 ]]
But this is tantamount to: if (function() == false). Thus the simpler and more idiomatic test is:

! (( n % 4 ))
[1]: Modern bash handles numbers up to your machine's intmax_t size.

[2]: Note that you can drop $ inside of (( )), because it dereferences variables within.
bash  learn  arithmetic 
february 2013 by aries1988
Keyboard Shortcuts for Bash ( Command Shell for Ubuntu, Debian, Suse, Redhat, Linux, etc) - How-To Geek
Ctrl AGo to the beginning of the line you are currently typing on Ctrl EGo to the end of the line you are currently typing on Ctrl L              Clears the Screen, similar to the clear command Ctrl UClears the line before the cursor position. If you are at the end of the line, clears the entire line. Ctrl HSame as backspace Ctrl RLet’s you search through previously used commands Ctrl CKill whatever you are running Ctrl DExit the current shell Ctrl ZPuts whatever you are running into a suspended background process. fg restores it. Ctrl WDelete the word before the cursor Ctrl KClear the line after the cursor Ctrl TSwap the last two characters before the cursor Esc TSwap the last two words before the cursor Alt FMove cursor forward one word on the current line Alt BMove cursor backward one word on the current line TabAuto-complete files and folder names
linux  shortcuts  via:jkprime  bash 
february 2013 by aries1988
BASH: How to Redirect Output to File, AND Still Have it on Screen
ls -l 2>&1 >file.txt
will send stderr to your screen and stdout to file.txt. Why? Because stderr was redirected to the same place as stdout, but at this time stdout was still pointing to the console. stdout was not redirected to file.txt until AFTER stderr had been redirected. When we are talking AFTER in this example we are talking about placement on the command line. Things specified further to the right are thought of as coming after. So this example does nothing for stderr. stderr is indeed redirected to the same place as stdout, which is the console at the time of the redirection, but stderr was ALREADY pointing there in the first place - resulting in no perceivable change.

It makes sense in the light of the shell's operation. The "|" is actioned in "3. Parses the tokens into simple and compound commands" and the ">"s are actioned in "5. Performs any necessary redirections ..." so, in this case, the ls command's stdout is already configured for redirection to the tee command by the time the ">"s are processed.
bash  linux  output  howto  explained 
december 2012 by aries1988
linux - Why does find -exec mv {} ./target/ + not work? - Stack Overflow
find -exec command {} ;

For each result, command {} is executed. All occurences of {} are replaced by the filename. ; is prefixed with a slash to prevent the shell from interpreting it.

find -exec command {} +

Each result is appended to command and executed afterwards. Taking the command length limitations into account, I guess that this command may be executed more times, with the manual page supporting me:
bash  linux  workflow 
october 2012 by aries1988
mtime option in find command
find ~ -mtime 1 -exec ls -ld --time-style=iso {} ;
bash  ls  find  rm 
october 2012 by aries1988
OCR - Extract Scanned Text From PDF
#!/bin/bash
# - ocrpdf - Extract scanned text from a PDF file using Tesseract,
# Poppler and ImageMagick.
# Check if all necessary executables are installed
# Check if exist the file and is a pdf
# People that use graphical file managers happily use names like
# "This is my file.pdf" and include brackets, commas, non ascii
# symbols. And in some cases slashes too! Then they send this file
# like an email attachment and it travels across different machines
# and programs, protocols, encodings, character sets, etc. Despite
# most today operating systems and programs are able to get rid of
# this, it is not a good practice.
#
# Cleaning some weird symbols from file's name
# Convert pdf to ppm images
# Convert PPM images to TIF. If you use TIFF (two efs) tesseract
# returns an error
# Convert tif images to plain text
# Join txt files
# End ocrpdf
filename  example  bash 
september 2012 by aries1988
28个Unix/Linux的命令行神器
下面是Kristóf Kovács收集的28个Unix/Linux下的28个命令行下的工具(原文链接),有一些是大家熟悉的,有一些是非常有用的,有一些是不为人知的。这些工具都非常不错,希望每个人都知道。本篇文章还在Hacker News上被讨论,你可以过去看看。我以作者的原文中加入了官网链接和一些说明。
googlereader  linux  bash 
july 2012 by aries1988
Extract Scanned Text From PDF
Extract scanned text from a PDF file using Tesseract, Poppler and ImageMagick.
-------
Advice about the scripts included in this site: try to understand what the script does and attempt to write your own version. If you just cut and paste the next time you'll have to visit my stupid site again ;-). Remember, it's not free software but to learn what makes you free.
bash  example  filename  pdf  oct  linux  howto  script 
may 2012 by aries1988
Manipulating Strings
${string%substring}
Deletes shortest match of $substring from back of $string.
bash  string  linux 
october 2011 by aries1988
« earlier      
per page:    204080120160

Copy this bookmark:





to read