Tagged Questions

The rename tag refers to the action of giving a different name to either an existing file or to a copy of a file as part of some other operations (.e.g. remote copy, backup). Use this tag as well for questions related to the (perl) rename command.

learn more… | top users | synonyms

1
vote
2answers
139 views

Why `rename` behaves differently whenever I use full path instead current path?

Ok, I'm answering a question where the OP have several repositories in Ubuntu that might be causing a problem installing unrelated software. I recommend disabling the PPA's using a single liner rename ...
4
votes
5answers
317 views

In Bash how does one determining the length of filename?

I'm doing a little script to rename some files. Actually a lot of files. The problem and the cool thing is, that I actually just need to change the files that have a filename length of 5 characters. ...
2
votes
1answer
1k views

Move a remote file at an FTP prompt

I don't think it's possible but still I would like to ask if there is any command to transfer a remote file from one directory to other at an FTP prompt. In more detail: I run ftp to a remote ...
6
votes
3answers
5k views

Rename files in the local folder adding a prefix or suffix

I have many files in a folder and I want to add either prefix or a suffix (not both) to them. I checked here and found out I can use for filename in *.jpg; do mv "$filename" "prefix_$filename"; done; ...
1
vote
2answers
3k views

How can I find files and then use xargs to move them?

I want to find some files and then move them. I can find the file with: $ find /tmp/ -ctime -1 -name x* I tried to move them to my ~/play directory with: $ find /tmp/ -ctime -1 -name x* | xargs ...
3
votes
2answers
1k views

Automatically moving files to a directory, one by one, and only when the target folder is empty

Is it possible? And in reverse alphabetical order? Essentially, this: How can I move files by type recursively from a directory and its sub-directories to another directory? Except that each file is ...
7
votes
3answers
612 views

Generate new name for moved file to prevent overwriting?

How can I generate a new name for a file if there's an existing file With that same name? In a Desktop environment a new name is generated my appending a number to the end of the file name, but how ...
7
votes
3answers
644 views

cp or mv files to same directory they are already in when I am in another?

If I am in ~/blob and I have a file in ~/blob/a_long_directory_name/c/x.x I can type mv blob/a_long_directory_name/c/x.x blob/a_long_directory_name/even_more/y.y Is there any shortcut whereby I ...
2
votes
1answer
355 views

Renaming files based on the contents of a text file

I have lots of point files I need to change for model input. I want to rename lots of these files based on the contents of a file. These files are text files arranged in rows. file name: ...
6
votes
8answers
6k views

Is there a way to make “mv” fail silently?

A command like mv foo* ~/bar/ produces this message in stderr if there are no files matching foo*. mv: cannot stat `foo*': No such file or directory However, in the script I'm working on that case ...
6
votes
4answers
2k views

Bash script to rename files from a text file source

I'm fairly new to bash; I can just about perform simple administrative tasks with simple commands 1 at a time. However, I've been tasked with renaming some files in a directory using a text file as ...
3
votes
3answers
463 views

Batch rename files with unknown names and unknown extensions

I have a bunch of pictures, some are .jpg, some are .png. any given picture could have an entirely random name (possibly including spaces). in any given directory, how can I rename all of them, ...
4
votes
2answers
108 views

When I move a file to a different directory on the same partition, does the file's data actually move on disk?

I could see it going both ways. If the filesystem stores it's directory structure and list of files in each directory, and then points to the disk location of each of the files, it shouldn't require ...
2
votes
3answers
186 views

mv files to a different path which is constructed via a regex replacement

I have a directory full of files stored in subdirectories according to their filename, i.e.: 20d1/d325/52d1/20d1d32552d1a95249e62662fbdf924dd72c4027.jpg ...
2
votes
4answers
2k views

Change filename from lowercase to uppercase recursively

I have 1,000,000 files in some folders and subfolders. I want to rename them from lowercase to uppercase using shell commands. I don't want to modify the extension. only filename part. I have found ...
17
votes
5answers
3k views

What does `mv ./*` without specifying destination do?

I accidentally forgot to specify destination before hitting the Return key. Where does mv ./* without specifying destination move the files and directories under current directory to?
3
votes
1answer
2k views

Using regex in ls and mv

I have a directory structure like this ├── UK │   ├── BuyBand_go_UK.png │   ├── BuyBand_go_UK.svg │   ├── BuyBand_K.png │   ├── BuyBand_K.svg │   ├── BuyBago_UK.png │   ├── BuyBago_UK.svg │   ├── ...
0
votes
2answers
251 views

Keeps on getting message files are identical using find

Whenever I enter this: find . -type f -name 'diag*' -mtime +30 -exec mv {} temp_diag \; in SunOS I always get this message mv: ./temp_diag/diagnostic.log.68.gz and temp_diag/diagnostic.log.68.gz ...
1
vote
3answers
65 views

Rename directory from within directory?

How would I rename a directory from within that directory? For example: ~/tmp $ rn tmp2 ~/tmp2 $ I can do that with: cd .. && mv tmp tmp2 && cd tmp2, but not sure how to make it ...
1
vote
2answers
285 views

Unable to move or delete file with \r in the name

Somehow i have tar file called 'secret\r-.tar.gz'. Note that it has \r in the name. I tried following SSH command for moving but none of them are working: mv secret\r-.tar.gz ../ mv ...
1
vote
2answers
262 views

How batch mv files to folders created and named by modification date?

I am quite new to the terminal stuff and I just couldn't find any answer on the aforementioned subject. On my OS X, I have a folder with about 4000 pics that I'd like to move into folders that are ...
1
vote
1answer
343 views

Trouble with mv and adding the date

I want to be able to move $oldfile to my backup folder and add the date to the file name. So I tried this... mv $oldfile /home/u0146121/backupfiles/$oldfile_$(date +%F-%T) This just gives me this ...
1
vote
1answer
3k views

Adding a time stamp when moving a file in bash [duplicate]

#!/bin/bash while read server <&3; do #read server names into the while loop if [[ ! $server =~ [^[:space:]] ]] ; then #empty line exception continue fi echo "Connecting to - ...
2
votes
2answers
221 views

how to copy and rename files with “:” and incrementing number in the filename

I need to copy and rename (and then edit) a group of files in the /etc/sysconfig/network-scripts folder. The files are ifcfg-eth1:* I have ifcfg-eth1 through ifcfg-eth1:121 but need to extend with ...
2
votes
2answers
2k views

batch rename file names including spaces and patterns [duplicate]

I would like to rename a bunch of files which are named in a general form of, text1 text2 [firstname.lastname] text3 ... textn.ext I want to remove the text [firstname.lastname] from the name of a ...
2
votes
3answers
1k views

Need to trim the names of file names

I have files in UNIX directory which have a unique number starting with, i have to remove the unique id followed by '-' from the file name and need to have regular file. Any help is appreciated. ...
3
votes
3answers
71 views

Can I forbid the creation of files with certain permissions?

I have a directory with a certain group ID, and I only want files with the same ID to be in that directory. So I set the SGID bit on that directory, so that everytime a file is created inside it, it ...
1
vote
2answers
59 views

Copying Files in a Folder To Individual Folders

This might sound like something quite odd but for my HTPC, I need to rearrange how my files are stored such that each of the individual files in a folder needs to be moved to a subdirectory of its own ...
0
votes
1answer
97 views

Moving folders used wrong syntax and lost them

I thought I was being smart trying to move a folder to one level up by going: mv folder .newfolder and neglecting to even put: mv folder .newfolder/folder and anyway it didn't put up an error but ...
2
votes
3answers
1k views

Replace filename with parent folder name

I have a bunch of files each in their own subdirectory. I need to write a script to rename each file to have the same name as its directory: For example, given: ./1111/1234.pdf ./2222/2345.pdf ...
2
votes
2answers
3k views

How can I rename all files with one extension to a different extension recursively [duplicate]

Say I have a folder: / /a.bub /v.bub /dr.bub /catpictures /catpictures/or.bub /catpictures/on.bub How can I format a script to change each of these to .aaa. Here is what I've got, although it ...
2
votes
1answer
1k views

find/rename command doesn't work

I am using Linux Slackware 14.0, bash 4.2. Suppose, I have 2 files in the directory: bash-4.2$ ls 1.txt 2.txt I want to rename them to .svg. This answer is accepted and upvoted, so I think, it ...
3
votes
2answers
10k views

mv: cannot stat No such file or directory in shell script

I wrote a script to move some files form one folder to another folder but I got the following error, I checked 2 folders and notice for 1 folder there are such files and another there is no such ...
1
vote
3answers
781 views

How to rename pattern in one file to another over several directories recursively

I have several directories through which I want to recursively iterate over and change the file name of *.GEOT14246.* to *.GEOT15000.* Is there a one liner on the bash script to do this ...
1
vote
4answers
902 views

How to remove URI encoding in file names

I realise this might be quite a simple question, but I'm still quite new to the command line and only have a grasp of basic commands. I've downloaded some lecture presentations (~25 or so) from my ...
2
votes
3answers
256 views

Unix command to rename multiple files

I have some dirs with different plugin-cfg.xml files that I want to take a backup of and keep in the same dir. E.g. Plug6_a1/plugin-cfg.xml Plug6_a2/plugin-cfg.xml Plug6_a3/plugin-cfg.xml How can ...
1
vote
3answers
366 views

Remove random string from particular position in file names [duplicate]

I've downloaded dozen of files from youtube using youtube-dl. Nice feature, btw. After I searched through them all, I've realized that there are lots of ending with random numbers and letters of ...
20
votes
1answer
605 views

How to move a directory, file by file? (instead of “copy then remove”)

My computer has one 500GB drive. I want to move 400GB of data from /unencrypted to /encrypted. Both directories are on the same partition, but /encrypted is handled by ecryptfs, so mv /uncrypted/* ...
3
votes
3answers
3k views

How to move all files with a certain file extension from subdirectories to a single directory

I have a directory that contains many subdirectories. The subdirectories contain lots of types of files with different file extensions. I want to move (not copy) all the files of one type into a new ...
0
votes
2answers
1k views

Rename multiple files in UNix directory [duplicate]

I have files in unix directory in below format using sed or some other commands. Owner.Env.File_010513_1200_ver1.expdp Owner.Env.File_010513_1200_ver2.expdp Owner.Env.File_010513_1200_ver3.expdp ...
2
votes
2answers
2k views

how to change `rm` to as a command like `mv ~/ .trash` [duplicate]

I like to use rm but I often made mistakes so that I remove something mistakenly so I want to make somthing like mv .trash so that rm file is equal to mv file ~/.trash besides, I also ...
2
votes
1answer
269 views

Unable to preserve ownership in a copy but able with a move?

I have noticed that I am unable to preserve ownership if I rsync -o files. However, I am when I move them. This is all without admin privileges. What is the rationale of this? Several threads e.g. ...
1
vote
1answer
332 views

Strange behavior in mv command - maybe open sys call issue?

I'm noticing very strange behavior from the "mv" command that may (or may not) be related to the "open" system call. We're running RedHat v5. There are two separate storage devices, one mounted to ...
2
votes
2answers
638 views

Delete whitespace in filenames in directory

I have a directory where some filenames have been wrongly named something .pdf rather than something.pdf. Is there a quick one liner I can use to delete the whitespace in the filenames. I have tried ...
1
vote
3answers
562 views

Why is this Bash command using regex not replacing my brackets?

I have this command to go through all my files in my Music directory, and all subdirectories, and replace any square brackets in the file name with rounded brackets: find /home/Music/ -depth -name "* ...
1
vote
2answers
191 views

How to strip directory structure with command line (or script)

I have a large collection of files packed into a two-level directory structure with many, many, many folders. In other words, I have a folder with a great many subfolders in it. There are no ...
2
votes
3answers
189 views

What has happened to the file when I entered “mv file.txt ../”?

I wanted to move 'file.txt' one folder up, but instead of mv file.txt ../file.txt I entered mv file.txt ../. Now the file is gone and I didn't get any error message. So it seems the some action was ...
3
votes
4answers
2k views

How to change extension of all files in a directory?

There are some extensionless files in current directory (there are not dot in their names). I want to rename like so: filename -> filename.md I tried doing mv * *.md but that didn't help. I am ...
1
vote
2answers
261 views

Is it better to pass all files to mv or to run a bunch of mv processes in parallel?

I have three ways of running mv. First: mv /db/dbfile1 /db/dbfile2 /db/dbfile3 /usb_storage/ and second: mv /db/dbfile1 /usb_storage/ & mv /db/dbfile2 /usb_storage/ & mv /db/dbfile3 ...
2
votes
5answers
243 views

move a directory with a single character (back quote) as its name [duplicate]

How can I move a directory whose name is just a space? ls -lah drwx------ 4 user1 user1 8.0K Mar 13 14:16 . drwxr-xr-x 3 root root 60 Mar 13 13:48 .. drwx------ 18 user1 user1 4.0K Mar 13 11:18 ...