Unix and perl primer for Biologists - Part1 :Unix - Learning the Essentials - Reading Notes(U13-U24)

2023-11-03

U13: Time to tidy up
use the rmdir command, this will only remove empty directories
remove_nonempty_directories
U14: The art of typing less to do more
you can tab complete the names of files and programs on most Unix
systems. pressing tab twice will show you all possible completions.

Task U14.1
Unix stores a list of all the commands that you have typed in each login session. You can access this list by using the history command or more simply by using the up and down arrows to access anything from your history.

U15: U can touch this
copy files to/from places, move files, rename files, remove files, and most importantly, look at files. Unix command touch will let us create a new, empty file.

U16: Moving text2 and text3
move these files to a new directory (‘Temp’). using the Unix mv (move) command:
touch_and_move_command
For the mv command, we always have to specify a source file (or directory) that we want to move, and then specify a target location. If we had wanted to we could have moved both files in one go by typing any of the following
commands:
wild_card_character_1
wild_card_character_2
The asterisk * acts as a wild-card character, essentially meaning ‘match anything’. The second example works because there are no other files or directories in the directory that end with the letters ‘t’ (if there was, then they would be copied too). Likewise, the third example works because only those two files contain the letters ‘ea’ in their names, except that the directory of Temp, and error was reported here.

mv: cannot move 'Temp' to a subdirectory of itself, 'Temp/Temp'

Task U16.1
Use touch to create three files called ‘fat’, ‘fit’, and ‘feet’ inside the Temp directory:
The ? character is also a wild-card but with a slightly different meaning.
wild_card_character_?_match_only_one

U17: Renaming files
make a new file and move it whilst renaming it at the same time:
move_and_rename_the_file
So mv can rename a file as well as move it. The logical extension of this is using mv to rename a file without moving it (you have to use mv to do this as Unix does not have a separate ‘rename’ command):
rename

U18: Stay on target
specified a ‘source’ and a ‘target’ location when you are moving a file, then it doesn’t matter what your current directory is.Moving directories is just like moving files.
Task U18.1
Create another Temp directory (Temp3) and then change directory to your home directory. Without changing directory, move the Temp3 directory to inside the /Temp directory.

mv_regardless_of_the_current_directory

U19: Here, there, and everywhere
The philosophy of ‘not having to be in a directory to do something in that directory’, extends to just about any operation that you might want to do in Unix.
not_having_to_be_in_the_directory

U20: To slash or not to slash?
Task U20.1

slash
In both cases we have a directory named ‘Documentation’ and it is
optional as to whether you include the trailing slash. When you tab complete any Unix directory name, you will find that a trailing slash character is automatically added for you. This becomes useful when that directory contains subdirectories which you also want to tab complete.

U21: The most dangerous Unix command you will ever learn!
remove a directory with the rmdir command, but rmdir won’t remove directories if they contain any files. rm is a very dangerous command; if you delete something with rm , you will not get it back! It does not go into the trash or recycle can, it is permanently removed. It is possible to delete everything in your home directory (all directories and subdirectories) with rm . use it with the -i command-line option which will ask for confirmation before deleting anything:

root@kali:~/Documents/test1/Temp# pwd
/root/Documents/test1/Temp
root@kali:~/Documents/test1/Temp# ls 
fat   fit    Temp3  text1       text11.txt  text3.txt  text5.txt  text7.txt   text9.text
feet  Temp1  text   text10.txt  text2.txt   text4.txt  text6.txt  text8.text
root@kali:~/Documents/test1/Temp# rm -i text11.txt 
rm: remove regular empty file 'text11.txt'? y
root@kali:~/Documents/test1/Temp# rm -i text4.txt 
rm: remove regular empty file 'text4.txt'? y
root@kali:~/Documents/test1/Temp# ls
fat  feet  fit  Temp1  Temp3  text  text1  text10.txt  text2.txt  text3.txt  text5.txt  text6.txt  text7.txt  text8.text  text9.text
root@kali:~/Documents/test1/Temp# rm -i ?e??
rm: remove regular empty file 'feet'? n
rm: remove regular empty file 'text'? n
root@kali:~/Documents/test1/Temp# rm -i ?e*
rm: remove regular empty file 'feet'? n
rm: cannot remove 'Temp1': Is a directory
rm: cannot remove 'Temp3': Is a directory
rm: remove regular empty file 'text'? n
rm: remove regular empty file 'text1'? n
rm: remove regular empty file 'text10.txt'? n
rm: remove regular empty file 'text2.txt'? n
rm: remove regular empty file 'text3.txt'? n
rm: remove regular empty file 'text5.txt'? n
rm: remove regular empty file 'text6.txt'? n
rm: remove regular empty file 'text7.txt'? n
rm: remove regular empty file 'text8.text'? n
rm: remove regular empty file 'text9.text'? n
root@kali:~/Documents/test1/Temp# rm -i *.txt
rm: remove regular empty file 'text10.txt'? n
rm: remove regular empty file 'text2.txt'? n
rm: remove regular empty file 'text3.txt'? n
rm: remove regular empty file 'text5.txt'? n
rm: remove regular empty file 'text6.txt'? n
rm: remove regular empty file 'text7.txt'? n
root@kali:~/Documents/test1/Temp# rm -i *ex*.*ex*
rm: remove regular empty file 'text8.text'? n
rm: remove regular empty file 'text9.text'? n

Task U21.1
Remove the file and then remove the empty directories
rmdir_rm

U22: Go forth and multiply
Copying files with the cp (copy) command is very similar to moving them. Remember to always specify a source and a target location. In Unix, the current directory can be represented by a ‘.’ (dot) character.The default behavior of copy is to overwrite (without warning) files that have the same name,
cp

U23: Going deeper and deeper
The cp command also allows us (with the use of a command-line option) to copy entire directories. The -R option means ‘copy recursively’, many other Unix commands also have a similar option.
cp_directory_ls_multiple_directories

U24: When things go wrong
In general, if a command fails, check your current directory ( pwd ) and check that all the files or directories that you mention actually exist (and are in the right place). Many errors occur because people are not in the right directory!

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

Unix and perl primer for Biologists - Part1 :Unix - Learning the Essentials - Reading Notes(U13-U24) 的相关文章

  • Perl 三元条件运算符

    我正在尝试在脚本中编写更高效的代码 并且有时会实现三元条件运算符 我不明白为什么在循环中使用三元条件运算符时会得到额外的结果 usr bin perl use strict use warnings my array Serial 123
  • 在 macOS 上使用 find 时出现“非法选项”错误

    我试图列出末尾仅带有字母 R 的文件 我用了find在 macOS 终端中如下所示 find type f name R 但我收到消息说illegal option t 第一个参数find是它应该开始寻找的路径 路径 表示当前目录 find
  • Java“tail -f”包装器

    我需要将 Unix 命令 tail f 包装在 BufferedInputStream 中 我不想模拟或模仿尾巴 如所述这个问题 https stackoverflow com questions 557844 java io implem
  • 在 Perl 中,如何将一个函数作为另一个函数的参数传递?

    我编写了以下 Perl 类 package Menu use strict my MENU ITEMS my HEADER Pick one of the options below n my INPUT REQUEST Type your
  • 添加到表现异常的 Perl 哈希

    我试图通过将时间标签从事件内移动到其父级内来更改一些 XML 以按时间对事件进行分组 那是
  • 在 Python 中删除 root 权限

    我想让一个Python程序开始侦听端口80 但之后执行时无需root权限 有没有办法放弃 root 或在没有 root 的情况下获取端口 80 如果没有 root 权限 您将无法在端口 80 上打开服务器 这是对操作系统级别的限制 因此 唯
  • LibXML findnodes($query)

    我在使用这段代码时遇到了一些问题 my file xml news xml my parser XML LibXML gt new my doc parser gt parse file file my xpc XML LibXML XPa
  • 如何在不描述每个元素的格式的情况下打印数组?

    我想打印几个数组 输出的元素的字段宽度为 3 我想我可以使用printf 但如果我使用printf然后我需要编写数组所有元素的格式 但数组很大 例如 array 1 10 100 30 printf 3d 3d 3d 3d n array
  • 如何编写正则表达式来匹配 Verilog 文件中的模块实例化?

    我正在开发一个项目 通过使用 perl 脚本语言来促进 verilog 编程 现在我想编写一个脚本来扫描顶级verilog文件 然后生成模块的层次结构列表 这表明我需要提取模块实例化 从verilog文件中的语句来看 问题是这样的 如何编写
  • 如何使用 Perl 将连接数据线转换为方案块?

    我正在寻找一种将信号连接转换为简单方案或图表的方法 假设我有 2 个组件 周围有 2 条线路 信号 component A input S1 output S2 component B input S2 output S1 这将是输入数据文
  • 通过匹配模式将字符串替换为另一个文本文件中的行

    我有一个带有对应键 gt 值的文件 sort keyFile txt head ENSMUSG00000000001 ENSMUSG00000000001 Gnai3 ENSMUSG00000000003 ENSMUSG0000000000
  • 如何在unix中对ls输出进行编号?

    我正在尝试编写一个格式为 id file absolute path 的文件 该文件基本上递归地列出文件夹中的所有文件 并为每个文件提供一个标识符 如 1 2 3 4 我可以使用以下命令递归地获取文件的绝对路径 ls d 1 PWD 但是
  • 如果等于特定值则替换列

    我希望替换 CSV 中的第四列 如果它等于 N A 我正在尝试将其更改为 1 我似乎无法让它发挥作用 awk F if 4 N A 4 1 test csv 您可以使用以下内容awk awk F 4 4 N A 1 4 1 OFS test
  • 如何在 Perl 中不阻塞地测试 STDIN?

    我正在编写我的第一个 Perl 应用程序 一个 AOL Instant Messenger 机器人 它与 Arduino 微控制器对话 后者控制一个伺服系统 按下我们系统管理员服务器上的电源按钮 该服务器每 28 小时左右就会随机冻结一次
  • perl 中的大写重音字符

    有没有办法在perl中大写重音字符 my string l phant print uc string 这样它实际上会打印 L PHANT 我的 perl 脚本以 ISO 8859 1 编码 string 以相同编码打印在 xml 文件中
  • 很好的 C 库集合? [关闭]

    Closed 这个问题正在寻求书籍 工具 软件库等的推荐 不满足堆栈溢出指南 help closed questions 目前不接受答案 我正在寻找一个很好的 ANSI C 库集合 用于处理向量 哈希映射 二进制树 字符串处理等 Try g
  • sed:用匹配的模式替换第 n 个单词?

    我有一个具有以下特征的文本文件 每行至少有三个由空格分隔的 单词 单词 可以是任何字符或字符串 我在一些行中附加了一些注释 并提出了对原始单词进行更改的初步建议 现在想使用 sed 为我进行这些更改 因此 为了提供更清晰的图片 我的文件如下
  • 为什么有关严格 subs 的错误仅在 autodie 下触发?

    鉴于这样的代码 我没有收到任何警告 use strict use warnings open STDERR gt STDOUT 鉴于此代码 我收到一个致命错误 use strict use warnings use autodie open
  • Python select() 行为很奇怪

    我在理解 select select 的行为时遇到一些困难 请考虑以下 Python 程序 def str to hex s def dig n if n gt 9 return chr 65 10 n else return chr 48
  • UNIX 域 STREAM 和 DATAGRAM 套接字之间的区别?

    这个问题是NOTSTREAM 类型和 DATAGRAM 类型 INTERNET 套接字之间的区别 我知道 STREAM 套接字使用 TCP 数据报套接字使用 UDP 以及所有 TCP UDP 内容 按顺序到达的数据包 ACK NACK 等

随机推荐