Skip to main content

All Questions

Tagged with
463 votes
18 answers
702k views

How do I change the extension of multiple files?

I would like to change a file extension from *.txt to *.text. I tried using the basename command, but I'm having trouble changing more than one file. Here's my code: files=`ls -1 *.txt` for x in $...
afbr1201's user avatar
  • 4,959
66 votes
3 answers
246k views

How to rename multiple files in single command or script in Unix? [duplicate]

I have the below list of files aro_tty-mIF-45875564pmo_opt aro_tty-mIF-45875664pmo_opt aro_tty-mIF-45875964pmo_opt aro_tty-mIF-45875514pmo_opt aro_tty-mIF-45875524pmo_opt that I need to rename to ...
Udhayakumar's user avatar
37 votes
14 answers
62k views

Preserve directory structure when moving files using find

I have created the following script that move old days files as defined from source directory to destination directory. It is working perfectly. #!/bin/bash echo "Enter Your Source Directory" read ...
KK Patel's user avatar
  • 1,885
32 votes
4 answers
65k views

How to replace spaces in all file names with underscore in Linux using shell script?

I tried following shell script which should replace spaces from all xml filenames for xml_file in $(find $1 -name "* .xml" -type f); do echo "removing spaces from XML file:" $xml_file mv "$xml_file"...
krishna's user avatar
  • 529
20 votes
5 answers
63k views

move file by list in file (with leading whitespace)

I have a file that contains file names. For example: /tmp/list.txt (it is with the spaces at the start of each line): /tmp/file.log /app/nir/home.txt /etc/config.cust I want, using one line, ...
Nir's user avatar
  • 1,395
19 votes
7 answers
17k views

Best way to swap filenames

I need to swap filenames of two files (file and file_1). I'm using the following code for it. mv file .phfile mv file_1 file mv .phfile file This works but is very buggy, It sometimes even results ...
Binoy Babu's user avatar
  • 1,065
19 votes
9 answers
75k views

How to rename all files with special characters and spaces in a directory?

How can I rename all the files in a specific directory where the files contains blanks spaces and special characters ($ and @) in their names? I tried the rename command as follows to replace all the ...
Ankit Vashistha's user avatar
15 votes
4 answers
36k 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; ...
That Brazilian Guy's user avatar
13 votes
5 answers
19k views

Delete spaces, hyphens, and underscores in filenames?

What is a good command to delete spaces, hyphens, and underscores from all files in a directory, or selected files? I use the following command with Thunar Custom Actions to slugify filenames: for ...
whitewings's user avatar
  • 2,507
12 votes
4 answers
8k views

Flattening folder structure

I have this folder structure: ├── foo1 │   ├── bar1.txt │   └── bar2.txt ├── foo2 │   ├── bar3.txt │   └── bar4 with a space.txt └── foo3 └── qux1 ├── bar5.txt └── bar6.txt that I ...
nunos's user avatar
  • 507
11 votes
2 answers
11k views

Create sub-directories and organize files by date

I have some directories of files copied from my security camera that I would like to organize into sub-directories by file date. So for example; -rwxrwxrwx 0 root root 4935241 Jul 19 2012 DSCN1406....
Richard Ahlquist's user avatar
9 votes
4 answers
4k views

How to move and recreate a folder at the same time?

I have a folder called statistics in an Ubuntu server in which data files are regularly stored. How can I rename statistics folder to backup-xx while re-creating statistics folder to be available for ...
Googlebot's user avatar
  • 1,959
9 votes
3 answers
5k views

Change only the extension of a file [duplicate]

I am working on a simple shell script to change a file one.PDF to one.pdf. I have this file stored in a folder called Task1. My script is in the same directory as Task1. Called Shell1.sh When I run ...
Callat's user avatar
  • 243
9 votes
3 answers
7k views

How to remove space in all sub directories in shell script?

I tried following shell script to remove all spaces with underscores: find $1 -depth -name "* *" -print0 | \ while read -d $'\0' f; do mv -v "$f" "${f// /_}"; done If I have a directory /home/user/g ...
krishna's user avatar
  • 529
8 votes
5 answers
21k views

Batch rename files to a sequential numbering

I am trying to batch-rename a bunch of files in my shell, and even though there is plenty of material about it on the internet, I cannot seem to find a solution for my specific case. I have a bunch ...
NicApicella's user avatar

15 30 50 per page
1
2 3 4 5
13