mv

bash removing part of a file name

和自甴很熟 提交于 2021-02-15 11:01:24
问题 I have the following files in the following format: $ ls CombinedReports_LLL-*'('*.csv CombinedReports_LLL-20140211144020(Untitled_1).csv CombinedReports_LLL-20140211144020(Untitled_11).csv CombinedReports_LLL-20140211144020(Untitled_110).csv CombinedReports_LLL-20140211144020(Untitled_111).csv CombinedReports_LLL-20140211144020(Untitled_12).csv CombinedReports_LLL-20140211144020(Untitled_13).csv CombinedReports_LLL-20140211144020(Untitled_14).csv CombinedReports_LLL-20140211144020(Untitled

bash removing part of a file name

眉间皱痕 提交于 2021-02-15 11:01:11
问题 I have the following files in the following format: $ ls CombinedReports_LLL-*'('*.csv CombinedReports_LLL-20140211144020(Untitled_1).csv CombinedReports_LLL-20140211144020(Untitled_11).csv CombinedReports_LLL-20140211144020(Untitled_110).csv CombinedReports_LLL-20140211144020(Untitled_111).csv CombinedReports_LLL-20140211144020(Untitled_12).csv CombinedReports_LLL-20140211144020(Untitled_13).csv CombinedReports_LLL-20140211144020(Untitled_14).csv CombinedReports_LLL-20140211144020(Untitled

mv a file that contains spaces from a shell script

怎甘沉沦 提交于 2021-02-07 14:49:04
问题 I am trying to mv a file (rename it to replace spaces with dashes). If I pass the source and dest arguments without quotes, the source is broken up because mv thinks it is the end of the argument. If I surround source and dest with arguments, mv reports that the source can't be found. Currently, $1 and $2 have hardcoded quotes at the beginning and end. $onam and $dnam are the equivalents without the hardcoded quotes. This command from a prompt works perfectly because source and dest are

mv a file that contains spaces from a shell script

╄→尐↘猪︶ㄣ 提交于 2021-02-07 14:48:40
问题 I am trying to mv a file (rename it to replace spaces with dashes). If I pass the source and dest arguments without quotes, the source is broken up because mv thinks it is the end of the argument. If I surround source and dest with arguments, mv reports that the source can't be found. Currently, $1 and $2 have hardcoded quotes at the beginning and end. $onam and $dnam are the equivalents without the hardcoded quotes. This command from a prompt works perfectly because source and dest are

Linux Bash: Move multiple different files into same directory

笑着哭i 提交于 2021-02-06 02:29:05
问题 As a rather novice Linux user, I can't seem to find how to do this. I am trying to move unique files all in one directory into another directory. Example: $ ls vehicle car.txt bicycle.txt airplane.html train.docx (more files) I want car.txt, bicycle.txt, airplane.html, and train.docx inside vehicle. Right now I do this by moving the files individually: $ mv car.txt vehicle $ mv bicycle.txt vehicle ... How can I do this in one line? 回答1: You can do mv car.txt bicycle.txt vehicle/ (Note that

Linux Bash: Move multiple different files into same directory

别来无恙 提交于 2021-02-06 02:27:56
问题 As a rather novice Linux user, I can't seem to find how to do this. I am trying to move unique files all in one directory into another directory. Example: $ ls vehicle car.txt bicycle.txt airplane.html train.docx (more files) I want car.txt, bicycle.txt, airplane.html, and train.docx inside vehicle. Right now I do this by moving the files individually: $ mv car.txt vehicle $ mv bicycle.txt vehicle ... How can I do this in one line? 回答1: You can do mv car.txt bicycle.txt vehicle/ (Note that

massive rename on terminal and sequentially numbered

旧时模样 提交于 2021-01-27 17:38:50
问题 I want to rename a lot of files (some jpg and a lot of png files) I need them sequentially numbered on each folder have this structure: .../folder01 file.png file.jpg .../folder02 file.png file.png .......... .../folder05 file.png file.png and I want something like this: .../folder01 0001.jpg 0002.png .../folder02 0003.png 0004.png .......... .../folder05 0012.png 0013.png how can I make it using bash? 回答1: Here's one way: find . \( -name '*.jpg' -o -name '*.png' \) -print | (i=0; while read

目录处理命令

十年热恋 提交于 2020-12-25 12:04:40
创建目录:mkdir mkdir -p [目录名] -p 递归创建 命令英文愿意:make directories 切换目录:cd cd [目录] 命令英文原意:change directory 简化操作: cd: 进入当前用户的家目录 cd 目标目录:进入目标目录 cd -:回到上一次所在的目录 cd ~:进入当前用户家目录 cd . :进入当前目录 cd . .:进入上一级目录 查看所在目录位置:pwd pwd 命令英文原意:print working directory 注:pwd查看的是绝对路径。 绝对路径:从根目录开始制定,一级一级递归查找。在任何 目录下,都能进入指定位置。 如: [root@localhost~]#cd /etc/ 相对路径:参照当前所在目录,进行查找。 如:[root@localhost~]#cd ../usr/local/src/ 删除空目录:rmdir rmdir [目录名] 命令英文原意:remove empty directories 删除文件或目录:rm rm -rf [文件或目录] -r:删除目录 -f:强制删除 命令英文原意:remove 复制命令:cp cp [选项] [原文件或目录] [目标目录] 命令英文原意:copy 选项: -r 复制目录 -p 连带文件属性复制 -d 若原文件是链接文件,则复制链接属性 -a 相当于-dpr

Rename files using sed and mv

核能气质少年 提交于 2020-07-18 04:06:22
问题 I want to rename files in the format: img_MM-DD-YY_XX.jpg img_MM-DD-YY_XXX.jpg to: newyears_YYYY-MM-DD_XXX.jpg Where: YYYY = year MM = month DD = day XXX or XX = photo number I came up with this script but it isn't working: for filename in ?*.jpg; do newFilename=$(echo $filename | \ sed 's/img_\(.*\)-\(.*\)-\(.*\)_\([0-9][0-9]\)\./newyears_20\3-\1-\2_0\4./; s/img_\(.*\)-\(.*\)-\(.*\)_\([0-9][0-9][0-9]\)/newyears_20\3-\1-\2_\4/' -) mv $filename $newFilename done Any help would be greatly

Split a folder into multiple subfolders in terminal/bash script

痴心易碎 提交于 2020-06-24 07:26:29
问题 I have several folders, each with between 15,000 and 40,000 photos. I want each of these to be split into sub folders - each with 2,000 files in them. What is a quick way to do this that will create each folder I need on the go and move all the files? Currently I can only find how to move the first x items in a folder into a pre-existing directory. In order to use this on a folder with 20,000 items... I would need to create 10 folders manually, and run the command 10 times. ls -1 | sort -n |