tips & tricks for directory traversal & terminal & copying files

Some frequent actions on my pc are the following:
-Going to a console
-Doing directory traversal
-Going to a console
-Doing directory traversal
-Moving & Copying files.

Which tools do you use and how ? Example : midnight commander , ranger , nnn , keyboard shortcuts configured in your shell , shell extensions ?
 
I use x11-fm/xfe for all my file transfers. I have an instance of it open with the desktop that stays open as long as the desktop is up for easy access and scrolled up when not in use.

Right next to urxvt, which opens with gkrellm2 and fluxbox.

transfer.png
 
I use x11-fm/xfe for all my file transfers. I have an instance of it open with the desktop that stays open as long as the desktop is up for easy access and scrolled up when not in use.

Right next to urxvt, which opens with gkrellm2 and fluxbox.

View attachment 11283
Instead of urxvt I'm using qterminal.
zsh has the option "setopt AUTO_PUSHD" but I never used it.
You can do "pushd ." and then "popd". You see we learn each day.
 
traverse directories? use zsh or equivalent
in .zshrc ...
Code:
hh=/usr/home/me/filearea
say that directory contains subdirs pics, storage, in, vacation...
then cp -iv $hh/pics/a* $hh/vacation works, as does
cd pics, go there from anywhere in the filesystem, iow.
the copy command and the one above eliminate the need to type, or
even remember, the paths.
[ sorry for any errata due on this info... ]
but you see each command saves a large # of keystrokes.
/edit/
also useful for quick duplication and backup of files you've just saved
to somewhere!
 
I spent a lot of the last couple of days poking and prodding winscp on a Windows box, copying virtual machine images.
What a pain in the preverbial that was. I don't really like GUIs.
Code:
# To replicate a directory (Bourne compatible shell)

SRC=/some/source/dir/path
DST=/some/dest/dir/path

# SRC and DST on the same host
mkdir -p $DST && cd $SRC && \ 
    find . -depth -print | cpio -pdmu $DST

# Rsync is good (trailing slashes are mandatory in this context)
rsync -SHAXax $SRC/ $DST/

# You can do it with tar as well, but I rarely use it (cpio is easier)
test -d $SRC && test -d $DST && \
    cd $SRC; tar cbf 20 - . | (cd $DST; tar xf -)

# If you have your ssh private key unlocked in a keychain, or not passphrase
# protected, the rsync command may have either SRC xor DST as an ssh network
# spec, e.g.

ssh username@dsthostname mkdir -p $DST && \
    rsync -SHAXax $SRC/ username@dsthostname:$DST/

I will leave "SHAXax" as an excercise for the reader. They emphasise correctness over speed, which is certainly what I want.
 
My most often used commands are tcsh's pushd and popd. The man page has information on how to use it but for a brief overview: https://rubenerd.com/using-pushd-popd-with-tcsh/
The pushd and popd commands simply allow you to push and pop directories onto a stack.

Sounds frightening. Like the whole file hierarchy is in danger of collapse.

I use Qterminal on Kali, urxvt transparency doesn't act right. I always have one instance open and sometime run two, depending on desktop space. That way if I have to become root in one I've already got another open running top or something for usr tasks l while I'm root in the other. If I compile ports I exit the WM and work from the login terminal. *joy*

If I can't get FreeBSD tech talk through to people about what kind of computer I use I sometime ask if they've ever seen War Games or The Matrix. When they say yes I say "It's like that" and they just look at me like they don't know what to think.

I had a cute geek girl that worked at the Library look at my site the other day. When it opened she looked at me like she was shocked. Like I sent her to a porn site or something.
 
It must have been Harley that shocked her. I had to go back last week and tried to talk tech to her, thinking maybe she might be FreeBSD desktop material, but she had problems running the cash register.

And far too fair a young geek girl she was for a grey beard and black heart to guide but down the path to see my etchings :) , though 18 and sweet she surely was.
 
My 'trick', using !$, which works for the C shells and bash shells.
As you may or may not know !! is a shell short cut to repeat the last command:
Code:
dice@molly:~/test % ll
total 6
-rw-r--r--  1 dice  dice  38 Aug  9 15:11 test.sh
dice@molly:~/test % !!
ll
total 6
-rw-r--r--  1 dice  dice  38 Aug  9 15:11 test.sh

!$ repeats the last word of the previous line. Which is often really useful.
Code:
dice@molly:~/test % ls test.sh
test.sh
dice@molly:~/test % cat !$
cat test.sh

foo="bar"
foo="not bar"

echo $foo

dice@molly:~/test % mkdir somedir
dice@molly:~/test % cd !$
cd somedir
dice@molly:~/test/somedir %
 
I do most of that from the shell. Using relatively few aliases and pre-installed scripts. One alias I have is "mkdircd", a little shell function that creates a directory (with -p, so not a problem if it already exists), and then cd's into it, in a single step.

If the task involves many files, I often start with find, create a list of files, and then process them. For example:
Code:
for f in `find . -name elephant\* | grep -v dumbo`
do
    if [ -f ${f}.ears ] ; then
        echo Elephant $f already has ears
    else
        cat $f | ./create_ear_script > ${f}.ears
    fi
done
That's the kind of script I would just type in from the command line.

If the decision making gets hard or I have to perform complex commands for each file, I use find to create a list (find ... > temp), then I edit the list into a script using emacs (often turning the single file name into a command, which often involves separating files into categories, copying the file name multiple times, ...), then execute the script.

If the task is something that will happen repeatedly, I write a script (usually in sh, if it's complex in Python and occasionally perl), put the script under source control, and install it.
 
Back
Top