Skip to content

files manager

NNB edited this page Feb 6, 2022 · 25 revisions

You don't need a files manager

Yeah, maybe you don't...

πŸ’‘ About

A machine without a files manager is too minimal!

Of course everyone have their own different need and workflow. But if you have an satifice shell config and want to utilize it as much as possible. Then maybe you don't need a files manage and instead, you should use your terminal for files managing. This guide will not only teach you how to managing files but also do it optimally.

Here is all of files managers uses that I could think of:

For the sake of convenience, I will call files and directories as items.

  1. Enter a directory location.
  2. See a directory's content.
  3. Drag and drop items to different applications.
  4. Searching for items.
  5. Create new items.
  6. Copy, cut, link, delete and rename items.
  7. Extract and archive items.
  8. Check free and used spaces.
  9. Open terminal in current directory.

Those are all things that the terminal can easily do:


πŸ“‚ Enter a directory location

To enter a directory, type cd path/to/dir. But if your shell support implicit directory change, enable it if it isn't already so you can enter a path just by typing it out.

You could also utilize it with a fuzzy picker (example).


πŸ‘€ See a directory's content

Use ls or other alternatives. Alias it in your shell as l for easy access.

You could alias cd and ls to the same command to quickly view a directory's contents. But if your shell have a hook/event system, it's best to set it automatically ls every time you change your directory. Here is an example for Xonsh:

@events.on_chdir
def auto_ls(olddir, newdir, **kw):
	ls

βœ‹ Drag and drop items to different applications

Most programs and web apps already have a button to open a file picker, but if you really want it, check out Dragon.


πŸ”Ž Searching for items

Use find or other alternatives. Then you could also utilize it with a fuzzy picker. Alias it in your shell as f for easy access.


πŸ†• Create new items

To create a new directory, type mkdir -p dir_name. Alias it in your shell as mk, mkd or md for easy access.

To create a new file, type touch file_name or just open it with a text editor, it will automatically be created when you save the file.


πŸ“  Copy, cut, link, delete and rename items

  • To copy items, use cp -r.
  • To cut and rename, use mv (rename file by mv file_with_old_name file_with_new_name).
  • To link items, use ln -s.
  • To delete items, use rm -rf or trash-cli.

If you want to select some items, cd to a new path, then copy/cut/link items to current directory. Add this to your shell config:

For Bash/Zsh
s() {
	SELECTION=()

	for item in "$@"; do
		SELECTION+=("$(readlink -f "$item")")
	done
}

mv()  { if [ "$#" -eq '0' ]; then command mv    "${SELECTION[@]}" .; else command mv    "$@"; fi }
cp()  { if [ "$#" -eq '0' ]; then command cp -r "${SELECTION[@]}" .; else command cp -r "$@"; fi }
ln()  { if [ "$#" -eq '0' ]; then command ln -s "${SELECTION[@]}" .; else command ln -s "$@"; fi }
hln() { if [ "$#" -eq '0' ]; then command ln    "${SELECTION[@]}" .; else command ln    "$@"; fi }
For Xonsh
import os

$SELECTION = None

def set_file_select(items):
	$SELECTION = [os.path.abspath(item) for item in items]

aliases["s"]   = lambda args: set_file_select(args)

aliases["mv"]  = lambda args: execx("mv    @($SELECTION) .") if not args else execx(" ".join(["mv"]    + args))
aliases["cp"]  = lambda args: execx("cp -r @($SELECTION) .") if not args else execx(" ".join(["cp -r"] + args))
aliases["ln"]  = lambda args: execx("ln -s @($SELECTION) .") if not args else execx(" ".join(["ln -s"] + args))
aliases["hln"] = lambda args: execx("ln    @($SELECTION) .") if not args else execx(" ".join(["ln"]    + args))

Now you can mark items as selected by s item1 item2 ..., cd to a new path then simply type cp, mv or ln with no arguments, it will do the jobs. Of course you can still use those commands normally.

Some more ideas:

  • Clipboard: Set string of items to clipboard when selected to use in other terminal or GUI apps.
  • Register: you can operate in any specific register (also cross shell).
  • Smart cut: after cutting the file to a new path, the file's new path will be automatically copied for future operation.

Also check out edir if you want to bulk rename, delete and copy items.


πŸ“š Extract and archive items

Use Patool or other archiving and compression tools. Alias it in your shell for easy access.


πŸ’½ Check free and used spaces

Use du or other disk usage display tools. If you want this to always visible, add it to your prompt.


πŸ“Ÿ Open terminal in current directory

You already in a terminal...




πŸ’Œ Credits

Special thanks to: