FILE MANAGEMENT

SPACE-GO.SH

folder

Replace spaces with underscores.

01

Tasks & Commands

The following is a list of tasks the script will need to complete. Each of these tasks will be presided by a comment '#'. Below that... are the commands that can be used to complete them.

# get the target directory
# store directory in a variable called 'path'
echo -n "Target Directory: "
read path

# turn returned sting into an object
# change directory to given path
eval cd $path

# show contents of provided directory
ls -l

# prompt user to continue
echo "Replace all spaces with underscores?"
read -p "Hit <ENTER> to continue / ctrl + c to quit"

# replace all space with underscores
rename 's/ /_/g' *

# show results
ls -l

# exit
exit

02

The Script

Now that the commands have been found, the can be saved to a file with a .sh extension, then run as a script. The following code snippet can be copy and pasted into an editor, saved and run.

The very 1st line of the script points to where bash is installed on the system. If this is different in your case, the following command can be used to find this path.

fossman@linux-server:~$ which bash
#!/usr/bin/bash

# welcome message
echo ""
echo "SPACE-GO.SH"
echo ""

# get the target directory
echo -n "Target Diarectory: "
read path

# turn returned sting into an object
# change directory to given path
eval cd $path

# show contents of provided directory
echo ""
echo "Directory Contents"
ls -l
echo ""

# prompt user to continue
echo "Replace all spaces with underscores?"
read -p "Hit <ENTER> to continue / ctrl + c to quit"

# replace all spaces with underscores
rename 's/ /_/g' *

# show results
echo ""
echo "Success! generating results..."
sleep 2
echo ""
ls -l

# exit
exit

Commands
The following commands were used

Command Purpose
echo -n "Target Diarectory: "
read path
get the target directory
eval cd $path change returned string into an object
move to target directory
ls -l list contents of target directory
echo "Replace all spaces with underscores?"
ead -p "Hit <ENTER> to continue / ctrl + c to quit"
prompt user to continue
rename 's/ /_/g' * replace spaces with underscores
ls -l show results
exit exit script

SPACE-GET.SH

folder

Replace underscores with spaces.

01

Tasks & Commands

The following is a list of tasks the script will need to complete. Each of these tasks will be presided by a comment '#'. Below that... are the commands that can be used to complete them.

# get the target directory
# store directory in a variable called 'path'
echo -n "Target Directory: "
read path

# turn returned sting into an object
# change directory to given path
eval cd $path

# show contents of provided directory
ls

# prompt user to continue
echo "Replace all underscores with spaces?"
read -p "Hit <ENTER> to continue / ctrl + c to quit"

# replace all underscores with spaces
rename 's/_/ /g' *

# show results
ls -l

# exit
exit

02

The Script

Now that the commands have been found, the can be saved to a file with a .sh extension, then run as a script. The following code snippet can be copy and pasted into an editor, saved and run.

The very 1st line of the script points to where bash is installed on the system. If this is different in your case, the following command can be used to find this path.

fossman@linux-server:~$ which bash
#!/usr/bin/bash

# welcome message
echo ""
echo "SPACE-GET.SH"
echo ""

# get the target directory
echo -n "Target Diarectory: "
read path

# turn returned sting into an object
# change directory to given path
eval cd $path

# show contents of provided directory
echo ""
echo "Directory Contents"
ls
echo ""

# prompt user to continue
echo "Replace all underscores with spaces?"
read -p "Hit <ENTER> to continue / ctrl + c to quit"

# replace all underscores with spaces
rename 's/_/ /g' *

# show results
echo ""
echo "Success! generating results..."
sleep 2
echo ""
ls -l

# exit
exit

Commands
The following commands were used

Command Purpose
echo -n "Target Diarectory: "
read path
get the target directory
eval cd $path change returned string into an object
move to target directory
ls -l list contents of target directory
echo "Replace all underscores with spaces?"
read -p "Hit <ENTER> to continue / ctrl + c to quit"
prompt user to continue
rename 's/_/ /g' * replace underscores with spaces
ls -l show results
exit exit script

RE-NAME.SH

01

Tasks & Commands

The following is a list of tasks the script will need to complete. Each of these tasks will be presided by a comment '#'. Below that... are the commands that can be used to complete them.

# get the target directory
# store directory in a variable called 'path'
echo -n "Target Directory: "
read path

# turn returned sting into an object
# change directory to given path
eval cd $path

# show contents of provided directory
ls -l

# prompt user for start pattern
# store in variable 'pattern_start'
echo -n "Start Pattern: "
read pattern_start

# prompt user for end pattern
# store in variable 'pattern_end'
echo -n "End Pattern: "
read pattern_end

# prompt user to continue
# show which patterns will be replaced
echo "\"$pattern_start\" will be replaced with \"$pattern_end\""
read -p "Hit <ENTER> to continue / ctrl + c to quit"

# replace 'start pattern' with 'end_pattern'
mmv "*$pattern_start*" "#1$pattern_end#2"

# show results
ls -l

# exit
exit

02

The Script

Now that the commands have been found, the can be saved to a file with a .sh extension, then run as a script. The following code snippet can be copy and pasted into an editor, saved and run.

The very 1st line of the script points to where bash is installed on the system. If this is different in your case, the following command can be used to find this path.

fossman@linux-server:~$ which bash
#!/usr/bin/bash

echo ""
echo "RE-NAME.SH"
echo ""

echo -n "Target Diarectory: "
read path

eval cd $path

echo ""
echo "Directory Contents"
ls -l
echo ""

echo -n "Start Pattern: "
read pattern_start

echo -n "End Pattern: "
read pattern_end

echo ""
echo "\"$pattern_start\" will be replaced with \"$pattern_end\""
read -p "Hit <ENTER> to continue / ctrl + c to quit"

mmv "*$pattern_start*" "#1$pattern_end#2"

echo ""
echo "Success! generating results..."
sleep 2
echo ""
ls -l

exit

Commands
The following commands were used

Command Purpose
echo -n "Target Diarectory: "
read path
get the target directory
eval cd $path change returned string into an object
move to target directory
ls -l list contents of target directory
echo "\"$pattern_start\" will be replaced with \"$pattern_end\""
read -p "Hit <ENTER> to continue / ctrl + c to quit"
prompt user to continue
show before and after
mmv "*$pattern_start*" "#1$pattern_end#2" replace 'start_pattern' with 'end_pattern'
ls -l show results
exit exit script