The program vidir in the package community/moreutils does roughly the same. Except, that one you can use to delete files, and you can combine it with find.
Thanks for the reply. Hadn't known about the moreutils package, which has a slew of other nice small, useful scripts.
]]>I stumbled across this little script gem some years ago and have been using it very heavily ever since.
It's based on the idea that filenames are ultimately text and editing them would best be done with your text editor of choice.
The program vidir in the package community/moreutils does roughly the same. Except, that one you can use to delete files, and you can combine it with find.
]]>I stumbled across this little script gem some years ago and have been using it very heavily ever since.
It's based on the idea that filenames are ultimately text and editing them would best be done with your text editor of choice.
I modified it slightly so that it also creates directories when needed (my version is appended below). This isn't extensively tested however. I found I seldomly use it for renaming whole hierarchies after all. I was also planning on adding support for copying (not just renaming) at some point, as well as using absolute pathnames for everything. Just didn't get around to doing it yet.
This script is absolutely life-changing for me. Brings the power of vim now to everything I use (I'm even using vim to type this, via w3m )... I can already see a gazallion minutes saved because of this. Thanks a lot.
]]>It's based on the idea that filenames are ultimately text and editing them would best be done with your text editor of choice.
I modified it slightly so that it also creates directories when needed (my version is appended below). This isn't extensively tested however. I found I seldomly use it for renaming whole hierarchies after all. I was also planning on adding support for copying (not just renaming) at some point, as well as using absolute pathnames for everything. Just didn't get around to doing it yet.
Apart from that I only use coreutils and zsh's `EXTENDED_GLOB' to make life easier.
#!/bin/sh
# emv - editor mv
#
# Description:
# Rename files with your favourite text editor.
# or: Edit file names using the "document metaphor" ;-)
#
# This script is intended to be Posix-compliant.
# Tested with coreutils 5.2.1, dash 0.5.2, bash 3.0 and sed 4.1.4.
#
# It was initiated during another nice LUG Sinsheim meeting
# by Torsten Scheck, Uwe Menges, Volker Weiss.
# Special thanks to Marc Lehmann for many valuable hints
# which made emv actually usable.
#
# v1.95 2006-02-17 torsten.scheck@gmx.de
# Latest Version: http://www.i0i0.de/toolchest/emv
#
# Knows issues:
# * Names must not contain new line characters (0x0a)
# * A directory and its entries can't be renamed in the same
# emv session.
# * before bash 3.1 the builtin read removes 0x7f, so file names
# containing that character can't be renamed.
# * dash 0.5.2 removes 0x81 and 0x88 from variables, so
# file names containing those characters won't be listed.
# * dash 0.5.2's builtin read combines '\\' to '\'
#
# This software is provided by the contributors "as is" and any
# express or implied warranties, including, but not limited to, the
# implied warranties of merchantability and fitness for a
# particular purpose are disclaimed. In no event shall the
# contributors be liable for any direct, indirect, incidental,
# special, exemplary, or consequential damages (including, but not
# limited to, procurement of substitute goods or services; loss of
# use, data, or profits; or business interruption) however caused
# and on any theory of liability, whether in contract, strict
# liability, or tort (including negligence or otherwise) arising in
# any way out of the use of this software, even if advised of the
# possibility of such damage.
#
# Copyright is hereby assigned to the Public Domain.
edit=${VISUAL:-${EDITOR:-vi}}
if [ $# -eq 0 ]; then
echo "Usage: $0 FILE...
Rename FILEs with your favourite text editor ($edit),
specified by the VISUAL or EDITOR environment variable."
exit 0
fi
# create private temp dir and ensure its deletion
umask 077
dir="/var/tmp/emv-$(id -u)-$$"
[ ! -d "$dir" ] && mkdir "$dir"
cleanexit () { rm -rf "$dir"; exit $1; }
trap 'cleanexit 0' 2 15
orgfile="$dir/org-$$"
newfile="$dir/new-$$"
diffile="$dir/dif-$$"
tmpfile="$dir/tmp-$$"
errfile="$dir/err-$$"
# list file names into temp files
# remove trailing '/' of directories passed to allow intermediate renaming step
ls -1d -- "$@" | sed 's/\/$//' | tee "$orgfile" >"$newfile"
# files not found
[ ! -s "$orgfile" ] && cleanexit 1
# detect file names with newlines
if [ $(ls -q -1d -- "$@" | wc -l) -ne $(wc -l <"$orgfile") ]; then
echo "This script doesn't work for file names containing newline characters. Exiting." >&2
cleanexit 1
fi
while
if [ -t 0 ]; then
"$edit" "$newfile"
else
# workaround: for find/xargs: <&1 prevents that editor gets confused by /dev/null being attached
# to stdin; not all editors are able to find an appropriate terminal, though.
"$edit" "$newfile" <&1
fi
# remove empty lines
sed '/^$/ d' "$newfile" > "$tmpfile"
mv "$tmpfile" "$newfile"
# detect line count mismatch
diff=$(( $(wc -l <"$orgfile") - $(wc -l <"$newfile") ))
[ $diff -ne 0 ]
do
echo "Line count doesn't match by $diff lines. (press 'Enter' to continue, Ctrl-C to exit)"
read enter
done
# quit if file wasn't changed (only if 'cmp' is available)
type cmp >/dev/null 2>&1 && cmp "$orgfile" "$newfile" >/dev/null 2>&1 && cleanexit 0
# remove IFS default value to prevent 'read' from trimming space and tabs
IFS=''
# copy old and new content of changed lines into temp file
exec 3< "$newfile"
while read -r orgline; do
read -r newline <&3
# workaround: dash doesn't like '!' or '('
if [ "x${orgline}" != "x${newline}" ]; then
tmpline="$orgline"
# intermediate renaming step to prevent collision of file names (a->b; b->a)
# only if target is not a directory
if [ ! -d "$newline" ]; then
tmpline="${orgline}.tmp$$~"
# -i: safety net, but should have no effect; stdin in is not connected to a terminal
mv -i -- "$orgline" "$tmpline" 2>>"$errfile"
# mark error in intermediate renaming step
[ "$?" -ne "0" ] && { newline="err"; orgline="err"; }
fi
echo --"$tmpline" >>"$diffile"
echo --"$newline" >>"$diffile"
echo --"$orgline" >>"$diffile"
fi
done <"$orgfile"
# verbosely rename files
if [ -e "$diffile" ]; then
# workaround: echo does not interpret '--' to mean the end of options
cut -c 3- "$diffile" > "$tmpfile"
mv "$tmpfile" "$diffile"
while read -r tmpline && read -r newline && read -r orgline; do
# skip errors in intermediate renaming step
if [ "x${orgline}" != "x${newline}" ]; then
# shell doesn't like '<' '=' '>' at this point; workaround?
if [ -e "$newline" -a ! -d "$newline" ]; then
# don't overwrite existing files
echo "File '$newline' already exists - '$orgline' remains unchanged." >>"$errfile"
false
else
mkdir -v -p $(dirname "$newline") 2>>"$errfile"
echo " '""$orgline""'" "->" "'""$newline""'"
mv -i -- "$tmpline" "$newline" 2>>"$errfile"
fi
# if renaming failed, revoke intermediate renaming step
if [ "$?" -ne "0" -a "x${tmpline}" != "x${orgline}" ]; then
mv -i -- "$tmpline" "$orgline" 2>>"$errfile"
fi
fi
done <"$diffile"
fi
# list errors
[ -e "$diffile" ] && { [ -s "$errfile" ] && cat "$errfile" || echo "All files have been successfully renamed/moved."; }
cleanexit 0
Try Ranger. Cli file manager.
I have ranger installed for when I'm looking for something and I don't know what it is; Drifting -- Searching for clues. Otherwise, bash is where I do most of my file work. Other shells are interesting, but I've haven't found a need that's driven me to one of them.
]]>I would actually state that using bash as your filemanager is good for a 'few' files, but once you have video files cluttered all throughout your hard drive and folders all over, thats where the 'bash' filemanager system lacks its use in terms of effectiveness.
Indeed. I love features like Ctrl+click to highlight files that have nothing in common and symlink them to another folder by drag'n'drop('n hold a key).
I usually use Nautilus when I don't really know what I want to do with which file. I also use it with file-roller. I seem to be unable to memorize the tar options. tar -xfce :-D
]]>once you have video files cluttered all throughout your hard drive and folders all over, thats where the 'bash' filemanager system lacks its use in terms of effectiveness.
Actually, I found this to be one of the best advantages of using bash is that it forces a user to think about file organization and making useful naming schemes for files.
For example, instead of having 1000+ media files in one directory I subcategorize theme by genre or whatever, and then probably subcategorize them again.
Then I usually rename the files to something meaningful, like if I have 50 pictures of my kids birthday, just do a for each loop on the directory and rename all the files donovan_birthdayX.jpg where X is an integer incrementation.
essentially. just don't "have files cluttered all throughout you hard drive and folders all over". and your life will be much happier regardless of how you manage your files.
]]>I would actually state that using bash as your filemanager is good for a 'few' files, but once you have video files cluttered all throughout your hard drive and folders all over, thats where the 'bash' filemanager system lacks its use in terms of effectiveness.
Wow, precisely what moved me away from using graphical filemanagers is how unresponsive they became when there were a large number of multimedia files in a given folder (--every try to open a folder in nautilus with 1000+ images?), and how long they take to search the entire filesystem for certain kinds of files when they were spread around (as compared to locate/find in a terminal).
]]>I would actually state that using bash as your filemanager is good for a 'few' files, but once you have video files cluttered all throughout your hard drive and folders all over, thats where the 'bash' filemanager system lacks its use in terms of effectiveness.
You are correct for multimedia files but for text (even rich text) the command line tools are unparalleled; recall find and grep. The shell one chooses also matters. Bash is great but zsh has superior globbing features. Personally I use fish which alows me to jump to directories much faster than any file manager, even Ranger.
]]>I must state that however I say that, I use a bash terminal to sometimes go through folders myself and it does feel a bit natural. Just being the devils advocate.
some bits from my .bashrc
alias ll="ls -lh"
alias la="ls -a"
alias exit="clear; exit"
alias ls="ls --color=auto"
I like the use of aliases.
]]>Just out of curiosity, what don't you guys like about file managers?
For me, it's mostly that I can type faster than I can click and drag. I find moving files around in a file manager tedious and slow.
once you are used to using the command line for everything you realize that it's actually quite a bit faster than pushing your mouse around for everything. especially once you get into scripting common tasks.